English

ogre 3d 1.7 beginner’s guide 第四章 第六小节 中文翻译 给模型添加动作

2011/3/11

Adding movement to the model

【 给模型添加动作 】

Now that we have the possibility to get user input, let's use it to control Sinbad's movement

on the plane.

【 现在我们已经有能力获取用户的输入,现在让我们使用它来控制Sinbad的在平面上的运动吧。】

Time for action – controlling Sinbad

【 实践时刻 —— 控制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:

【 我们使用以前的代码并添加代码到我们需要的地方,正如之前所做的一样。我们将会使用以下代码,使用WASD键来控制Sinbad。】

if(_key->isKeyDown(OIS::KC_W))

{

translate += Ogre::Vector3(0,0,-10);

}

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);

}

4.  Now use the translate vector to translate the model, and keep in mind to use

time-based and not frame-based movement:

【 4. 现在使用向量来变换模型,并记住使用基于时间的运动而非基于帧的运动:】

_node->translate(translate*evt.timeSinceLastFrame);

5.  Compile and run the application, and you should be able to control Sinbad with

the WASD keys:

【 5. 编译运行程序,然后你就可以用WASD键来控制Sinbad了。】

What just happened?

【 刚刚发生了什么?】

We added a basic movement control using the WASD keys. We queried all four keys and

built the accumulative movement vector. We then applied this vector to the model using

time-based movement.

Have a go hero – using a speed factor for movement

【 让英雄动起来 —— 使用决定运动的速度因素 】

One downside of this approach is that when we want to change the movement speed of

the model, we have to modify four vectors. A better way would be to use the vectors only

to indicate the movement direction and use a float variable as the speed factor and multiply the translate vector by it. Change the code to use a movement-speed variable.

【 上面方法的缺点是我们想要改变模型的运动速度的时候,我们不得不改变四个向量。更好的方法是使用一个向量来表示运动方向,并使用一个float作为速度因子并使速度因子乘以变换向量。使用一个速度变量来改变代码。】