feat: Basic Shape to Shape Collision Detection
This commit is contained in:
parent
2bfd391286
commit
c6d2bad23e
|
@ -38,7 +38,26 @@ public class CollisionDetector : ICollisionDetector
|
|||
|
||||
private static bool DetectShapeShape(IShapeCollider2D left, IShapeCollider2D right, out CollisionDetectionInformation? collisionInformation)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
collisionInformation = default;
|
||||
|
||||
var vertices = left.ShapeWorld.Vertices;
|
||||
int count = vertices.Count;
|
||||
|
||||
for (int indexProjection = 0; indexProjection < count; indexProjection++)
|
||||
{
|
||||
Vector2D projectionVector = vertices[indexProjection].FromTo(vertices[(indexProjection + 1) % count]).Perpendicular().Normalized;
|
||||
|
||||
Projection leftProjection = left.ShapeWorld.ToProjection(projectionVector);
|
||||
Projection rightProjection = right.ShapeWorld.ToProjection(projectionVector);
|
||||
|
||||
if (!leftProjection.Overlaps(rightProjection, out float depth))
|
||||
return false;
|
||||
|
||||
if (collisionInformation == default || Math.Abs(collisionInformation.Penetration) > Math.Abs(depth))
|
||||
collisionInformation = new(left, right, projectionVector, depth);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool DetectShapeCircle(IShapeCollider2D shapeCollider, ICircleCollider2D circleCollider, out CollisionDetectionInformation? collisionInformation)
|
||||
|
|
Loading…
Reference in New Issue