* Remove use of instance variable in BIHTree, instead use TempVars
This commit is contained in:
parent
e637cd0b7a
commit
67f402df75
@ -68,7 +68,7 @@ public class BIHTree implements CollisionData {
|
||||
private float[] pointData;
|
||||
private int[] triIndices;
|
||||
|
||||
private transient CollisionResults boundResults = new CollisionResults();
|
||||
// private transient CollisionResults boundResults = new CollisionResults();
|
||||
private transient float[] bihSwapTmp;
|
||||
|
||||
private static final TriangleAxisComparator[] comparators = new TriangleAxisComparator[]
|
||||
@ -398,33 +398,39 @@ public class BIHTree implements CollisionData {
|
||||
BoundingVolume worldBound,
|
||||
CollisionResults results) {
|
||||
|
||||
boundResults.clear();
|
||||
worldBound.collideWith(r, boundResults);
|
||||
if (boundResults.size() > 0) {
|
||||
float tMin = boundResults.getClosestCollision().getDistance();
|
||||
float tMax = boundResults.getFarthestCollision().getDistance();
|
||||
TempVars vars = TempVars.get();
|
||||
try {
|
||||
CollisionResults boundResults = vars.collisionResults;
|
||||
boundResults.clear();
|
||||
worldBound.collideWith(r, boundResults);
|
||||
if (boundResults.size() > 0) {
|
||||
float tMin = boundResults.getClosestCollision().getDistance();
|
||||
float tMax = boundResults.getFarthestCollision().getDistance();
|
||||
|
||||
if (tMax <= 0) {
|
||||
tMax = Float.POSITIVE_INFINITY;
|
||||
} else if (tMin == tMax) {
|
||||
tMin = 0;
|
||||
}
|
||||
|
||||
if (tMin <= 0) {
|
||||
tMin = 0;
|
||||
}
|
||||
|
||||
if (r.getLimit() < Float.POSITIVE_INFINITY) {
|
||||
tMax = Math.min(tMax, r.getLimit());
|
||||
if (tMin > tMax){
|
||||
return 0;
|
||||
if (tMax <= 0) {
|
||||
tMax = Float.POSITIVE_INFINITY;
|
||||
} else if (tMin == tMax) {
|
||||
tMin = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// return root.intersectBrute(r, worldMatrix, this, tMin, tMax, results);
|
||||
return root.intersectWhere(r, worldMatrix, this, tMin, tMax, results);
|
||||
if (tMin <= 0) {
|
||||
tMin = 0;
|
||||
}
|
||||
|
||||
if (r.getLimit() < Float.POSITIVE_INFINITY) {
|
||||
tMax = Math.min(tMax, r.getLimit());
|
||||
if (tMin > tMax){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// return root.intersectBrute(r, worldMatrix, this, tMin, tMax, results);
|
||||
return root.intersectWhere(r, worldMatrix, this, tMin, tMax, results);
|
||||
}
|
||||
return 0;
|
||||
} finally {
|
||||
vars.release();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int collideWithBoundingVolume(BoundingVolume bv,
|
||||
|
@ -33,6 +33,7 @@ package com.jme3.util;
|
||||
|
||||
import com.jme3.bounding.BoundingBox;
|
||||
import com.jme3.bounding.BoundingVolume;
|
||||
import com.jme3.collision.CollisionResults;
|
||||
import com.jme3.collision.bih.BIHNode.BIHStackData;
|
||||
import com.jme3.math.*;
|
||||
import com.jme3.scene.Spatial;
|
||||
@ -222,6 +223,7 @@ public class TempVars {
|
||||
/**
|
||||
* BIHTree
|
||||
*/
|
||||
public final CollisionResults collisionResults = new CollisionResults();
|
||||
public final float[] bihSwapTmp = new float[9];
|
||||
public final ArrayList<BIHStackData> bihStack = new ArrayList<BIHStackData>();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user