My application works with unit direction vectors internally. Now that
I'm trying to integrate ODE, I have to convert rotation matrices back to
direction vectors after every frame. I am definitely not a math major so
I'm having some troubles with this.
Converting a rotation matrix for a single rotation of "a" degrees around
the Z-axis is easy enough, as this becomes:
cos(a) -sin(a) 0
sin(a) cos(a) 0
0 0 1
And working your way from there to get a direction vector isn't too
hard. However, obviously ODE's rotation matrices are combinations of
multiple rotations around multiple axes. I'm really lost on how to
convert such a 'complex' rotation matrix back to a unit direction
vector.
Can anyone on this list help me out? Couldn't find the answer using
google :(
Thanks a lot in advance!
Cheers,
Marc
It's rather simple actually. You just need to perform a matrix-vector
multiplication. With a unit vector oriented along a coordinate axis,
this is reduced to extracting a single column from the matrix. In fact,
the columns of the matrix can be viewed as the unit X, Y and Z vectors
of the rotated space.
ODE provides an even simpler solution though. You can use the
dBodyVectorToWorld function, as documented here:
http://opende.sourceforge.net/mediawiki-1.6.10/index.php/Manual_%28Rigid_Body_Functions%29#Utility
--
Mikko Rasa "The DataBeaver"
I think the process you are looking for is converting a rotation
matrix to a "angle axis", although you may not be using the angle
portion, just the axis (the forward). A good reference site is:
http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
, which will provide you with both an explanation of the maths, and
reference code (in Java).
Just a note that you will be missing one form of possible rotation by
only using the axis. But if your system is pseudo-2d (all things use a
constant "up") then I imagine it would be ok.
Peter N
However, a single "rotation vector" is not enough to fully determine the
rotation of an object in 3D; at a minimum you also need an assumed "up"
vector. However, in ODE, "up" for the object will change as it tumbles,
so there is no conversion between a single rotation vector and a full
rotation. You will have to change your system to use full rotations
(quaternions or matrices).
Sincerely,
jw
Marc "Foddex" Oude Kotte wrote: