48 lines
2.2 KiB
C#
48 lines
2.2 KiB
C#
using System.Numerics;
|
|
using GamePort.Game;
|
|
|
|
// Source vector::angles cardinal/quadrant results, plus copied-DLL references.
|
|
var samples = new (Vector3 Direction, int Units)[]
|
|
{
|
|
(Vector3.Zero, 0), (Vector3.UnitZ, 0), (-Vector3.UnitX, 4096),
|
|
(-Vector3.UnitZ, 8192), (Vector3.UnitX, 12288),
|
|
(new(-1, 0, 1), 2048), (new(-1, 0, -1), 6144),
|
|
(new(1, 0, -1), 10240), (new(1, 0, 1), 14336),
|
|
(new(1, 100, 1000), 16364), (new(-1, -100, 1000), 20),
|
|
(new(1000, 0, 1), 12288), (new(-1000, 0, 1), 4096),
|
|
(new(.1234567f, 88, .7654321f), 15967), (new(-99.1f, -20, 15.7f), 3686),
|
|
};
|
|
foreach (var (direction, units) in samples)
|
|
{
|
|
float actual = OriginalHeading.Degrees(direction);
|
|
if (actual != units * 0.02197265625f)
|
|
throw new Exception($"Heading {direction}: expected {units} units, got {actual} degrees");
|
|
}
|
|
foreach (var bad in new[] { new Vector3(float.NaN, 0, 1), new Vector3(0, float.PositiveInfinity, 1) })
|
|
{
|
|
try { OriginalHeading.Degrees(bad); throw new Exception("Nonfinite vector accepted"); }
|
|
catch (ArgumentOutOfRangeException) { }
|
|
}
|
|
// A seam-crossing near-forward direction remains near360; the caller performs
|
|
// the original strict comparisons against Jimmy's EulerY without wrapping.
|
|
float seam = OriginalHeading.Degrees(new Vector3(1, 0, 1000));
|
|
if (seam is not (> 355 and < 360)) throw new Exception("Heading seam normalized away");
|
|
if (-5 < seam && seam < 5) throw new Exception("Source seam comparison changed");
|
|
uint hash = 2166136261;
|
|
int cases = 0;
|
|
for (int i = 0; i <= 16384; i++)
|
|
{
|
|
float a = (float)Math.Sqrt((i + .25) / 16384.5);
|
|
float b = (float)Math.Sqrt(1 - (i + .25) / 16384.5);
|
|
for (int quadrant = 0; quadrant < 4; quadrant++)
|
|
{
|
|
var direction = new Vector3((quadrant & 1) != 0 ? -b : b, 0, (quadrant & 2) != 0 ? -a : a);
|
|
ushort units = (ushort)(OriginalHeading.Degrees(direction) / .02197265625f);
|
|
hash = unchecked((hash ^ units) * 16777619);
|
|
cases++;
|
|
}
|
|
}
|
|
// Observed through the copied OMT2.dll export, heading-probe/wine.log.
|
|
if (hash != 0x24e64f91) throw new Exception($"Original-DLL sweep mismatch: {hash:x8}");
|
|
Console.WriteLine($"Heading: {samples.Length} copied-DLL references, {cases} sweep cases, finite guards and unwrapped seam passed.");
|