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:
Replace the line where we translate the node in the
FrameListener
with a zero vector calledtranslate:
Ogre::Vector3 translate(0,0,0);
Then add the following keyboard query after the escape query:
if(_key->isKeyDown(OIS::KC_W)) { translate += Ogre::Vector3(0,0,-10); }
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 += Ogre::Vector3(10,0,0); }
Now use the translate vector to translate the model, and keep in mind to use time-based and not frame-based movement:
_node->translate(translate*evt.timeSinceLastFrame);
Compile and run the application...