Advertisement

Matrix Math....

Started by May 23, 2000 12:14 AM
2 comments, last by jLeslie 24 years, 7 months ago
How would I go about extracting the angle of rotation about a given axes from a matrix? Is there an easy way to do it, or would I need to use the reverse of the equation to make a rotation matrix? I know if I extract the 11-13th, or is it 11,21,31....I would have a vector discribing the X rotation....Could I do it with just those to improve speed?
I''d just keep using vectors.
I''ve never really felt the need to convert anything to the old angles (roll pitch yaw) system again since I''m working with matrices.

Perhaps we could help you finding a solution with vectors if you describe what you''re trying to do ?

-Markus-
www.lunaticsystems.de
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
Advertisement
You can compute the euler angles from a rotation matrix by first extracting the orientation vectors and then rotating these until they are aligned with the world axes.

Here''s some old code that I used once, there are some useless code in it that can be trimmed away for better performance:

void mlMatrixAnglesXYZL(ML_FLOAT &OX, ML_FLOAT &OY, ML_FLOAT &OZ, ML_MATRIX3D &M){  ML_VECTOR3D SX,SY,SZ; // System axises  ML_MATRIX3D Mtx;  ML_VECTOR3D Tmp;  // Extract the system''s coordinate vectors from the matrix  // This is done by multiplying the matrix with [1 0 0 0]T for the   // X axis, [0 1 0 0]T for the Y axis and [0 0 1 0] for the Z axis  mlVectorSet(SX, M._00, M._10, M._20);  mlVectorSet(SY, M._01, M._11, M._21);  mlVectorSet(SZ, M._02, M._12, M._22);  // TODO: Do we need to make sure they are perpendicular to each other?  // Rotate the system around the world Z axis to   // align the system X axis with the world XZ plane  OZ = (ML_FLOAT)atanf(SX.y / SX.x);  if( SX.x < 0 ) OZ += ML_PI;  if( OZ > ML_2_PI ) OZ -= ML_2_PI;  // Ofcourse we don''t have to rotate all the vectors all the   // time but for easier reading and debugging we do it anyway.  mlMatrixSetRotateZL(Mtx, -OZ);  mlMatrixVectorMultiplyO(Tmp, Mtx, SX);  mlVectorCopy(SX, Tmp);  mlMatrixVectorMultiplyO(Tmp, Mtx, SY);  mlVectorCopy(SY, Tmp);  mlMatrixVectorMultiplyO(Tmp, Mtx, SZ);  mlVectorCopy(SZ, Tmp);  // Rotate the system around the world Y axis to  // align the system Z axis with the world YZ plane  OY = (ML_FLOAT)atanf(SZ.x / SZ.z);  if( SZ.z < 0 ) OY += ML_PI;  if( OY > ML_2_PI ) OY -= ML_2_PI;    mlMatrixSetRotateYL(Mtx, -OY);  mlMatrixVectorMultiplyO(Tmp, Mtx, SX);  mlVectorCopy(SX, Tmp);  mlMatrixVectorMultiplyO(Tmp, Mtx, SY);  mlVectorCopy(SY, Tmp);  mlMatrixVectorMultiplyO(Tmp, Mtx, SZ);  mlVectorCopy(SZ, Tmp);  // Finally we rotate around the world X axis to align   // the system Y axis with the world XY plane  OX = (ML_FLOAT)atanf(SY.z / SY.y);  if( SY.y < 0 ) OX += ML_PI;  if( OX > ML_2_PI ) OX -= ML_2_PI;  mlMatrixSetRotateXL(Mtx, -OX);  mlMatrixVectorMultiplyO(Tmp, Mtx, SX);  mlVectorCopy(SX, Tmp);  mlMatrixVectorMultiplyO(Tmp, Mtx, SY);  mlVectorCopy(SY, Tmp);  mlMatrixVectorMultiplyO(Tmp, Mtx, SZ);  mlVectorCopy(SZ, Tmp);}






- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks for the suggestions...I spent all day fixing a bug though so I haven''t had a chance to try it yet.

This topic is closed to new replies.

Advertisement