Here is a nifty set of functions for use in converting between Euler and axis angles.

The basic usage for eulerToAxis() is this:

`%obj.setTransform(%position SPC eulerToAxis(%x SPC %y SPC %z));`

Note: Using **eulerToMatrix()** in the example above **produces incorrect results**.

The basic usage for axisToEuler() is this:

`%eulerRot = axisToEuler(getWords(%obj.getTransform(),3,6));`

Note: **Do not use** axisToEuler() **with %obj.rotation**, as it produces incorrect results.

Now for the code:

`function eulerToAxis(%euler)`

{

%euler = VectorScale(%euler,$pi / 180);

%matrix = MatrixCreateFromEuler(%euler);

return getWords(%matrix,3,6);

}

function axisToEuler(%axis)

{

%angleOver2 = getWord(%axis,3) * 0.5;

%angleOver2 = -%angleOver2;

%sinThetaOver2 = mSin(%angleOver2);

%cosThetaOver2 = mCos(%angleOver2);

%q0 = %cosThetaOver2;

%q1 = getWord(%axis,0) * %sinThetaOver2;

%q2 = getWord(%axis,1) * %sinThetaOver2;

%q3 = getWord(%axis,2) * %sinThetaOver2;

%q0q0 = %q0 * %q0;

%q1q2 = %q1 * %q2;

%q0q3 = %q0 * %q3;

%q1q3 = %q1 * %q3;

%q0q2 = %q0 * %q2;

%q2q2 = %q2 * %q2;

%q2q3 = %q2 * %q3;

%q0q1 = %q0 * %q1;

%q3q3 = %q3 * %q3;

%m13 = 2.0 * (%q1q3 - %q0q2);

%m21 = 2.0 * (%q1q2 - %q0q3);

%m22 = 2.0 * %q0q0 - 1.0 + 2.0 * %q2q2;

%m23 = 2.0 * (%q2q3 + %q0q1);

%m33 = 2.0 * %q0q0 - 1.0 + 2.0 * %q3q3;

return mRadToDeg(mAsin(%m23)) SPC mRadToDeg(mAtan(-%m13, %m33)) SPC mRadToDeg(mAtan(-%m21, %m22));

}