Author Topic: Finding a Player's Roll Degree  (Read 603 times)

I don't know how to find the roll. I've gotten pitch and yaw, but not roll.

Any help?

You mean when they are in a vehicle?

Because, your head can't face anywhere other than up, without skis/a vehicle.

I don't want the roll value to rely on the vehicle.

So, the player in general. Inside, or outside, a vehicle.

Code: [Select]
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));
}

Assuming %t will be their transform:
Code: [Select]
%rot = axisToEuler(getWords(%t, 3, 9));And %rot will be something like this:
180.482 24.142 4.2039
Yaw Roll Pitch

You mean to tell me that this is my full equation?

Code: [Select]
mRadToDeg(mATan(-(2.0 * (((getWord(%axis,0) * mSin(-(getWord(%axis,3) * 0.5))) * (getWord(%axis,2) * mSin(-(getWord(%axis,3) * 0.5)))) - (mCos(-(getWord(%axis,3) * 0.5)) * (getWord(%axis,1) * mSin(-(getWord(%axis,3) * 0.5)))))), (2.0 * (mCos(-(getWord(%axis,3) * 0.5)) * mCos(-(getWord(%axis,3) * 0.5))) - 1.0 + 2.0 * ((getWord(%axis,2) * mSin(-(getWord(%axis,3) * 0.5))) * (getWord(%axis,2) * mSin(-(getWord(%axis,3) * 0.5)))))))
I got Pitch with one command, and Yaw with two.

Wait, where's %axis defined?


I got it to work, but it's off a bit.

For one, you got Yaw and Pitch backwards.

Two, Yaw is inversed. 90 should be east, yet it is -90.

Roll is fine, I think, and that's all that I really needed.

Just letting you know.
« Last Edit: September 14, 2010, 07:36:39 PM by Deathwishez »