Simulation of videosignal lost.

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.

Simulation of videosignal lost.

Postby Starterz » Sat Nov 20, 2010 1:22 am

Hi, friends! Here it is:

Code: Select all
  //! Simulation of videosignal lost. Call this fun. inside main loop.
  //! Returns true if videosignal from camera is 'lost'.
  //! NOTE: MUST NOT use if() before itself
  //! or after 'if(smth) emulCamDamage()' use:
  //! '..else device->getSceneManager()->getRootSceneNode()->setVisible(true);'
  bool emulCamDamage(u8 damage //! Damage level [0..255] 0-is no damage.
                    ,ICameraSceneNode* camera
                    ,IrrlichtDevice* device
                    ,wchar_t* mess=L"V I D E O S I G N A L   I S   L O S T"
                    ,IGUIFont* font=0)
  {
    if(!device) return true;
    ISceneManager* smgr=device->getSceneManager();
    ISceneNode* rsn=smgr->getRootSceneNode();
    if(camera!=smgr->getActiveCamera())
    {
      rsn->setVisible(true);
      return true;
    }

    static s32 comatoz;
    if(--comatoz<0) comatoz=0;
    IVideoDriver* driver=device->getVideoDriver();
    if(!comatoz&&rand()%255<damage)
    {
      u32 coma=driver->getFPS();
      comatoz=1+rand()%++coma;   //! (0..1] in seconds.
    }
    smgr->getRootSceneNode()->setVisible(!comatoz);
    if(!comatoz) return false;

    rect<s32> view=driver->getViewPort();
    u32 x=view.getSize().Width;
    u32 y=view.getSize().Height;
    s32 sfc=x*y/100;      //! Let's get enough green snowflakes ;)
    for(s32 j=0; j<sfc; j++)
      driver->drawPixel(rand()%(x+1),rand()%(y+1)
                        ,SColor(255,0,255,0));
    if(mess) //! Tells that a signal from camera is lost.
    {
      IGUIEnvironment* env=device->getGUIEnvironment();
      if(!font) font=env->getSkin()->getFont();
      font->draw(mess
                 ,view
                 ,SColor(255,255,255,0)
                 ,true,true);
    }
    device->sleep(10);      //! Some rest when show just a noise.
    return true;
  }


Now we can have fun with "broadcast" from our 'robots'! :)
Starterz
 
Posts: 27
Joined: Thu Apr 02, 2009 2:45 am

Postby Virion » Sat Nov 20, 2010 2:41 am

any screenshot?
User avatar
Virion
 
Posts: 2102
Joined: Mon Dec 18, 2006 5:04 am
Location: Malaysia

Postby ArakisTheKitsune » Sat Nov 20, 2010 4:54 pm

@Starterz: You forgot to call srand function.
Knowledge is power, understanding is wisdom.
User avatar
ArakisTheKitsune
 
Posts: 73
Joined: Sat Jun 27, 2009 6:52 am

Postby Starterz » Sun Nov 21, 2010 12:06 am

ArakisTheKitsune wrote:@Starterz: You forgot to call srand function.

I don't know what to say to you... Do you really think it should be called here?

What about screenshots. This code simulates electronic noise on the screen,
when videosignal is lost. You can try call my function into any Irr standart example (Hallo world etc..) And you'll see all by your self.

Do it like this:

...
emulCamDamage(30,cameraFPS,device);
driver->beginScene();
smgr->drawAll();
driver->endScene();
...

And you'll see all by your self.
Starterz
 
Posts: 27
Joined: Thu Apr 02, 2009 2:45 am

Postby ArakisTheKitsune » Sun Nov 21, 2010 1:47 am

Starterz wrote:
ArakisTheKitsune wrote:@Starterz: You forgot to call srand function.

I don't know what to say to you... Do you really think it should be called here?


IMHO yes. Because if you don't you will always get same random numbers.
Of course user can call srand outside your code but this way looks more elegant to me. But that is just my opinion.
Knowledge is power, understanding is wisdom.
User avatar
ArakisTheKitsune
 
Posts: 73
Joined: Sat Jun 27, 2009 6:52 am

Postby Anoyser » Sat Jan 22, 2011 3:30 pm

Hi!
Is it possible to get this working over 2d objects too?
If yes, how?

Thanks in advance :)
Anoyser
 
Posts: 2
Joined: Sat Jan 22, 2011 3:29 pm

Postby devsh » Sat Jan 22, 2011 5:01 pm

very inefficient, do it in a shader
Portfolio (WIP) and Development Blog:
http://indirectlightandmagic.tumblr.com/

Do you want to hire a GLSL graphics programmer cheaply???
Try me!
http://indirectlightandmagic.tumblr.com/contact
User avatar
devsh
Competition winner
 
Posts: 1304
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK

Postby freetimecoder » Sat Jan 22, 2011 5:50 pm

Starterz wrote:What about screenshots. This code simulates electronic noise on the screen,
when videosignal is lost. You can try call my function into any Irr standart example (Hallo world etc..) And you'll see all by your self.


We are coders.
We are lazy.

;)

greetings
User avatar
freetimecoder
 
Posts: 226
Joined: Fri Aug 22, 2008 8:50 pm

Postby Anoyser » Sun Jan 23, 2011 1:06 am

devsh wrote:very inefficient, do it in a shader


Was that directed to me or op, both maybe?
I'm pretty new to graphics programming (not programming in general), so i don't know how i can do it in a shader.
And i don't need efficiency since I'm just creating something fun for my GF.
It has a max of 15-20 2D animations at once.
I only need to "hide" the 2D animations while the noise is happening.
So, is that possible some way to do with this piece of code?

Thanks :)
Anoyser
 
Posts: 2
Joined: Sat Jan 22, 2011 3:29 pm

Postby roelor » Sat Jan 29, 2011 9:41 pm

I like how this code is made, but I think the result is very unsatisfying, just some random green pixels and a video signal lost text in the middle of the screen.

I think its something I can learn from though, thanks anyway.
( : I like the old school text smileys best! : )
User avatar
roelor
 
Posts: 236
Joined: Wed Aug 13, 2008 8:06 am

Postby REDDemon » Tue Feb 01, 2011 8:51 am

in the GLSL i found that there is a noise function that can simulate that with a shader and it is faster. maybe you can be interested in it
OpenGL is not hard. What you have to do is just explained in specifications. What is hard is dealing with poor OpenGL implementations.
User avatar
REDDemon
 
Posts: 832
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 0 guests