mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-27 13:11:42 +00:00
fix this broadphase crash
This commit is contained in:
parent
8f08c3b817
commit
724ebbda99
2 changed files with 12 additions and 4 deletions
|
|
@ -30,6 +30,14 @@ class Util {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static inline function imin(a:Int, b:Int) {
|
||||||
|
return a < b ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static inline function imax(a:Int, b:Int) {
|
||||||
|
return a > b ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
public static inline function lerp(a:Float, b:Float, t:Float) {
|
public static inline function lerp(a:Float, b:Float, t:Float) {
|
||||||
return a + (b - a) * t;
|
return a + (b - a) * t;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -111,10 +111,10 @@ class GridBroadphase {
|
||||||
var queryMinY = Math.max(object.boundingBox.yMin, bounds.yMin);
|
var queryMinY = Math.max(object.boundingBox.yMin, bounds.yMin);
|
||||||
var queryMaxX = Math.min(object.boundingBox.xMax, bounds.xMax);
|
var queryMaxX = Math.min(object.boundingBox.xMax, bounds.xMax);
|
||||||
var queryMaxY = Math.min(object.boundingBox.yMax, bounds.yMax);
|
var queryMaxY = Math.min(object.boundingBox.yMax, bounds.yMax);
|
||||||
var xStart = Math.floor((queryMinX - bounds.xMin) / this.cellSize.x);
|
var xStart = Util.imax(0, Math.floor((queryMinX - bounds.xMin) / this.cellSize.x));
|
||||||
var yStart = Math.floor((queryMinY - bounds.yMin) / this.cellSize.y);
|
var yStart = Util.imax(0, Math.floor((queryMinY - bounds.yMin) / this.cellSize.y));
|
||||||
var xEnd = Math.floor((queryMaxX - bounds.xMin) / this.cellSize.x);
|
var xEnd = Util.imin(CELL_SIZE - 1, Math.floor((queryMaxX - bounds.xMin) / this.cellSize.x));
|
||||||
var yEnd = Math.floor((queryMaxY - bounds.yMin) / this.cellSize.y);
|
var yEnd = Util.imin(CELL_SIZE - 1, Math.floor((queryMaxY - bounds.yMin) / this.cellSize.y));
|
||||||
var proxy = objectToProxy.get(object);
|
var proxy = objectToProxy.get(object);
|
||||||
if (proxy == null) {
|
if (proxy == null) {
|
||||||
insert(object);
|
insert(object);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue