移除物理引擎 移动到新库

This commit is contained in:
yhh
2020-06-15 10:42:06 +08:00
parent 7f8f1cf0d0
commit 16892eb7af
21 changed files with 553 additions and 1118 deletions

View File

@@ -0,0 +1,28 @@
///<reference path="./Polygon.ts" />
class Box extends Polygon {
public width: number;
public height: number;
public updateBox(width: number, height: number){
this.width = width;
this.height = height;
let halfWidth = width / 2;
let halfHeight = height / 2;
this.points[0] = new Vector2(-halfWidth, -halfHeight);
this.points[1] = new Vector2(halfWidth, -halfHeight);
this.points[2] = new Vector2(halfWidth, halfHeight);
this.points[3] = new Vector2(-halfWidth, halfHeight);
for (let i = 0; i < this.points.length; i ++)
this._originalPoints[i] = this.points[i];
}
public containsPoint(point: Vector2){
if (this.isUnrotated)
return this.bounds.contains(point);
return super.containsPoint(point);
}
}

View File

@@ -14,8 +14,8 @@ class Circle extends Shape {
}
public collidesWithShape(other: Shape): CollisionResult{
if (other instanceof Rect && (other as Rect).isUnrotated){
return ShapeCollisions.circleToRect(this, other as Rect);
if (other instanceof Box && (other as Box).isUnrotated){
return ShapeCollisions.circleToRect(this, other as Box);
}
throw new Error(`Collisions of Circle to ${other} are not supported`);

View File

@@ -4,7 +4,7 @@ class Polygon extends Shape {
public isUnrotated: boolean = true;
private _polygonCenter: Vector2;
private _areEdgeNormalsDirty = true;
private _originalPoint: Vector2[];
protected _originalPoints: Vector2[];
public _edgeNormals: Vector2[];
public get edgeNormals(){
@@ -42,8 +42,8 @@ class Polygon extends Shape {
this.points = points;
this.recalculateCenterAndEdgeNormals();
this._originalPoint = new Vector2[points.length];
this._originalPoint = points;
this._originalPoints = new Vector2[points.length];
this._originalPoints = points;
}
public collidesWithShape(other: Shape){

View File

@@ -1,8 +0,0 @@
class Rect extends Polygon {
public containsPoint(point: Vector2){
if (this.isUnrotated)
return this.bounds.contains(point);
return super.containsPoint(point);
}
}

View File

@@ -32,7 +32,7 @@ class ShapeCollisions {
}
}
public static circleToRect(circle: Circle, box: Rect): CollisionResult{
public static circleToRect(circle: Circle, box: Box): CollisionResult{
let result = new CollisionResult();
let closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position).res;