Crystal Space
Welcome, Guest. Please login or register.
August 21, 2014, 05:09:09 pm

Login with username, password and session length
Search:     Advanced search
9012 Posts in 2050 Topics by 8332 Members
Latest Member: Msquartcarle03
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  Rotate , convert transform matrix to radians?
« previous next »
Pages: [1] Print
Author Topic: Rotate , convert transform matrix to radians?  (Read 1492 times)
Recon
Newbie
*
Posts: 24


View Profile
« 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
Administrator
Hero Member
*****
Posts: 1706


View Profile
« 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] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 5.201 seconds with 15 queries.