mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
speedup bounds calcs
This commit is contained in:
parent
cf3b6f5ac2
commit
f89e557662
2 changed files with 27 additions and 3 deletions
|
|
@ -9,6 +9,11 @@ import h3d.Vector;
|
|||
import src.Settings;
|
||||
|
||||
class Util {
|
||||
public static function mat3x3equal(a:Matrix, b:Matrix) {
|
||||
return a._11 == b._11 && a._12 == b._12 && a._13 == b._13 && a._21 == b._21 && a._22 == b._22 && a._23 == b._23 && a._31 == b._31 && a._32 == b._32
|
||||
&& a._33 == b._33;
|
||||
}
|
||||
|
||||
public static function adjustedMod(a:Float, n:Float) {
|
||||
var r1 = a % n;
|
||||
var r2 = (r1 + n) % n;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import octree.IOctreeObject;
|
|||
import h3d.Matrix;
|
||||
import h3d.col.Bounds;
|
||||
import src.PathedInterior;
|
||||
import src.Util;
|
||||
|
||||
class CollisionEntity implements IOctreeObject {
|
||||
public var boundingBox:Bounds;
|
||||
|
|
@ -63,9 +64,27 @@ class CollisionEntity implements IOctreeObject {
|
|||
public function setTransform(transform:Matrix) {
|
||||
if (this.transform.equal(transform))
|
||||
return;
|
||||
this.transform.load(transform);
|
||||
this.invTransform = transform.getInverse();
|
||||
generateBoundingBox();
|
||||
// Speedup
|
||||
if (Util.mat3x3equal(this.transform, transform)) {
|
||||
var oldPos = this.transform.getPosition();
|
||||
var newPos = transform.getPosition();
|
||||
this.transform.setPosition(newPos);
|
||||
this.invTransform.setPosition(newPos.multiply(-1));
|
||||
if (this.boundingBox == null)
|
||||
generateBoundingBox();
|
||||
else {
|
||||
this.boundingBox.xMin += newPos.x - oldPos.x;
|
||||
this.boundingBox.xMax += newPos.x - oldPos.x;
|
||||
this.boundingBox.yMin += newPos.y - oldPos.y;
|
||||
this.boundingBox.yMax += newPos.y - oldPos.y;
|
||||
this.boundingBox.zMin += newPos.z - oldPos.z;
|
||||
this.boundingBox.zMax += newPos.z - oldPos.z;
|
||||
}
|
||||
} else {
|
||||
this.transform.load(transform);
|
||||
this.invTransform = transform.getInverse();
|
||||
generateBoundingBox();
|
||||
}
|
||||
}
|
||||
|
||||
public function generateBoundingBox() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue