Implement original gadget panel and playable shrink ray

This commit is contained in:
UnixNight committed 2026-10-27 12:18:45 -04:00
1 parent 0272f7bef7
commit 7b5230ceb8
57 files changed
+3545 -48

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
using System.Numerics;
namespace GamePort.Game;
/// <summary>OMT2 vector::angles second output used by the original shrink ray.</summary>
public static class OriginalHeading
{
private static readonly ushort[] halfAcos = BuildHalfAcos();
public static float Degrees(Vector3 vector)
{
if (!float.IsFinite(vector.X) || !float.IsFinite(vector.Y) || !float.IsFinite(vector.Z))
throw new ArgumentOutOfRangeException(nameof(vector), "A finite direction is required.");
double x = vector.X, z = vector.Z;
if (x == 0 && z == 0) return 0;
// DLL1001FDCB..1001FE3D: truncate the squared ratio, table lookup,
// quadrant correction, negate and mask to the original 14-bit circle.
// Double intermediates approximate x87 extended precision; see findings.
int index = (int)(16384.0 * z * z / (x * x + z * z));
int angle = halfAcos[index];
if (z < 0)
angle = x < 0 ? 8192 + angle : 8192 - angle;
else if (x < 0)
angle = 16384 - angle;
return ((-angle) & 0x3fff) * 0.02197265625f;
}
private static ushort[] BuildHalfAcos()
{
var table = new ushort[16385];
// Stored DLL constants; final endpoint is explicitly zero at100EDD0D.
for (int i = 0; i < 16384; i++)
table[i] = (ushort)(Math.Acos(i * 0.0001220703125 - 1)
* 2607.5945876921437 * 0.5);
return table;
}
}