Angle-axis vector rotation + quaternions

Started by
7 comments, last by David20321 22 years, 9 months ago
I made a simple program where you can rotate around a space-ship like in descent and stuff using quaternions but now I have to figure out how to move forwards... how do I find the vector of which direction the ship is facing? I know how to convert quaternions into angle-axis rotation values but I don''t know how to turn any of them into a vector... Any help would be appreciated. -David-
Advertisement
Your vector is already contained in the information you have.

Assume that you know the ship is pointing in a direction such that it makes angles theta, phi and psi with your 3 ground based directional axes.

Then, your velocity vector is just:

V = speed*(cos(theta) i + cos(phi) j + cos(psi) k)


where theta is an angle relative to the i basis vector
phi is an angle relative to the j basis vector
psi is an angle relative to the k basis vector

Regards,


Tim
If your quaternion is q and the ship''s forward direction is x (e.g. the x-axis), then just apply the quaternion to x to generate rotated x, i.e. the ship''s forward direction in it''s current rotated state. Mathematically that''s just

x'' = qxq''

where q'' = the conjugate as q and both x'' and x are treated as quaternions for this calculation.
John BlackburneProgrammer, The Pitbull Syndicate
Timkin for that wouldn''t I need to have a euler rotation... I don''t know how to convert quaternions or angle-axis into euler.

Johnb sorry but I''m new to quaternions, do you know where I could find a piece of source code that could apply the quaternion to the vector?
All you need to do is two quaternion products, i.e. first work out qx then multiply the result of this with q'' = the conjugate/inverse of q. Note that the it matters which order you multiply them.

How to multiply quaternions and much more is documented at http://www.gamasutra.com/features/19980703/quaternions_01.htm. There are a few other quaternions articles I''ve not had a look at on Gamedev''s Articles page.
John BlackburneProgrammer, The Pitbull Syndicate
If you are using DX8 there is a bucket load of ''helper'' functions that convert back and forth from quats to axis angles and back again.

Just search for D3DXQuaternionToAxisAngle in the help.

D.V.
D.V.Carpe Diem
How do I multiply a quaternion by a vector though... would the vector just be a quaternion with [0,x,y,z] instead of [x,y,z,w] or something?

-David-
AAAAARGH!
take a shorter look to this excellent tutorial:
click
unwritten letters

This topic is closed to new replies.

Advertisement