Author Topic: How does Torque rotation work?  (Read 907 times)

Realistically I don't even know what I'm about to ask. I don't have the first clue how to describe this problem.

So, I have this static shape right
Code: [Select]
%s = new StaticShape()
{
datablock = WhateverStatic;
position = %pos;
rotation = %rot;
};

If I was to put in this for the rotation
Code: [Select]
rotation = "1 0 0 90";

It appears that it would rotate the shape 90 degrees on it's X axis. Makes sense... I think?
But when you do this:

Code: [Select]
rotation = "1 1 0 90";

What I would expect to happen is it to rotate 90 degrees on it's X axis and then 90 degrees on it's Y axis. But, it doesn't do that. It gives me some weird ass angle. I'm guessing that the first three values are going to be the x, y and z of a Vector, and then I guess it'll rotate the object around that vector's axis? This is a really interesting way of rotating something.

So, realistically, what I'd like to know is what is the steps to get from a directional vector, for example "0 0 1" which goes up, and convert it to Torque's rotation system with 4 values.

I dug really deep into the GarageGames community forums and did some research, and made a function that converts a 3 value Euler sequence into Torque's "X Y Z θ" notation.

I'll post it here in-case someone with the same problem stumbles across this thread and finds as much use in it as I did. To use it go in-game and type "/CalculateRotation X Y Z" and it will put the 4 value vector needed for rotation in your console
Code: [Select]
function servercmdCalculateRotation(%client, %a, %b, %c)
{
%rotinf = MatrixCreateFromEuler(mDegtoRad(%a) SPC mDegtoRad(%b) SPC mDegtoRad(%c));
echo(getWord(%rotinf, 3) SPC getWord(%rotinf, 4) SPC getWord(%rotinf, 5) SPC mRadtoDeg(getWord(%rotinf, 6)));
}
« Last Edit: June 04, 2016, 10:06:28 AM by Rally »

I personally use the Angle system from regular fxDTSBricks.

Code: [Select]
angleID = %angle;
rotation = rotationFromAngleID(%angle);

Now rotationFromAngleID(); does that. Returns the XYZθ by hard-coding but I've yet to see any issues with this.

Code: [Select]
function rotationFromAngleID(%angle)
{
    switch(%angle)
    {
        case 0:
            %rotation = "1 0 0 0";
        case 1:
            %rotation = "0 0 1 90";
        case 2:
            %rotation = "0 0 1 180";
        default:
            %rotation = "0 0 -1 90";
    }
    return %rotation;
}

What about using eulerToMatrix( "0 0 0" ); instead for rotations?

Wow, look what I found.

Badspot had this issue in 2002 and came to a similar solution. And it's one of Blockland's own functions. forget me right

What about using eulerToMatrix( "0 0 0" ); instead for rotations?

I tried it at some point and it didn't work, and I couldn't find any documentation on it. Probably because it was written by Badspot lmao.
« Last Edit: June 06, 2016, 10:04:12 PM by Rally »

You have to include those given functions in that topic into your code as far as i know.
Code: [Select]
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));
}
« Last Edit: June 07, 2016, 11:31:36 AM by lordician »