Object Hierarchy | Related C++ Class: CRotation
This object represents a rotation in 3D space. It supports three representation methods:
X, Y and Z Euler angles, Quaternion and 3 by 3 matrix.
Note: When represented as X,Y,Z Euler angles the values are always in Radians, not degrees.
/* Demonstrates different representations of a rotation: -As a SIRotation object -As a 3x3 matrix -As a 4x4 matrix -As a SITransformation object -As a SIVector3 object */ var oSIRotation = XSIMath.CreateRotation( XSIMath.DegreesToRadians( 45 ), XSIMath.DegreesToRadians( 30 ), XSIMath.DegreesToRadians( 15 ) ) ; oSIMatrix3 = XSIMath.CreateMatrix3() ; oSIRotation.GetMatrix3( oSIMatrix3 ) ; oSIMatrix4 = ConvertMatrix3ToMatrix4( oSIMatrix3 ) ; oSITransformation = XSIMath.CreateTransform() ; oSITransformation.SetMatrix4( oSIMatrix4 ) ; var oSIVector3 = XSIMath.CreateVector3() ; oSITransformation.GetRotationXYZAngles( oSIVector3 ) ; // Prove that we haven't lost the original rotation values Application.LogMessage( "Rotation " + XSIMath.RadiansToDegrees( oSIVector3.X ) + ", " + XSIMath.RadiansToDegrees( oSIVector3.Y ) + ", " + XSIMath.RadiansToDegrees( oSIVector3.Z ) ) ; // Output (notice very small rounding problems that occur // when dealing with pi and trig functions): //INFO : Rotation 45, 29.999999999999996, 14.999999999999998 function ConvertMatrix3ToMatrix4( oM3 ) { // Helper function to convert 3x3 rotation matrix // to equivalent 4x4 transformation matrix: // // r11 r12 r13 0 // r21 r22 r23 0 // r31 r32 r33 0 // 0 0 0 1 oSIMatrix4 = XSIMath.CreateMatrix4( oM3(0,0), oM3(0,1), oM3(0,2), 0, oM3(1,0), oM3(1,1), oM3(1,2), 0, oM3(2,0), oM3(2,1), oM3(2,2), 0, 0, 0, 0, 1 ) ; return oSIMatrix4 ; } |