Time for action — adding a timer

  1. Add the timer as a member variable to the frame listener:
    Ogre::Timer _timer;
    
  2. Reset the timer in the constructor:
    _timer.reset();
    
  3. Now add a check to see if 0.25 seconds have passed since the last time the R key was pressed. Only if that is true, will we continue with processing the input:
    if(_key->isKeyDown(OIS::KC_R) && _timer.getMilliseconds() > 250)
    {
    
  4. If enough time has passed, we need to reset the timer; otherwise, the R key can only be pressed once:
    _timer.reset();
    
  5. Compile and run the application; when pressing the R key now, it should only change the render mode to the next one.

What just happened?

We used another new class from Ogre 3D, namely, Ogre::Timer. This class offers, as the name suggests, timer functionality. We reset the timer in the constructor of our listener and every time the user presses the R key, we check if 0.25 seconds have passed since the last time we called reset(). If this is the case, we enter the if block and the first thing we do is reset the timer and then change the render mode like before. This makes sure that the render mode is only changed after 0.25 seconds. When we keep pressing the R key, we see that our application changes through all render modes with a wait of 0.25 seconds after each change.

Have a go hero — changing the input mode

Change the render mode by changing code in such a way that the mode doesn't change after a certain time has passed, but only when the R key is released and pressed again.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.126.165