移除物理引擎 移动到新库

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

@@ -1,4 +1,6 @@
class SpatialHash {
public gridBounds: Rectangle = new Rectangle();
private _raycastParser: RaycastResultParser;
private _cellSize: number;
private _inverseCellSize: number;
@@ -12,6 +14,29 @@ class SpatialHash {
this._raycastParser = new RaycastResultParser();
}
public remove(collider: Collider){
let bounds = collider.registeredPhysicsBounds;
let p1 = this.cellCoords(bounds.x, bounds.y);
let p2 = this.cellCoords(bounds.right, bounds.bottom);
for (let x = p1.x; x <= p2.x; x ++){
for (let y = p1.y; y <= p2.y; y ++){
let cell = this.cellAtPosition(x, y);
if (!cell)
console.error(`removing Collider [${collider}] from a cell that it is not present in`);
else
cell.remove(collider);
}
}
}
public register(collider: Collider){
let bounds = collider.bounds;
collider.registeredPhysicsBounds = bounds;
let p1 = this.cellCoords(bounds.x, bounds.y);
let p2 = this.cellCoords(bounds.right, bounds.bottom);
}
public overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask){
let bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2);