Search in sources :

Example 1 with Matrix

use of com.jme3.scene.plugins.blender.math.Matrix in project jmonkeyengine by jMonkeyEngine.

the class BoundingBox method transform.

/**
     * <code>transform</code> modifies the center of the box to reflect the
     * change made via a rotation, translation and scale.
     * 
     * @param trans 
     *            the transform to apply
     * @param store
     *            box to store result in
     */
public BoundingVolume transform(Transform trans, BoundingVolume store) {
    BoundingBox box;
    if (store == null || store.getType() != Type.AABB) {
        box = new BoundingBox();
    } else {
        box = (BoundingBox) store;
    }
    center.mult(trans.getScale(), box.center);
    trans.getRotation().mult(box.center, box.center);
    box.center.addLocal(trans.getTranslation());
    TempVars vars = TempVars.get();
    Matrix3f transMatrix = vars.tempMat3;
    transMatrix.set(trans.getRotation());
    // Make the rotation matrix all positive to get the maximum x/y/z extent
    transMatrix.absoluteLocal();
    Vector3f scale = trans.getScale();
    vars.vect1.set(xExtent * FastMath.abs(scale.x), yExtent * FastMath.abs(scale.y), zExtent * FastMath.abs(scale.z));
    transMatrix.mult(vars.vect1, vars.vect2);
    // Assign the biggest rotations after scales.
    box.xExtent = FastMath.abs(vars.vect2.getX());
    box.yExtent = FastMath.abs(vars.vect2.getY());
    box.zExtent = FastMath.abs(vars.vect2.getZ());
    vars.release();
    return box;
}
Also used : TempVars(com.jme3.util.TempVars)

Example 2 with Matrix

use of com.jme3.scene.plugins.blender.math.Matrix in project jmonkeyengine by jMonkeyEngine.

the class FbxBindPose method fromElement.

@Override
public void fromElement(FbxElement element) {
    super.fromElement(element);
    for (FbxElement child : element.children) {
        if (!child.id.equals("PoseNode")) {
            continue;
        }
        FbxId node = null;
        float[] matData = null;
        for (FbxElement e : child.children) {
            if (e.id.equals("Node")) {
                node = FbxId.create(e.properties.get(0));
            } else if (e.id.equals("Matrix")) {
                double[] matDataDoubles = (double[]) e.properties.get(0);
                if (matDataDoubles.length != 16) {
                    // corrupt
                    throw new UnsupportedOperationException("Bind pose matrix " + "must have 16 doubles, but it has " + matDataDoubles.length + ". Data is corrupt");
                }
                matData = new float[16];
                for (int i = 0; i < matDataDoubles.length; i++) {
                    matData[i] = (float) matDataDoubles[i];
                }
            }
        }
        if (node != null && matData != null) {
            Matrix4f matrix = new Matrix4f(matData);
            bindPose.put(node, matrix);
        }
    }
}
Also used : FbxElement(com.jme3.scene.plugins.fbx.file.FbxElement) Matrix4f(com.jme3.math.Matrix4f) FbxId(com.jme3.scene.plugins.fbx.file.FbxId)

Example 3 with Matrix

use of com.jme3.scene.plugins.blender.math.Matrix in project jmonkeyengine by jMonkeyEngine.

the class MirrorModifier method getWorldMatrix.

/**
     * Fetches the world matrix transformation of the given node.
     * @param node
     *            the node
     * @return the node's world transformation matrix
     */
private Matrix4f getWorldMatrix(Node node) {
    Matrix4f result = new Matrix4f();
    result.setTranslation(node.getWorldTranslation());
    result.setRotationQuaternion(node.getWorldRotation());
    result.setScale(node.getWorldScale());
    return result;
}
Also used : Matrix4f(com.jme3.math.Matrix4f)

Example 4 with Matrix

use of com.jme3.scene.plugins.blender.math.Matrix in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRendererVR method renderShadowMap.

protected void renderShadowMap(int shadowMapIndex) {
    shadowMapOccluders = getOccludersToRender(shadowMapIndex, shadowMapOccluders);
    Camera shadowCam = getShadowCam(shadowMapIndex);
    //saving light view projection matrix for this split            
    lightViewProjectionsMatrices[shadowMapIndex].set(shadowCam.getViewProjectionMatrix());
    renderManager.setCamera(shadowCam, false);
    renderManager.getRenderer().setFrameBuffer(shadowFB[shadowMapIndex]);
    renderManager.getRenderer().clearBuffers(true, true, true);
    renderManager.setForcedRenderState(forcedRenderState);
    // render shadow casters to shadow map
    viewPort.getQueue().renderShadowQueue(shadowMapOccluders, renderManager, shadowCam, true);
    renderManager.setForcedRenderState(null);
}
Also used : Camera(com.jme3.renderer.Camera)

