Time for action — controlling Sinbad

We use the previous code and add this code where we need, as we did before. We will create a WASD control for Sinbad with the following code:

  1. Replace the line where we translate the node in the FrameListener with a zero vector called translate:
    Ogre::Vector3 translate(0,0,0);
    
  2. Then add the following keyboard query after the escape query:
    if(_key->isKeyDown(OIS::KC_W))
    {
    translate += Ogre::Vector3(0,0,-10);
    }
    
  3. Now add the code to the other three keys. It is basically the same, only the key code and the direction of the vector changes:
    if(_key->isKeyDown(OIS::KC_S)) { translate += Ogre::Vector3(0,0,10); } if(_key->isKeyDown(OIS::KC_A)) { translate += Ogre::Vector3(-10,0,0); } if(_key->isKeyDown(OIS::KC_D)) { translate ...

Get Ogre 3D 1.7 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.