移除物理引擎 移动到新库
This commit is contained in:
28
source/src/Physics/Shapes/Box.ts
Normal file
28
source/src/Physics/Shapes/Box.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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`);
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
class Rect extends Polygon {
|
||||
public containsPoint(point: Vector2){
|
||||
if (this.isUnrotated)
|
||||
return this.bounds.contains(point);
|
||||
|
||||
return super.containsPoint(point);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user