// CREATE OBJECTS A & B
var A = ActiveSceneRoot.AddNull("A");
var B = ActiveSceneRoot.AddNull("B");
// GET GLOBAL TRANSFORM OF A & B
var gksA = A.kinematics.global;
var gksB = B.kinematics.global;
var tgA = gksA.transform;
var tgB = gksB.transform;
// TRANSLATE & ROTATE A
var vA = XSIMath.CreateVector3(2, 2, 0);
tgA.SetTranslation( vA );
var rA = XSIMath.CreateRotation();
rA.SetFromXYZAnglesValues( 0, 0, XSIMath.DegreesToRadians( 45 ) );
tgA.SetRotation( rA );
gksA.transform = tgA;
// GET LOCAL TRANSFORM OF B RELATIVE TO A
var mA = XSIMath.CreateMatrix3();
var mB = XSIMath.CreateMatrix3();
tgA.GetRotationMatrix3(mA);
tgB.GetRotationMatrix3(mB);
mA.TransposeInPlace();
mB.MulInPlace( mA );
// GET ORIENTATION OF B RELATIVE TO A AS A QUATERNION
var qB = XSIMath.CreateQuaternion();
mB.GetQuaternion(qB);
// log result
var aXYZ = new VBArray(qB.GetXYZAngleValues2()).toArray();
Application.LogMessage( "R(" +
XSIMath.RadiansToDegrees(aXYZ[0]) + "," +
XSIMath.RadiansToDegrees(aXYZ[1]) + "," +
XSIMath.RadiansToDegrees(aXYZ[2]) + ")" ); |