Hi, I'm working on a 3D space game built with C++ and DirectX. I've got a question about using quaternions for object rotation and I'm hoping someone might have an idea.
Currently, the player ship's rotation is represented by a quaternion. The ship starts off level and facing directly straight forward (towards the positive Z axis). I create a quaternion based on the 3 axes (positive X to the right, Y is up, and Z is forward).
If I want to apply a rotation to the ship, for example 90 degrees to the right, I can call D3DXQuaternionRotationAxis() to get a rotation quaternion. I then multiply that against the original rotation using D3DXQuaternionMultiply() and I get a new updated rotation where the ship is facing forward along the X axis (perfect!).
The problem I have is in the next step:
If I then want to make a second rotation of pitching the nose of the ship up (based on the current direction it's facing along the X axis), when I try to use the method described above I don't get the intended result. What happens instead is the ship indeed rotates, but as if it were still facing in it's original direction towards the Z axis. So instead of seeing the nose of the ship rotate up, I see the ship roll. Or to be more clear, I see a rotation around the X axis, rather than seeing a rotation around the Z axis.
This is probably a very simple mistake, but for some reason I always have trouble wrapping my head around quaternion math.
Any help is appreciated!
TorathMember Since 24 May 2012
Offline Last Active Nov 04 2012 03:00 PM