Search in sources :

Example 46 with BoundingBox

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;
}
Also used : BoundingBox(com.jme3.bounding.BoundingBox) BoundingVolume(com.jme3.bounding.BoundingVolume) TempVars(com.jme3.util.TempVars)

Example 47 with BoundingBox

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);
}
Also used : Matrix4f(com.jme3.math.Matrix4f) BoundingBox(com.jme3.bounding.BoundingBox) Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars)

Example 48 with BoundingBox

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;
}
Also used : BoundingBox(com.jme3.bounding.BoundingBox) BoundingVolume(com.jme3.bounding.BoundingVolume) TempVars(com.jme3.util.TempVars)

Example 49 with BoundingBox

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;
}
Also used : Geometry(com.jme3.scene.Geometry) Vector3f(com.jme3.math.Vector3f)

Example 50 with BoundingBox

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);
}
Also used : BoundingBox(com.jme3.bounding.BoundingBox) Vector3f(com.jme3.math.Vector3f) Test(org.junit.Test)

Aggregations

BoundingBox (com.jme3.bounding.BoundingBox)42 Vector3f (com.jme3.math.Vector3f)35 Geometry (com.jme3.scene.Geometry)14 TempVars (com.jme3.util.TempVars)14 BoundingVolume (com.jme3.bounding.BoundingVolume)10 BoundingSphere (com.jme3.bounding.BoundingSphere)8 Material (com.jme3.material.Material)7 Vector2f (com.jme3.math.Vector2f)4 Texture (com.jme3.texture.Texture)4 Test (org.junit.Test)4 DirectionalLight (com.jme3.light.DirectionalLight)3 Matrix4f (com.jme3.math.Matrix4f)3 Ray (com.jme3.math.Ray)3 Node (com.jme3.scene.Node)3 Spatial (com.jme3.scene.Spatial)3 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)3 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)3 DistanceLodCalculator (com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator)3 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)3 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)3