Example 5 with Matrix

use of com.jme3.scene.plugins.blender.math.Matrix in project jmonkeyengine by jMonkeyEngine.

the class PssmShadowRenderer method postQueue.

@SuppressWarnings("fallthrough")
public void postQueue(RenderQueue rq) {
    for (Spatial scene : viewPort.getScenes()) {
        ShadowUtil.getGeometriesInCamFrustum(scene, viewPort.getCamera(), ShadowMode.Receive, lightReceivers);
    }
    Camera viewCam = viewPort.getCamera();
    float zFar = zFarOverride;
    if (zFar == 0) {
        zFar = viewCam.getFrustumFar();
    }
    //We prevent computing the frustum points and splits with zeroed or negative near clip value
    float frustumNear = Math.max(viewCam.getFrustumNear(), 0.001f);
    ShadowUtil.updateFrustumPoints(viewCam, frustumNear, zFar, 1.0f, points);
    //shadowCam.setDirection(direction);
    shadowCam.getRotation().lookAt(direction, shadowCam.getUp());
    shadowCam.update();
    shadowCam.updateViewProjection();
    PssmShadowUtil.updateFrustumSplits(splitsArray, frustumNear, zFar, lambda);
    switch(splitsArray.length) {
        case 5:
            splits.a = splitsArray[4];
        case 4:
            splits.b = splitsArray[3];
        case 3:
            splits.g = splitsArray[2];
        case 2:
        case 1:
            splits.r = splitsArray[1];
            break;
    }
    Renderer r = renderManager.getRenderer();
    renderManager.setForcedMaterial(preshadowMat);
    renderManager.setForcedTechnique("PreShadow");
    for (int i = 0; i < nbSplits; i++) {
        // update frustum points based on current camera and split
        ShadowUtil.updateFrustumPoints(viewCam, splitsArray[i], splitsArray[i + 1], 1.0f, points);
        //Updating shadow cam with curent split frustra
        ShadowUtil.updateShadowCamera(viewPort, lightReceivers, shadowCam, points, splitOccluders, shadowMapSize);
        //saving light view projection matrix for this split            
        lightViewProjectionsMatrices[i].set(shadowCam.getViewProjectionMatrix());
        renderManager.setCamera(shadowCam, false);
        if (debugfrustums) {
            //                    frustrumFromBound(b.casterBB,ColorRGBA.Blue );
            //                    frustrumFromBound(b.receiverBB,ColorRGBA.Green );
            //                    frustrumFromBound(b.splitBB,ColorRGBA.Yellow );
            ((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points, i));
            ShadowUtil.updateFrustumPoints2(shadowCam, points);
            ((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points, i));
        }
        r.setFrameBuffer(shadowFB[i]);
        r.clearBuffers(true, true, true);
        // render shadow casters to shadow map
        viewPort.getQueue().renderShadowQueue(splitOccluders, renderManager, shadowCam, true);
    }
    debugfrustums = false;
    //restore setting for future rendering
    r.setFrameBuffer(viewPort.getOutputFrameBuffer());
    renderManager.setForcedMaterial(null);
    renderManager.setForcedTechnique(null);
    renderManager.setCamera(viewCam, false);
}
Also used : Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) Renderer(com.jme3.renderer.Renderer) Camera(com.jme3.renderer.Camera)

Aggregations

TempVars (com.jme3.util.TempVars)12 Matrix4f (com.jme3.math.Matrix4f)10 Vector3f (com.jme3.math.Vector3f)5 Bone (com.jme3.animation.Bone)3 Camera (com.jme3.renderer.Camera)3 Spatial (com.jme3.scene.Spatial)3 BoundingBox (com.jme3.bounding.BoundingBox)2 com.jme3.opencl (com.jme3.opencl)2 BoneContext (com.jme3.scene.plugins.blender.animations.BoneContext)2 Uniform (com.jme3.shader.Uniform)2 Bitmap (android.graphics.Bitmap)1 BitmapFactory (android.graphics.BitmapFactory)1 Matrix (android.graphics.Matrix)1 Skeleton (com.jme3.animation.Skeleton)1 TextureKey (com.jme3.asset.TextureKey)1 BoundingSphere (com.jme3.bounding.BoundingSphere)1 BoundingVolume (com.jme3.bounding.BoundingVolume)1 JoyAxisEvent (com.jme3.input.event.JoyAxisEvent)1 DirectionalLight (com.jme3.light.DirectionalLight)1 Light (com.jme3.light.Light)1