* Remove use of instance variable in BIHTree, instead use TempVars

experimental
shadowislord 11 years ago
parent e637cd0b7a
commit 67f402df75
  1. 52
      jme3-core/src/main/java/com/jme3/collision/bih/BIHTree.java
  2. 2
      jme3-core/src/main/java/com/jme3/util/TempVars.java

@ -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();
if (tMax <= 0) {
tMax = Float.POSITIVE_INFINITY;
} else if (tMin == tMax) {
tMin = 0;
}
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 (tMin <= 0) {
tMin = 0;
}
if (r.getLimit() < Float.POSITIVE_INFINITY) {
tMax = Math.min(tMax, r.getLimit());
if (tMin > tMax){
return 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 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…
Cancel
Save