修复polygon数组错误 修复emit空注册报错
This commit is contained in:
@@ -18,6 +18,18 @@ class Circle extends Shape {
|
||||
return ShapeCollisions.circleToRect(this, other as Box);
|
||||
}
|
||||
|
||||
if (other instanceof Circle){
|
||||
// TODO CIRCLETOCIRCLE
|
||||
}
|
||||
|
||||
if (other instanceof Polygon){
|
||||
return ShapeCollisions.circleToPolygon(this, other);
|
||||
}
|
||||
|
||||
throw new Error(`Collisions of Circle to ${other} are not supported`);
|
||||
}
|
||||
|
||||
public recalculateBounds(collider: Collider) {
|
||||
this.center = collider.localOffset;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ class Polygon extends Shape {
|
||||
private buildEdgeNormals(){
|
||||
let totalEdges = this.isBox ? 2 : this.points.length;
|
||||
if (this._edgeNormals == null || this._edgeNormals.length != totalEdges)
|
||||
this._edgeNormals = new Vector2[totalEdges];
|
||||
this._edgeNormals = new Array(totalEdges);
|
||||
|
||||
let p2: Vector2;
|
||||
for (let i = 0; i < totalEdges; i ++){
|
||||
@@ -42,7 +42,7 @@ class Polygon extends Shape {
|
||||
this.points = points;
|
||||
this.recalculateCenterAndEdgeNormals();
|
||||
|
||||
this._originalPoints = new Vector2[points.length];
|
||||
this._originalPoints = new Array(points.length);
|
||||
this._originalPoints = points;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ class Polygon extends Shape {
|
||||
}
|
||||
|
||||
public static buildSymmertricalPolygon(vertCount: number, radius: number) {
|
||||
let verts = new Vector2[vertCount];
|
||||
let verts = new Array(vertCount);
|
||||
|
||||
for (let i = 0; i < vertCount; i++) {
|
||||
let a = 2 * Math.PI * (i / vertCount);
|
||||
@@ -125,4 +125,8 @@ class Polygon extends Shape {
|
||||
|
||||
return verts;
|
||||
}
|
||||
|
||||
public recalculateBounds(collider: Collider) {
|
||||
this.center = collider.localOffset;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
abstract class Shape {
|
||||
public bounds: Rectangle;
|
||||
public position: Vector2;
|
||||
public center: Vector2;
|
||||
|
||||
public abstract recalculateBounds(collider: Collider);
|
||||
public abstract pointCollidesWithShape(point: Vector2): CollisionResult;
|
||||
}
|
||||
@@ -10,6 +10,35 @@ class ShapeCollisions {
|
||||
let polygonOffset = Vector2.subtract(first.position, second.position);
|
||||
let axis: Vector2;
|
||||
|
||||
for (let edgeIndex = 0; edgeIndex < firstEdges.length + secondEdges.length; edgeIndex ++){
|
||||
if (edgeIndex < firstEdges.length){
|
||||
axis = firstEdges[edgeIndex];
|
||||
} else {
|
||||
axis = secondEdges[edgeIndex - firstEdges.length];
|
||||
}
|
||||
|
||||
let minA = 0;
|
||||
let minB = 0;
|
||||
let maxA = 0;
|
||||
let maxB = 0;
|
||||
let intervalDist = 0;
|
||||
this.getInterval(axis, first, minA, maxA);
|
||||
this.getInterval(axis, second, minB, maxB);
|
||||
}
|
||||
}
|
||||
|
||||
public static getInterval(axis: Vector2, polygon: Polygon, min: number, max: number){
|
||||
let dot = Vector2.dot(polygon.points[0], axis);
|
||||
min = max = dot;
|
||||
|
||||
for (let i = 1; i < polygon.points.length; i++){
|
||||
dot = Vector2.dot(polygon.points[i], axis);
|
||||
if (dot < min){
|
||||
min = dot;
|
||||
}else if(dot > max){
|
||||
max = dot;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static circleToPolygon(circle: Circle, polygon: Polygon){
|
||||
|
||||
Reference in New Issue
Block a user