Game Development Community

Help me: Get player's mRot from a matrix

by Michael Bacon · in Torque Game Engine · 10/29/2007 (4:25 am) · 7 replies

The player uses a Point3F named mRot to represent the player's current orientation to some degree. Actually it looks like this only controls rotation about the Z axis by default.

I have no idea how to get this value back out of a matrix.

I've almost completely solved all of my jitter issues with riding on platforms but I need to be able to obtain this value.

Basically the update goes:
updateRenderTransformFromParent();
addPlayersDeltaToUpdatedRenderTransform();

But in order to add the delta (which is stored in the same format as mRot), I need to be able to obtain the current rotation value from my parented render transform.

Any help is appreciated.

#1
10/29/2007 (4:50 am)
This shows you which row and column the rotations are found on. You just need to find out if Torque is row or column major.

mathworld.wolfram.com/RotationMatrix.html
#2
10/29/2007 (5:14 am)
Torque is Column Major.

Thats not quite what I need though. This will give me each individual axis. I want the rotation about the world axis. I suppose.....

Something like
Get each column
Find the angle difference between that column and identity and save it as the value for that point....


Sounds easy enough... Now how do get get the angular difference between two vectors? I'm sure thats an easy one...
#3
10/29/2007 (5:29 am)
Angle between two vectors -> Dot product!!!!!

www.euclideanspace.com/maths/algebra/vectors/angleBetween/index.htm

Wolfram and Google are your friend.
#4
10/29/2007 (5:35 am)
Excellent, that is exactly what I needed.

In regards to the axis/angle I've been searching for years off and on for exactly this information put exactly this way so I could understand it.
#5
10/30/2007 (3:59 am)
I just want to point out that I just found my answer within Player.cc itself also.

This is the solution I came up with given the above info, it doesn't quite work.
rot.z = mAcos(mDot(vec, Point3F(0,1,0)));  // fails after 90 degrees of difference

and this one is found in Player::setTransform() (which for some reason I thought didn't exist)
Point3F rot(0.0f, 0.0f, -mAtan(-vec.x,vec.y));

This is probably trivial to most of you math whizzes but I never did take any trig classes so tangents and cosines ALMOST elude me.


It is obvious that the second method is better (even if I fixed the 90 degree bug) because it removes the creation of an extra variable or two and reduced the number of method calls.
#6
10/30/2007 (6:03 am)
I think dot product only works on acute angles. I think that's why the arc tangent function is better suited. But hey! I'm a math novice too.
#7
10/30/2007 (6:09 am)
Ah, so the Dot Product gives us the SMALLEST angle between two vectors... that could be useful somewhere.

Previously I just knew that the Dot Product gives the parallelism of two vectors (which is also true).