Avoid allocation of a temporary float[] array
and avoid allocation of a needless Vector3f array.
This commit is contained in:
parent
28adc784a9
commit
34b4eebb81
@ -720,42 +720,45 @@ public class BoundingBox extends BoundingVolume {
|
|||||||
*/
|
*/
|
||||||
private int collideWithRay(Ray ray, CollisionResults results) {
|
private int collideWithRay(Ray ray, CollisionResults results) {
|
||||||
TempVars vars = TempVars.get();
|
TempVars vars = TempVars.get();
|
||||||
|
try {
|
||||||
|
Vector3f diff = vars.vect1.set(ray.origin).subtractLocal(center);
|
||||||
|
Vector3f direction = vars.vect2.set(ray.direction);
|
||||||
|
|
||||||
Vector3f diff = vars.vect1.set(ray.origin).subtractLocal(center);
|
//float[] t = {0f, Float.POSITIVE_INFINITY};
|
||||||
Vector3f direction = vars.vect2.set(ray.direction);
|
float[] t = vars.fWdU; // use one of the tempvars arrays
|
||||||
|
t[0] = 0;
|
||||||
|
t[1] = Float.POSITIVE_INFINITY;
|
||||||
|
|
||||||
float[] t = {0f, Float.POSITIVE_INFINITY};
|
float saveT0 = t[0], saveT1 = t[1];
|
||||||
|
boolean notEntirelyClipped = clip(+direction.x, -diff.x - xExtent, t)
|
||||||
|
&& clip(-direction.x, +diff.x - xExtent, t)
|
||||||
|
&& clip(+direction.y, -diff.y - yExtent, t)
|
||||||
|
&& clip(-direction.y, +diff.y - yExtent, t)
|
||||||
|
&& clip(+direction.z, -diff.z - zExtent, t)
|
||||||
|
&& clip(-direction.z, +diff.z - zExtent, t);
|
||||||
|
|
||||||
float saveT0 = t[0], saveT1 = t[1];
|
if (notEntirelyClipped && (t[0] != saveT0 || t[1] != saveT1)) {
|
||||||
boolean notEntirelyClipped = clip(+direction.x, -diff.x - xExtent, t)
|
if (t[1] > t[0]) {
|
||||||
&& clip(-direction.x, +diff.x - xExtent, t)
|
float[] distances = t;
|
||||||
&& clip(+direction.y, -diff.y - yExtent, t)
|
Vector3f point0 = new Vector3f(ray.direction).multLocal(distances[0]).addLocal(ray.origin);
|
||||||
&& clip(-direction.y, +diff.y - yExtent, t)
|
Vector3f point1 = new Vector3f(ray.direction).multLocal(distances[1]).addLocal(ray.origin);
|
||||||
&& clip(+direction.z, -diff.z - zExtent, t)
|
|
||||||
&& clip(-direction.z, +diff.z - zExtent, t);
|
|
||||||
vars.release();
|
|
||||||
|
|
||||||
if (notEntirelyClipped && (t[0] != saveT0 || t[1] != saveT1)) {
|
CollisionResult result = new CollisionResult(point0, distances[0]);
|
||||||
if (t[1] > t[0]) {
|
results.addCollision(result);
|
||||||
float[] distances = t;
|
result = new CollisionResult(point1, distances[1]);
|
||||||
Vector3f[] points = new Vector3f[]{
|
results.addCollision(result);
|
||||||
new Vector3f(ray.direction).multLocal(distances[0]).addLocal(ray.origin),
|
return 2;
|
||||||
new Vector3f(ray.direction).multLocal(distances[1]).addLocal(ray.origin)
|
}
|
||||||
};
|
|
||||||
|
|
||||||
CollisionResult result = new CollisionResult(points[0], distances[0]);
|
Vector3f point = new Vector3f(ray.direction).multLocal(t[0]).addLocal(ray.origin);
|
||||||
|
CollisionResult result = new CollisionResult(point, t[0]);
|
||||||
results.addCollision(result);
|
results.addCollision(result);
|
||||||
result = new CollisionResult(points[1], distances[1]);
|
return 1;
|
||||||
results.addCollision(result);
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
Vector3f point = new Vector3f(ray.direction).multLocal(t[0]).addLocal(ray.origin);
|
} finally {
|
||||||
CollisionResult result = new CollisionResult(point, t[0]);
|
vars.release();
|
||||||
results.addCollision(result);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int collideWith(Collidable other, CollisionResults results) {
|
public int collideWith(Collidable other, CollisionResults results) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user