Add rotation to .gob info

Port From (https://github.com/TrinityCore/TrinityCore/commit/afac2b174290c871d845e37f88c6f0c874d15fd6)
This commit is contained in:
hondacrx
2021-11-15 23:06:07 -05:00
parent 5b65a04358
commit 2aa910e9f6
3 changed files with 64 additions and 39 deletions
+32
View File
@@ -258,6 +258,38 @@ namespace System
}
}
public static void toEulerAnglesZYX(this Quaternion quaternion, out float z, out float y, out float x)
{
// rot = cy*cz cz*sx*sy-cx*sz cx*cz*sy+sx*sz
// cy*sz cx*cz+sx*sy*sz -cz*sx+cx*sy*sz
// -sy cy*sx cx*cy
var matrix = Matrix4x4.CreateFromQuaternion(quaternion);
if (matrix.M31 < 1.0)
{
if (matrix.M31 > -1.0)
{
z = MathF.Atan2(matrix.M21, matrix.M11);
y = MathF.Asin(-matrix.M31);
x = MathF.Atan2(matrix.M31, matrix.M33);
}
else
{
// WARNING. Not unique. ZA - XA = -atan2(r01,r02)
z = -(float)MathF.Atan2(matrix.M12, matrix.M13);
y = MathFunctions.PiOver2;
x = 0.0f;
}
}
else
{
// WARNING. Not unique. ZA + XA = atan2(-r01,-r02)
z = (float)MathF.Atan2(-matrix.M12, -matrix.M13);
y = -MathFunctions.PiOver2;
x = 0.0f;
}
}
public static Matrix4x4 fromEulerAnglesZYX(float fYAngle, float fPAngle, float fRAngle)
{
float fCos = (float)Math.Cos(fYAngle);