Transformation matrix and euler angles
by Markus Nuebel · in Torque Game Engine · 03/22/2004 (10:09 pm) · 5 replies
Hi guys.
I have two questions regarding transformation matrices in torque.
1. How are the vectors of a local coordinate system stored in a transformation matrix you get with ShapeBase::getTransform() ?
Since MatrixF::getPosition() returns the elements: [3][7][11][15] (the forth column).
I guess column one is the x-, column two the y- and column three the z-axis.
Am I right on this? (Or is it xzy, since torque uses the z-axis as the UP-Vector??)
2. How to get euler angles from a transformation matrix.
I have checked out a few math textbooks for the extraction of euler angles from a transformation matrix, but are unable to get this working for a "troque" trasformation matrix.
I think it's because troque uses a coordinate system, where the z-axis is pointing upwards, while most textbooks us the y-axis as UP vecotor. I have problems adapting the formulars, which are referencing matrix elements in a coordinate system with y-UP to a coordinate system with z-UP.
Has anyone done this before?
Kind regards
Markus
I have two questions regarding transformation matrices in torque.
1. How are the vectors of a local coordinate system stored in a transformation matrix you get with ShapeBase::getTransform() ?
Since MatrixF::getPosition() returns the elements: [3][7][11][15] (the forth column).
I guess column one is the x-, column two the y- and column three the z-axis.
Am I right on this? (Or is it xzy, since torque uses the z-axis as the UP-Vector??)
2. How to get euler angles from a transformation matrix.
I have checked out a few math textbooks for the extraction of euler angles from a transformation matrix, but are unable to get this working for a "troque" trasformation matrix.
I think it's because troque uses a coordinate system, where the z-axis is pointing upwards, while most textbooks us the y-axis as UP vecotor. I have problems adapting the formulars, which are referencing matrix elements in a coordinate system with y-UP to a coordinate system with z-UP.
Has anyone done this before?
Kind regards
Markus
About the author
#2
It calculates yaw and pitch for a given rotation vector.
I want to extract yaw, pitch and roll from a transformation matrix, that transfers one cooridate system (the world system) into another (the object local system).
Any othere pointers or tips?
-- Markus
03/23/2004 (4:13 am)
GetAnglesFromVector() is not what I was looking for.It calculates yaw and pitch for a given rotation vector.
I want to extract yaw, pitch and roll from a transformation matrix, that transfers one cooridate system (the world system) into another (the object local system).
Any othere pointers or tips?
-- Markus
#3
BTW, if you have the math to transform, torque uses the same scheme as any 3D engine (XYZ), the only thing you should do is to properly rename according with the directions, ex:
Your book:
XYZ = Left, Up, Front = Pitch, Yaw, Roll
Torque
XYZ = Left, Front, Up = Pitch, Roll, Yaw
In this case, just swap Roll and Yaw values. :)
03/23/2004 (5:06 am)
You can use this code to find out the pitch and yaw:Point3F vec; mat.getColumn(1,&vec); // +Y EulerF rot(-mAtan(vec.z, mSqrt(vec.x*vec.x + vec.y*vec.y)),0,-mAtan(-vec.x,vec.y));
BTW, if you have the math to transform, torque uses the same scheme as any 3D engine (XYZ), the only thing you should do is to properly rename according with the directions, ex:
Your book:
XYZ = Left, Up, Front = Pitch, Yaw, Roll
Torque
XYZ = Left, Front, Up = Pitch, Roll, Yaw
In this case, just swap Roll and Yaw values. :)
#4
Artificial horizon
I had the same issue and there's code in there that will get what you want. It will extract yaw, pitch, and roll from the current control object.
- Brett
EDIT: Here's the specific code...
03/23/2004 (10:14 am)
Check out the code in this resource:Artificial horizon
I had the same issue and there's code in there that will get what you want. It will extract yaw, pitch, and roll from the current control object.
- Brett
EDIT: Here's the specific code...
// Get current object transform matrix MatrixF objTx = control->getTransform(); // Get rotations from transform matrix VectorF vec; objTx.getColumn(1,&vec); // Get X-vector for roll calculation Point3F xv; objTx.getColumn(0,&xv); // Calculate PRH (x = pitch, y = roll, z = heading) Point3F rot(-mAtan(vec.z, mSqrt(vec.x*vec.x + vec.y*vec.y)), mDot(xv,Point3F(0,0,1)), -mAtan(-vec.x,vec.y) ); // Set up vars F32 pitch = mRadToDeg(rot.x); // Pitch F32 yaw = mRadToDeg(rot.z); // Heading F32 roll = mRadToDeg(rot.y); // Roll
#5
That was what I was looking for.
Will try it this evening.
-- Markus
03/24/2004 (12:18 am)
Thanks Bret.That was what I was looking for.
Will try it this evening.
-- Markus
Torque Owner Joel Davis