Refactor: CollisionDetectionInformation Names
This commit is contained in:
parent
4856800f5f
commit
55ed8b84f6
|
@ -6,14 +6,16 @@ namespace Syntriax.Engine.Physics2D;
|
||||||
[System.Diagnostics.DebuggerDisplay("Normal: {Normal.ToString(), nq}, Penetration: {Penetration}")]
|
[System.Diagnostics.DebuggerDisplay("Normal: {Normal.ToString(), nq}, Penetration: {Penetration}")]
|
||||||
public readonly struct CollisionDetectionInformation
|
public readonly struct CollisionDetectionInformation
|
||||||
(
|
(
|
||||||
ICollider2D Left,
|
ICollider2D Detector,
|
||||||
ICollider2D Right,
|
ICollider2D Detected,
|
||||||
Vector2D Normal,
|
Vector2D Normal,
|
||||||
float Penetration
|
float Penetration
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
public ICollider2D Left { get; init; } = Left;
|
public ICollider2D Detector { get; init; } = Detector;
|
||||||
public ICollider2D Right { get; init; } = Right;
|
public ICollider2D Detected { get; init; } = Detected;
|
||||||
public Vector2D Normal { get; init; } = Normal;
|
public Vector2D Normal { get; init; } = Normal;
|
||||||
public float Penetration { get; init; } = Penetration;
|
public float Penetration { get; init; } = Penetration;
|
||||||
|
|
||||||
|
public CollisionDetectionInformation Reverse() => new(Detected, Detector, -Normal, Penetration);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class CollisionDetector2D : ICollisionDetector2D
|
||||||
if (!leftProjection.Overlaps(rightProjection, out float depth))
|
if (!leftProjection.Overlaps(rightProjection, out float depth))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (collisionInformation.Left is null || Math.Abs(collisionInformation.Penetration) > Math.Abs(depth))
|
if (collisionInformation.Detector is null || Math.Abs(collisionInformation.Penetration) > Math.Abs(depth))
|
||||||
collisionInformation = new(left, right, projectionVector, depth);
|
collisionInformation = new(left, right, projectionVector, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ public class CollisionDetector2D : ICollisionDetector2D
|
||||||
if (!shapeProjection.Overlaps(circleProjection, out float depth))
|
if (!shapeProjection.Overlaps(circleProjection, out float depth))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (collisionInformation.Left is null || Math.Abs(collisionInformation.Penetration) > Math.Abs(depth))
|
if (collisionInformation.Detector is null || Math.Abs(collisionInformation.Penetration) > Math.Abs(depth))
|
||||||
collisionInformation = new(shapeCollider, circleCollider, projectionVector, depth);
|
collisionInformation = new(shapeCollider, circleCollider, projectionVector, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ public class CollisionDetector2D : ICollisionDetector2D
|
||||||
if (!shapeProjection.Overlaps(circleProjection, out float depth))
|
if (!shapeProjection.Overlaps(circleProjection, out float depth))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (collisionInformation.Left is null || Math.Abs(collisionInformation.Penetration) > Math.Abs(depth))
|
if (collisionInformation.Detector is null || Math.Abs(collisionInformation.Penetration) > Math.Abs(depth))
|
||||||
collisionInformation = new(shapeCollider, circleCollider, shapeToCircleProjectionVector, depth);
|
collisionInformation = new(shapeCollider, circleCollider, shapeToCircleProjectionVector, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ public class CollisionResolver2D : ICollisionResolver2D
|
||||||
{
|
{
|
||||||
Vector2D displacementVector = collisionInformation.Normal * collisionInformation.Penetration;
|
Vector2D displacementVector = collisionInformation.Normal * collisionInformation.Penetration;
|
||||||
|
|
||||||
ICollider2D left = collisionInformation.Left;
|
ICollider2D left = collisionInformation.Detector;
|
||||||
ICollider2D right = collisionInformation.Right;
|
ICollider2D right = collisionInformation.Detected;
|
||||||
|
|
||||||
bool isLeftStatic = left.RigidBody2D?.IsStatic ?? true;
|
bool isLeftStatic = left.RigidBody2D?.IsStatic ?? true;
|
||||||
bool isRightStatic = right.RigidBody2D?.IsStatic ?? true;
|
bool isRightStatic = right.RigidBody2D?.IsStatic ?? true;
|
||||||
|
|
|
@ -91,8 +91,16 @@ public class PhysicsEngine2D : IPhysicsEngine2D
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (information.Detector == colliderX)
|
||||||
|
{
|
||||||
colliderX.Detect(information);
|
colliderX.Detect(information);
|
||||||
|
colliderY.Detect(information.Reverse());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
colliderX.Detect(information.Reverse());
|
||||||
colliderY.Detect(information);
|
colliderY.Detect(information);
|
||||||
|
}
|
||||||
|
|
||||||
collisionResolver?.Resolve(information);
|
collisionResolver?.Resolve(information);
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,8 +73,16 @@ public class PhysicsEngine2DCollector : HierarchyObjectBase, IPhysicsEngine2D
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (information.Detector == colliderX)
|
||||||
|
{
|
||||||
colliderX.Detect(information);
|
colliderX.Detect(information);
|
||||||
|
colliderY.Detect(information.Reverse());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
colliderX.Detect(information.Reverse());
|
||||||
colliderY.Detect(information);
|
colliderY.Detect(information);
|
||||||
|
}
|
||||||
|
|
||||||
collisionResolver?.Resolve(information);
|
collisionResolver?.Resolve(information);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue