Crystal Space
9004 Posts in 2045 Topics by 52583 Members
Latest Member: Yozefgoldin778
 Pages: [1]
 Author Topic: Rotate , convert transform matrix to radians?  (Read 1732 times)
Recon
Newbie

Posts: 24

 « on: August 24, 2006, 08:10:05 pm »

I have been tying to work backwards from a mesh's Transform matrix to work out what the mesh's rotation is in radians. Not having much luck.

Here is a bit of code i was trying but it only worked for some angles and i not smart enough to workout what to do next

...........
playermesh = engine->FindMeshObject ( "turret.001" , 0 );
movable = playermesh->GetMovable ();
// Get mesh Position
start = movable->GetTransform().GetOrigin ();
// get mesh Rotation
pot = movable->GetTransform();

rotX = getM3xAngle(pot);
rotY = getM3YAngle(pot);
........

float AppSol::getM3xAngle ( csMatrix3 m3 )
{
//Rotation along the X-axis is represented by:
/// 1   0        0       \
//| 0   cos(a)   -sin(a) |
//\ 0   sin(a)   cos(a)  /
return  acos( m3.m22 );
}
float AppSol::getM3yAngle ( csMatrix3 m3 )
{
//Rotation along the Y-axis is represented by:
/// cos(a)   0    -sin(a) \
//| 0        1    0       |
//\ sin(a)   0    cos(a)  /
return acos( m3.m11 );
}

obviously, this does not work but my trig not that good and I cannot work out how to do this.
any help welcome.

Regards
 Logged
jorrit
Hero Member

Posts: 1706

 « Reply #1 on: August 24, 2006, 08:28:05 pm »

I have been tying to work backwards from a mesh's Transform matrix to work out what the mesh's rotation is in radians. Not having much luck.

Here is a bit of code i was trying but it only worked for some angles and i not smart enough to workout what to do next

...........
playermesh = engine->FindMeshObject ( "turret.001" , 0 );
movable = playermesh->GetMovable ();
// Get mesh Position
start = movable->GetTransform().GetOrigin ();
// get mesh Rotation
pot = movable->GetTransform();

rotX = getM3xAngle(pot);
rotY = getM3YAngle(pot);
........

float AppSol::getM3xAngle ( csMatrix3 m3 )
{
//Rotation along the X-axis is represented by:
/// 1   0        0       \
//| 0   cos(a)   -sin(a) |
//\ 0   sin(a)   cos(a)  /
return  acos( m3.m22 );
}
float AppSol::getM3yAngle ( csMatrix3 m3 )
{
//Rotation along the Y-axis is represented by:
/// cos(a)   0    -sin(a) \
//| 0        1    0       |
//\ sin(a)   0    cos(a)  /
return acos( m3.m11 );
}

obviously, this does not work but my trig not that good and I cannot work out how to do this.
any help welcome.

Regards

The easiest (but not most optimal) way to do this in cs would be the following code:

csQuaternion q;
q.SetMatrix (matrix);
csVector3 euler_angles = q.GetEulerAngles ();

Not sure how to do it more optimally then this though.

Greetings,
 Logged
 Pages: [1]