Search in sources :

Example 46 with Matrix4f

use of com.jme3.math.Matrix4f 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);
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) BoundingBox(com.jme3.bounding.BoundingBox) UnsupportedCollisionException(com.jme3.collision.UnsupportedCollisionException)

Example 47 with Matrix4f

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

Example 48 with Matrix4f

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

Example 49 with Matrix4f

use of com.jme3.math.Matrix4f 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 50 with Matrix4f

use of com.jme3.math.Matrix4f 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)

Aggregations

Matrix4f (com.jme3.math.Matrix4f)36 TempVars (com.jme3.util.TempVars)24 Vector3f (com.jme3.math.Vector3f)15 FloatBuffer (java.nio.FloatBuffer)7 BoundingBox (com.jme3.bounding.BoundingBox)6 Transform (com.jme3.math.Transform)6 Bone (com.jme3.animation.Bone)4 CollisionResult (com.jme3.collision.CollisionResult)3 Spatial (com.jme3.scene.Spatial)3 BoundingVolume (com.jme3.bounding.BoundingVolume)2 Material (com.jme3.material.Material)2 Quaternion (com.jme3.math.Quaternion)2 Geometry (com.jme3.scene.Geometry)2 BoneContext (com.jme3.scene.plugins.blender.animations.BoneContext)2 Structure (com.jme3.scene.plugins.blender.file.Structure)2 FbxId (com.jme3.scene.plugins.fbx.file.FbxId)2 FrameBuffer (com.jme3.texture.FrameBuffer)2 Texture2D (com.jme3.texture.Texture2D)2 Picture (com.jme3.ui.Picture)2 ByteBuffer (java.nio.ByteBuffer)2