English

ogre 3d 1.7 beginner’s guide 第四章 第八小节 中文翻译 鼠标状态

2011/3/15

Mouse state

【 鼠标状态 】

Querying the keyboard state was done using the isKeyDown() function. To get the mouse

state, we used the getMouseState() function. This function returns a mouse state struct

as an instance of the MouseState class, which contains information about the button state,

whether they are pressed or not, and how the mouse moved since the last capture call.

【 我们使用isKeyDown() 函数来完成查询键盘状态。这次我们使用getMouseState() 函数来完成查询鼠标状态的操作。这个函数返回一个鼠标状态作为MouseState类的实例,它包含了按钮按下与否和从上次获取鼠标状态开始鼠标是如何移动的按钮状态信息。】

We want the movement information to calculate how much our camera needs to be rotated. Mouse movement can happen on two axes, namely, the x-axis and the y-axis. Both axes' movements are saved separately in the X and Y variable of the mouse state. We then have the possibility to get the relative or absolute values. Because we are only interested in mouse movement and not the position of the mouse, we are using the relative values. The absolute values contain the position of the mouse on the screen. These are needed when we want to test if the mouse has clicked into a certain area of our application. For camera rotation, we only need the mouse movement, so we use the relative values. The relative value only indicates whether the speed and direction of the mouse has moved, but not the number of pixels.

【 我们想要移动的信息是为计算摄像机需要旋转的大小。鼠标移动发生在了两个轴,即X轴和Y轴。两个轴的移动是由两个鼠标状态变量分开存贮的。我们然后就可以得到相对或绝对值。因为我们只对鼠标移动而非鼠标的位置的感兴趣,我们使用相对值。而绝对值包含包含鼠标在屏幕上的信息。当鼠标点进我们程序的确切区域的时候绝对值很是需要了。对于摄像机旋转,我们只需要鼠标移动信息,所以使用相对值。相对值只是描述出鼠标移动过的速度和方向是否改变,并不是描述所在位置的值。】

These values are then multiplied by the time since the last frame and by -1. -1 is used

because we get the movement in a different direction to which we want the camera to

rotate. So we simply invert the movement direction. After calculating the rotation values, we apply them to the camera with the yaw() and pitch() functions. The last thing to do is to

apply the translation vector we created from the keyboard input to the camera. For this, we use the moveRelative() function of the camera. This function translates the camera in the local space without considering the rotation of the camera. This is useful, because we know that in local space (0,0,-1) moves the camera forward. With rotations applied to the camera, this isn't necessarily true. Refer to the chapter about the different spaces in 3D space for a more detailed explanation.

【 这些值乘以自上一帧到现在的时间和-1。使用-1是因为我们想让摄像机根据我们的需要进行旋转运动。所以我们需改变移动的方向。在计算完旋转的值,我们应用它们到yaw() 和pitch() 函数。最后一件事是应用我们从键盘输入创建的变换向量到摄像机。这个很有用,因为我们知道在局部空间中使用 (0,0,-1) 可以把摄像机向前移动。但当旋转应用于摄像机,这个就不一定正确了。请参考有关在三维空间中不同的空间的第二章寻找更为详尽的解释。】

Pop quiz – capturing the input

【 简单测试 —— 获取输入 】

Why do we call the capture() method for the mouse and keyboard?

【 为什么我们调用鼠标和键盘的capture() 方法?】

Have a go hero – playing with the example

【 让英雄个动起来 —— 试玩一下例子 】

Try removing the -1 from the rotation calculation and see how this changes the camera controls.Try removing the capture() function calls and see what impact this has.

【 尝试从旋转计算中移除-1并观察摄像机控制如何改变。】