use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class BIHNode method intersectWhere.
public final int intersectWhere(Collidable col, BoundingBox box, Matrix4f worldMatrix, BIHTree tree, CollisionResults results) {
TempVars vars = TempVars.get();
ArrayList<BIHStackData> stack = vars.bihStack;
stack.clear();
float[] minExts = { box.getCenter().x - box.getXExtent(), box.getCenter().y - box.getYExtent(), box.getCenter().z - box.getZExtent() };
float[] maxExts = { box.getCenter().x + box.getXExtent(), box.getCenter().y + box.getYExtent(), box.getCenter().z + box.getZExtent() };
stack.add(new BIHStackData(this, 0, 0));
Triangle t = new Triangle();
int cols = 0;
stackloop: while (stack.size() > 0) {
BIHNode node = stack.remove(stack.size() - 1).node;
while (node.axis != 3) {
int a = node.axis;
float maxExt = maxExts[a];
float minExt = minExts[a];
if (node.leftPlane < node.rightPlane) {
// if the box is in that gap, we stop there
if (minExt > node.leftPlane && maxExt < node.rightPlane) {
continue stackloop;
}
}
if (maxExt < node.rightPlane) {
node = node.left;
} else if (minExt > node.leftPlane) {
node = node.right;
} else {
stack.add(new BIHStackData(node.right, 0, 0));
node = node.left;
}
// if (maxExt < node.leftPlane
// && maxExt < node.rightPlane){
// node = node.left;
// }else if (minExt > node.leftPlane
// && minExt > node.rightPlane){
// node = node.right;
// }else{
// }
}
for (int i = node.leftIndex; i <= node.rightIndex; i++) {
tree.getTriangle(i, t.get1(), t.get2(), t.get3());
if (worldMatrix != null) {
worldMatrix.mult(t.get1(), t.get1());
worldMatrix.mult(t.get2(), t.get2());
worldMatrix.mult(t.get3(), t.get3());
}
int added = col.collideWith(t, results);
if (added > 0) {
int index = tree.getTriangleIndex(i);
int start = results.size() - added;
for (int j = start; j < results.size(); j++) {
CollisionResult cr = results.getCollisionDirect(j);
cr.setTriangleIndex(index);
}
cols += added;
}
}
}
vars.release();
return cols;
}
use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class BIHTree method construct.
public void construct() {
BoundingBox sceneBbox = createBox(0, numTris - 1);
root = createNode(0, numTris - 1, sceneBbox, 0);
}
use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class BIHTree method collideWithBoundingVolume.
private int collideWithBoundingVolume(BoundingVolume bv, Matrix4f worldMatrix, CollisionResults results) {
BoundingBox bbox;
if (bv instanceof BoundingSphere) {
BoundingSphere sphere = (BoundingSphere) bv;
bbox = new BoundingBox(bv.getCenter().clone(), sphere.getRadius(), sphere.getRadius(), sphere.getRadius());
} else if (bv instanceof BoundingBox) {
bbox = new BoundingBox((BoundingBox) bv);
} else {
throw new UnsupportedCollisionException("BoundingVolume:" + bv);
}
bbox.transform(worldMatrix.invert(), bbox);
return root.intersectWhere(bv, bbox, worldMatrix, this, results);
}
use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class PssmShadowUtil method computeZFar.
/**
* Compute the Zfar in the model vieuw to adjust the Zfar distance for the splits calculation
*/
public static float computeZFar(GeometryList occ, GeometryList recv, Camera cam) {
Matrix4f mat = cam.getViewMatrix();
BoundingBox bbOcc = ShadowUtil.computeUnionBound(occ, mat);
BoundingBox bbRecv = ShadowUtil.computeUnionBound(recv, mat);
return min(max(bbOcc.getZExtent() - bbOcc.getCenter().z, bbRecv.getZExtent() - bbRecv.getCenter().z), cam.getFrustumFar());
}
use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class ShadowUtil method computeBoundForPoints.
/**
* Compute bounds from an array of points
* @param pts
* @param mat
* @return
*/
public static BoundingBox computeBoundForPoints(Vector3f[] pts, Matrix4f mat) {
Vector3f min = new Vector3f(Vector3f.POSITIVE_INFINITY);
Vector3f max = new Vector3f(Vector3f.NEGATIVE_INFINITY);
TempVars vars = TempVars.get();
Vector3f temp = vars.vect1;
for (int i = 0; i < pts.length; i++) {
float w = mat.multProj(pts[i], temp);
temp.x /= w;
temp.y /= w;
// Why was this commented out?
temp.z /= w;
min.minLocal(temp);
max.maxLocal(temp);
}
vars.release();
Vector3f center = min.add(max).multLocal(0.5f);
Vector3f extent = max.subtract(min).multLocal(0.5f);
//Nehon 08/18/2010 : Added an offset to the extend to avoid banding artifacts when the frustum are aligned
return new BoundingBox(center, extent.x + 2.0f, extent.y + 2.0f, extent.z + 2.5f);
}
Aggregations