47 lines
2.2 KiB
C#
47 lines
2.2 KiB
C#
using System.Numerics;
|
|
|
|
namespace GamePort.Game;
|
|
|
|
/// <summary>473540 degree-to-OMT cache and1003FA60 unit-scale local transform.
|
|
/// Source root is unrotated. OMT1003FC00 subsequently decomposes/re-quantizes its
|
|
/// render matrix; this helper uses its directly recovered hierarchical basis.
|
|
/// See docs/gameplay/jimmy-render-transform.md for native evidence/limits.</summary>
|
|
public static class JimmyRenderTransform
|
|
{
|
|
public static int AngleUnits(float degrees)
|
|
{
|
|
if (!float.IsFinite(degrees)) throw new ArgumentOutOfRangeException(nameof(degrees));
|
|
return (int)Math.Truncate(((double)degrees % 360) * 45.51111111111111) & 16383;
|
|
}
|
|
|
|
public static Matrix4x4 Source(Vector3 root, Vector3 euler)
|
|
{
|
|
Finite(root);
|
|
var (sx,cx) = RocketOrientation.Units(AngleUnits(euler.X));
|
|
var (sy,cy) = RocketOrientation.Units(AngleUnits(euler.Y));
|
|
var (sz,cz) = RocketOrientation.Units(AngleUnits(euler.Z));
|
|
//Row-vector convention: Rz(-roll), then Rx(-pitch), then Ry(-yaw).
|
|
//The translation is the unchanged actor root, independent of all axes.
|
|
return new(
|
|
(float)((double)cz*cy-(double)sz*sx*sy), -sz*cx, (float)((double)cz*sy+(double)sz*sx*cy), 0,
|
|
(float)((double)sz*cy+(double)cz*sx*sy), cz*cx, (float)((double)sz*sy-(double)cz*sx*cy), 0,
|
|
-cx*sy, sx, cx*cy, 0,
|
|
root.X, root.Y, root.Z, 1);
|
|
}
|
|
|
|
/// <summary>Modern compatibility adapter, not an original recovered offset.
|
|
/// A fixed sole-derived correction is local to the model, so full-axis tilt
|
|
/// remains around the source logical root and upright placement is preserved.</summary>
|
|
public static Matrix4x4 Aligned(Vector3 root, Vector3 euler, float localYCorrection)
|
|
{
|
|
if (!float.IsFinite(localYCorrection)) throw new ArgumentOutOfRangeException(nameof(localYCorrection));
|
|
return Matrix4x4.CreateTranslation(0,localYCorrection,0) * Source(root,euler);
|
|
}
|
|
|
|
private static void Finite(Vector3 value)
|
|
{
|
|
if (!float.IsFinite(value.X) || !float.IsFinite(value.Y) || !float.IsFinite(value.Z))
|
|
throw new ArgumentOutOfRangeException(nameof(value));
|
|
}
|
|
}
|