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.
Post Reply
Starterz
Posts: 27
Joined: Thu Apr 02, 2009 2:45 am

Simulation of videosignal lost.

Post by Starterz »

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'! :)
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

any screenshot?
ArakisTheKitsune
Posts: 73
Joined: Sat Jun 27, 2009 6:52 am

Post by ArakisTheKitsune »

@Starterz: You forgot to call srand function.
Knowledge is power, understanding is wisdom.
Starterz
Posts: 27
Joined: Thu Apr 02, 2009 2:45 am

Post by Starterz »

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.
ArakisTheKitsune
Posts: 73
Joined: Sat Jun 27, 2009 6:52 am

Post by ArakisTheKitsune »

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.
Anoyser
Posts: 2
Joined: Sat Jan 22, 2011 3:29 pm

Post by Anoyser »

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

Thanks in advance :)
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

very inefficient, do it in a shader
freetimecoder
Posts: 226
Joined: Fri Aug 22, 2008 8:50 pm
Contact:

Post by freetimecoder »

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
Anoyser
Posts: 2
Joined: Sat Jan 22, 2011 3:29 pm

Post by Anoyser »

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 :)
roelor
Posts: 240
Joined: Wed Aug 13, 2008 8:06 am

Post by roelor »

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.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Post by REDDemon »

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
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Post Reply