完善shapeCollision 支持多边形

This commit is contained in:
YHH
2020-06-16 00:04:28 +08:00
parent 5186bc0187
commit dba43b9773
22 changed files with 872 additions and 94 deletions

View File

@@ -56,6 +56,24 @@ class Polygon extends Shape {
this._areEdgeNormalsDirty = true;
}
public overlaps(other: Shape){
let result: CollisionResult;
if (other instanceof Polygon)
return ShapeCollisions.polygonToPolygon(this, other);
if (other instanceof Circle){
result = ShapeCollisions.circleToPolygon(other, this);
if (result){
result.invertResult();
return true;
}
return false;
}
throw new Error(`overlaps of Pologon to ${other} are not supported`);
}
public static findPolygonCenter(points: Vector2[]) {
let x = 0, y = 0;