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));
|
||||
}
|
||||
|
||||
|
||||
@@ -55,8 +55,10 @@ public static class OriginalSphereResponse
|
||||
var direction = toEdge / distance;
|
||||
if (Dot(direction, normal) >= 0 || state.EdgeDistance != -1 && distance >= state.EdgeDistance)
|
||||
return unchanged;
|
||||
var edgePosition = nearest - direction * radius;
|
||||
edgePosition.Y = position.Y;
|
||||
//47C194..47C1D0 keeps each X/Z product through the subtraction before
|
||||
//the final float store; Vector3 multiplication would round it early.
|
||||
var edgePosition = new Vector3((float)(nearest.X-(double)direction.X*radius),position.Y,
|
||||
(float)(nearest.Z-(double)direction.Z*radius));
|
||||
return new(edgePosition, state with { EdgeDistance = distance, Hit = nearest }, SphereContact.Edge);
|
||||
}
|
||||
|
||||
@@ -67,7 +69,12 @@ public static class OriginalSphereResponse
|
||||
if (length == 0) return a;
|
||||
var direction = edge / length;
|
||||
var projection = Dot(point - a, direction);
|
||||
return projection < 0 ? a : projection > length ? b : a + direction * projection;
|
||||
if (projection < 0) return a;
|
||||
if (projection > length) return b;
|
||||
//4699A0..4699DE retains X's product until adding the segment origin;
|
||||
//Y/Z products have explicit intervening float stores in the source.
|
||||
return new((float)(a.X+(double)direction.X*projection),
|
||||
a.Y+direction.Y*projection,a.Z+direction.Z*projection);
|
||||
}
|
||||
|
||||
private static float Dot(Vector3 a, Vector3 b) =>
|
||||
|
||||
@@ -8,6 +8,8 @@ public sealed class StaticCollisionContext(float radius, float faceDistance = 13
|
||||
public SphereResponseState Nearest { get; internal set; } = new(faceDistance, radius, null);
|
||||
public CameraRayPolygon? LastPolygon { get; internal set; }
|
||||
public int Passes { get; internal set; }
|
||||
//47B6A8..47B6B9 counts list visits before the geometry-enable gate.
|
||||
public int NodeVisits { get; internal set; }
|
||||
public int TriangleTests { get; internal set; }
|
||||
}
|
||||
|
||||
@@ -100,6 +102,7 @@ public sealed class OriginalStaticCollision
|
||||
if (walls.TryGetValue(cell, out var polygons))
|
||||
foreach (var polygon in polygons)
|
||||
{
|
||||
context.NodeVisits++;
|
||||
if (!geometryEnabled) continue;
|
||||
context.TriangleTests++;
|
||||
var result = OriginalSphereResponse.Resolve(polygon.Triangle, polygon.StoredNormal,
|
||||
|
||||
Reference in new issue
Block a user