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
37653ba974
commit
812af3925e
2 changed files with 27 additions and 3 deletions
|
|
@ -9,6 +9,11 @@ import h3d.Vector;
|
||||||
import src.Settings;
|
import src.Settings;
|
||||||
|
|
||||||
class Util {
|
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) {
|
public static function adjustedMod(a:Float, n:Float) {
|
||||||
var r1 = a % n;
|
var r1 = a % n;
|
||||||
var r2 = (r1 + n) % n;
|
var r2 = (r1 + n) % n;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import octree.IOctreeObject;
|
||||||
import h3d.Matrix;
|
import h3d.Matrix;
|
||||||
import h3d.col.Bounds;
|
import h3d.col.Bounds;
|
||||||
import src.PathedInterior;
|
import src.PathedInterior;
|
||||||
|
import src.Util;
|
||||||
|
|
||||||
class CollisionEntity implements IOctreeObject {
|
class CollisionEntity implements IOctreeObject {
|
||||||
public var boundingBox:Bounds;
|
public var boundingBox:Bounds;
|
||||||
|
|
@ -63,10 +64,28 @@ class CollisionEntity implements IOctreeObject {
|
||||||
public function setTransform(transform:Matrix) {
|
public function setTransform(transform:Matrix) {
|
||||||
if (this.transform.equal(transform))
|
if (this.transform.equal(transform))
|
||||||
return;
|
return;
|
||||||
|
// 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.transform.load(transform);
|
||||||
this.invTransform = transform.getInverse();
|
this.invTransform = transform.getInverse();
|
||||||
generateBoundingBox();
|
generateBoundingBox();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function generateBoundingBox() {
|
public function generateBoundingBox() {
|
||||||
var boundingBox = new Bounds();
|
var boundingBox = new Bounds();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue