Started by Jul 04 2001 06:18 PM

,
8 replies to this topic

Posted 04 July 2001 - 06:18 PM

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-

Posted 04 July 2001 - 08:16 PM

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

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

Posted 04 July 2001 - 08:54 PM

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.

x'' = qxq''

where q'' = the conjugate as q and both x'' and x are treated as quaternions for this calculation.

Posted 05 July 2001 - 06:56 AM

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?

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?

Posted 05 July 2001 - 09:26 PM

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.

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.

Posted 06 July 2001 - 12:13 AM

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.

Just search for D3DXQuaternionToAxisAngle in the help.

D.V.

Posted 06 July 2001 - 06:47 AM

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-

-David-