Match original collision rounding through populated dynamic reclip
This commit is contained in:
1 parent
135ff3642a
commit
bf876e9c3c
22 files changed
+701
-14
No files matched your search
@@ -30,7 +30,11 @@ public static class OriginalBodySupport
|
||||
private static readonly ushort[] halfAcos = BuildHalfAcos();
|
||||
|
||||
/// <summary>OMT1001FF70: largest component divided by a quantized sine lookup.</summary>
|
||||
public static float QuickMagnitude(Vector3 vector)
|
||||
public static float QuickMagnitude(Vector3 vector) => (float)QuickMagnitudeIntermediate(vector);
|
||||
|
||||
// OMT returns its quotient in an x87 register. Callers with no intervening
|
||||
// float store must retain that intermediate; this is not general x87 emulation.
|
||||
internal static double QuickMagnitudeIntermediate(Vector3 vector)
|
||||
{
|
||||
RequireFinite(vector);
|
||||
var x = (double)MathF.Abs(vector.X);
|
||||
@@ -43,7 +47,7 @@ public static class OriginalBodySupport
|
||||
if (z == 0) return 0;
|
||||
var otherSquared = x * x + y * y;
|
||||
var index = (int)(otherSquared * 16384 / (otherSquared + z * z)) & 0x3fff;
|
||||
return (float)(z / sine[halfAcos[index] & 0x3fff]);
|
||||
return z / sine[halfAcos[index] & 0x3fff];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -100,11 +104,13 @@ public static class OriginalBodySupport
|
||||
ArgumentNullException.ThrowIfNull(triangles);
|
||||
RequireFinite(start); RequireFinite(end);
|
||||
var direction = end - start;
|
||||
var length = QuickMagnitude(direction);
|
||||
var length = QuickMagnitudeIntermediate(direction);
|
||||
if (length == 0) return null;
|
||||
direction /= length;
|
||||
var reciprocal = 1 / length;
|
||||
direction = new((float)(direction.X*reciprocal),(float)(direction.Y*reciprocal),
|
||||
(float)(direction.Z*reciprocal));
|
||||
SupportHit? nearest = null;
|
||||
var nearestDistance = length;
|
||||
var nearestDistance = (float)length;
|
||||
foreach (var triangle in triangles)
|
||||
{
|
||||
var hit = IntersectSegment(triangle, start, direction, length, twoSided);
|
||||
@@ -124,13 +130,15 @@ public static class OriginalBodySupport
|
||||
{
|
||||
RequireFinite(start); RequireFinite(end);
|
||||
var direction = end - start;
|
||||
var length = QuickMagnitude(direction);
|
||||
var length = QuickMagnitudeIntermediate(direction);
|
||||
if (length == 0) return null;
|
||||
return IntersectSegment(triangle, start, direction / length, length, twoSided);
|
||||
var reciprocal = 1 / length;
|
||||
return IntersectSegment(triangle, start,new((float)(direction.X*reciprocal),
|
||||
(float)(direction.Y*reciprocal),(float)(direction.Z*reciprocal)),length,twoSided);
|
||||
}
|
||||
|
||||
private static SupportHit? IntersectSegment(SupportTriangle triangle,
|
||||
Vector3 start, Vector3 direction, float length, bool twoSided)
|
||||
Vector3 start, Vector3 direction, double length, bool twoSided)
|
||||
{
|
||||
RequireFinite(triangle.A); RequireFinite(triangle.B); RequireFinite(triangle.C);
|
||||
var edge1 = triangle.B - triangle.A;
|
||||
@@ -150,7 +158,10 @@ public static class OriginalBodySupport
|
||||
var distance = Dot(q, edge2) * inverse;
|
||||
// Beginning accepted, endpoint rejected; no invented camera radius/skin.
|
||||
if (distance < 0 || distance >= length) return null;
|
||||
var position = start + direction * distance;
|
||||
//469DF0..469E13 stores each hit coordinate only after multiply+add.
|
||||
//Keep the product until that store, including near-cancelling inputs.
|
||||
var position = new Vector3((float)(start.X+(double)direction.X*distance),
|
||||
(float)(start.Y+(double)direction.Y*distance),(float)(start.Z+(double)direction.Z*distance));
|
||||
return new SupportHit(position, triangle.ShapeId, triangle.PolygonId, QuickMagnitude(position - start));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user