We will use the previously used code and only modify one line of code:
Change the line where we translate the node to:
_node->translate(Ogre::Vector3(10,0,0) * evt.timeSinceLastFrame);
Compile and run the application. You should see the same scene as before, only the model might move at a different speed.
We changed our movement model from frame-based to time-based. We achieved this by adding a simple multiplication. As said before, frame-based movement has some downfalls. Time-based movement is simply superior because we get the same movement on all computers and have much more control over the movement speed. In step 1, we used the fact that Ogre 3D passes a FrameEvent
when calling the frameStarted()
method. This class holds the time since the last frame was rendered in seconds:
Ogre::Vector3(10,0,0) * evt.timeSinceLastFrame);
This line uses this data to calculate how much we want to move our model in this frame. We use...