想象一个物体在3D空间中移动的过程，该物体必然会涉及到旋转。例如一个怪物，他的运动方向会改变，要改变其方向只需要对其进行旋转即可。

OGRE中的Quaternion类用于四元数处理。该类（也可以说是四元数本身）有四个成员：x,y,z,w。这四个数分别代表什么？

Quaternions can seem pretty daunting because of the use of 'imaginary' numbers. It's much easier to understand if you just ignore this concept completely. The basic formula for creating a quaternion from angle/axis is:

Q = cos (angle/2) + i (x * sin(a/2)) + j (y * sin(a/2)) + k(z * sin(a/2))

or

Code:
 Q.w = cos (angle / 2) Q.x = axis.x * sin (angle / 2) Q.y = axis.y * sin (angle / 2) Q.z = axis.z * sin (angle / 2)

Q = cos (angle/2) + i (x * sin(a/2)) + j (y * sin(a/2)) + k(z * sin(a/2))

 Q.w = cos (angle / 2) Q.x = axis.x * sin (angle / 2) Q.y = axis.y * sin (angle / 2) Q.z = axis.z * sin (angle / 2)

 void Quaternion::FromAngleAxis (const Radian& rfAngle,const Vector3& rkAxis) { // assert: axis[] is unit length // // The quaternion representing the rotation is // q = cos(A/2)+sin(A/2)*(x*i+y*j+z*k) Radian fHalfAngle ( 0.5*rfAngle ); Real fSin = Math::Sin(fHalfAngle);   w = Math::Cos(fHalfAngle);   x = fSin*rkAxis.x;   y = fSin*rkAxis.y;   z = fSin*rkAxis.z; }

Quaternion q( Degree( -90 ), Vector3::UNIT_X );

sceneNode->rotate( q );

 Vector3 src = mNode->getOrientation() * Vector3::UNIT_X; Ogre::Quaternion quat = src.getRotationTo(mDirection); mNode->rotate(quat);

SceneNode的getOrientation获得该node的方位，用一个四元数来表示。什么是方位？这里我也不清楚，但是对于一个四元数，它这里表示的是一种旋转偏移，偏移于初始朝向。

OGRE论坛上有这么一段话：

The reason there's no other way to convert a quaternion to a vector is because a quaternion is relative. It has no direction.
With a direction (like a vector) you could say "face north east".

But with a quaternion, you say "face 45 degrees clockwise from whatever direction you are already facing" (very simplified example). Without knowing which way the object is already facing, a quaternion is virtually meaningless with respect to orientation. So we just default it to some initial direction, like Unit Z, and make all orientations relative to that.

 Vector3 src = mNode->getOrientation() * Vector3::UNIT_X; if ((1.0f + src.dotProduct(mDirection)) < 0.0001f) {   mNode->yaw(Degree(180)); } else {   Ogre::Quaternion quat = src.getRotationTo(mDirection);   mNode->rotate(quat); } // else