use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class ShadowUtil method computeUnionBound.
/**
* Compute bounds of a geomList
* @param list
* @param mat
* @return
*/
public static BoundingBox computeUnionBound(GeometryList list, Matrix4f mat) {
BoundingBox bbox = new BoundingBox();
TempVars tempv = TempVars.get();
for (int i = 0; i < list.size(); i++) {
BoundingVolume vol = list.get(i).getWorldBound();
BoundingVolume store = vol.transform(mat, tempv.bbox);
//Nehon : prevent NaN and infinity values to screw the final bounding box
if (!Float.isNaN(store.getCenter().x) && !Float.isInfinite(store.getCenter().x)) {
bbox.mergeLocal(store);
}
}
tempv.release();
return bbox;
}
use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class ShadowUtil method updateShadowCamera.
/**
* Updates the shadow camera to properly contain the given points (which
* contain the eye camera frustum corners)
*
* @param shadowCam
* @param points
*/
public static void updateShadowCamera(Camera shadowCam, Vector3f[] points) {
boolean ortho = shadowCam.isParallelProjection();
shadowCam.setProjectionMatrix(null);
if (ortho) {
shadowCam.setFrustum(-1, 1, -1, 1, 1, -1);
} else {
shadowCam.setFrustumPerspective(45, 1, 1, 150);
}
Matrix4f viewProjMatrix = shadowCam.getViewProjectionMatrix();
Matrix4f projMatrix = shadowCam.getProjectionMatrix();
BoundingBox splitBB = computeBoundForPoints(points, viewProjMatrix);
TempVars vars = TempVars.get();
Vector3f splitMin = splitBB.getMin(vars.vect1);
Vector3f splitMax = splitBB.getMax(vars.vect2);
// splitMin.z = 0;
// Create the crop matrix.
float scaleX, scaleY, scaleZ;
float offsetX, offsetY, offsetZ;
scaleX = 2.0f / (splitMax.x - splitMin.x);
scaleY = 2.0f / (splitMax.y - splitMin.y);
offsetX = -0.5f * (splitMax.x + splitMin.x) * scaleX;
offsetY = -0.5f * (splitMax.y + splitMin.y) * scaleY;
scaleZ = 1.0f / (splitMax.z - splitMin.z);
offsetZ = -splitMin.z * scaleZ;
Matrix4f cropMatrix = vars.tempMat4;
cropMatrix.set(scaleX, 0f, 0f, offsetX, 0f, scaleY, 0f, offsetY, 0f, 0f, scaleZ, offsetZ, 0f, 0f, 0f, 1f);
Matrix4f result = new Matrix4f();
result.set(cropMatrix);
result.multLocal(projMatrix);
vars.release();
shadowCam.setProjectionMatrix(result);
}
use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class ShadowUtil method computeUnionBound.
/**
* Compute bounds of a geomList
* @param list
* @param transform
* @return
*/
public static BoundingBox computeUnionBound(GeometryList list, Transform transform) {
BoundingBox bbox = new BoundingBox();
TempVars tempv = TempVars.get();
for (int i = 0; i < list.size(); i++) {
BoundingVolume vol = list.get(i).getWorldBound();
BoundingVolume newVol = vol.transform(transform, tempv.bbox);
//Nehon : prevent NaN and infinity values to screw the final bounding box
if (!Float.isNaN(newVol.getCenter().x) && !Float.isInfinite(newVol.getCenter().x)) {
bbox.mergeLocal(newVol);
}
}
tempv.release();
return bbox;
}
use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class WireBox method makeGeometry.
/**
* Create a geometry suitable for visualizing the specified bounding box.
*
* @param bbox the bounding box (not null)
* @return a new Geometry instance in world space
*/
public static Geometry makeGeometry(BoundingBox bbox) {
float xExtent = bbox.getXExtent();
float yExtent = bbox.getYExtent();
float zExtent = bbox.getZExtent();
WireBox mesh = new WireBox(xExtent, yExtent, zExtent);
Geometry result = new Geometry("bounding box", mesh);
Vector3f center = bbox.getCenter();
result.setLocalTranslation(center);
return result;
}
use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class BoundingCollisionTest method testBoxBoxCollision.
@Test
public void testBoxBoxCollision() {
BoundingBox box1 = new BoundingBox(Vector3f.ZERO, 1, 1, 1);
BoundingBox box2 = new BoundingBox(Vector3f.ZERO, 1, 1, 1);
checkCollision(box1, box2, 1);
// Put it at the very edge - should still intersect.
box2.setCenter(new Vector3f(2f, 0f, 0f));
checkCollision(box1, box2, 1);
// Put it a wee bit farther - no intersection expected
box2.setCenter(new Vector3f(2f + FastMath.ZERO_TOLERANCE, 0, 0));
checkCollision(box1, box2, 0);
// Check the corners.
box2.setCenter(new Vector3f(2f, 2f, 2f));
checkCollision(box1, box2, 1);
box2.setCenter(new Vector3f(2f, 2f, 2f + FastMath.ZERO_TOLERANCE));
checkCollision(box1, box2, 0);
}
Aggregations