public static bool TestIShapeWithConcavePolygon(IShape shape, Vector2 shapePos, Polygon concavePolygon, out Contact?contact) { List <Vector2[]> concavePolygonComponents = concavePolygon.ConvexComponents(); Vector2 concavePolygonAnchor = concavePolygon[0]; Vector2[] shapeAxes = shape.CalculateAxes(); Vector2[] axes; foreach (Vector2[] component in concavePolygonComponents) { Polygon componentPolygon = new Polygon(component); componentPolygon.Translate(concavePolygonAnchor); axes = new Vector2[shapeAxes.Length + componentPolygon.Normals.Length]; shapeAxes.CopyTo(axes, 0); componentPolygon.Normals.CopyTo(axes, shapeAxes.Length); if (TestIShapeWithConvexPolygon(shape, shapePos, componentPolygon, axes, out contact)) { return(true); } } contact = null; return(false); }
public static bool TestIShapeWithConvexPolygon(IShape shape, Vector2 shapePos, Polygon polygon, out Contact?contact) { Vector2[] shapeAxes = shape.CalculateAxes(); Vector2[] axes = new Vector2[shapeAxes.Length + polygon.Normals.Length]; shapeAxes.CopyTo(axes, 0); polygon.Normals.CopyTo(axes, shapeAxes.Length); return(TestIShapeWithConvexPolygon(shape, shapePos, polygon, polygon.Normals, out contact)); }
public static bool TestIShapeWithIShape(IShape shapeA, Vector2 posA, IShape shapeB, Vector2 posB, out Contact?contact) { Vector2[] shapeAAxes = shapeA.CalculateAxes(), shapeBAxes = shapeB.CalculateAxes(); Vector2[] axes = new Vector2[shapeAAxes.Length + shapeBAxes.Length]; shapeAAxes.CopyTo(axes, 0); shapeBAxes.CopyTo(axes, shapeAAxes.Length); return(TestIShapeWithIShape(shapeA, posA, shapeB, posB, axes, out contact)); }
public static bool TestLineSegmentWithIShape(Vector2 startPoint, Vector2 endPoint, IShape shape, Vector2 shapePos, out Contact?contact) { Vector2[] shapeAxes = shape.CalculateAxes(); Vector2[] axes = new Vector2[2 + shapeAxes.Length]; Vector2 direction = (endPoint - startPoint).Normalized(); axes[0] = direction; axes[1] = direction.PerpendicularCW(); shapeAxes.CopyTo(axes, 2); return(TestLineSegmentWithIShape(startPoint, endPoint, shape, shapePos, axes, out contact)); }