Search in sources :

Example 11 with Matrix4f

use of com.jme3.math.Matrix4f in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowFilter method preFrame.

@Override
protected void preFrame(float tpf) {
    shadowRenderer.preFrame(tpf);
    material.setMatrix4("ViewProjectionMatrixInverse", viewPort.getCamera().getViewProjectionMatrix().invert());
    Matrix4f m = viewPort.getCamera().getViewProjectionMatrix();
    material.setVector4("ViewProjectionMatrixRow2", tmpv.set(m.m20, m.m21, m.m22, m.m23));
}
Also used : Matrix4f(com.jme3.math.Matrix4f)

Example 12 with Matrix4f

use of com.jme3.math.Matrix4f in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRenderer method init.

private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize) {
    this.postshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PostShadow.j3md");
    shadowFB = new FrameBuffer[nbShadowMaps];
    shadowMaps = new Texture2D[nbShadowMaps];
    dispPic = new Picture[nbShadowMaps];
    lightViewProjectionsMatrices = new Matrix4f[nbShadowMaps];
    shadowMapStringCache = new String[nbShadowMaps];
    lightViewStringCache = new String[nbShadowMaps];
    //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
    dummyTex = new Texture2D(shadowMapSize, shadowMapSize, Format.RGBA8);
    preshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PreShadow.j3md");
    postshadowMat.setFloat("ShadowMapSize", shadowMapSize);
    for (int i = 0; i < nbShadowMaps; i++) {
        lightViewProjectionsMatrices[i] = new Matrix4f();
        shadowFB[i] = new FrameBuffer(shadowMapSize, shadowMapSize, 1);
        shadowMaps[i] = new Texture2D(shadowMapSize, shadowMapSize, Format.Depth);
        shadowFB[i].setDepthTexture(shadowMaps[i]);
        //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
        shadowFB[i].setColorTexture(dummyTex);
        shadowMapStringCache[i] = "ShadowMap" + i;
        lightViewStringCache[i] = "LightViewProjectionMatrix" + i;
        postshadowMat.setTexture(shadowMapStringCache[i], shadowMaps[i]);
        //quads for debuging purpose
        dispPic[i] = new Picture("Picture" + i);
        dispPic[i].setTexture(assetManager, shadowMaps[i], false);
    }
    setShadowCompareMode(shadowCompareMode);
    setEdgeFilteringMode(edgeFilteringMode);
    setShadowIntensity(shadowIntensity);
    initForcedRenderState();
}
Also used : Texture2D(com.jme3.texture.Texture2D) Matrix4f(com.jme3.math.Matrix4f) Picture(com.jme3.ui.Picture) Material(com.jme3.material.Material) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 13 with Matrix4f

use of com.jme3.math.Matrix4f in project jmonkeyengine by jMonkeyEngine.

the class InstancedGeometry method updateInstances.

public void updateInstances() {
    FloatBuffer fb = (FloatBuffer) transformInstanceData.getData();
    fb.limit(fb.capacity());
    fb.position(0);
    TempVars vars = TempVars.get();
    {
        float[] temp = vars.matrixWrite;
        for (int i = 0; i < firstUnusedIndex; i++) {
            Geometry geom = geometries[i];
            if (geom == null) {
                geom = geometries[firstUnusedIndex - 1];
                if (geom == null) {
                    throw new AssertionError();
                }
                swap(i, firstUnusedIndex - 1);
                while (geometries[firstUnusedIndex - 1] == null) {
                    firstUnusedIndex--;
                }
            }
            Matrix4f worldMatrix = geom.getWorldMatrix();
            updateInstance(worldMatrix, temp, 0, vars.tempMat3, vars.quat1);
            fb.put(temp);
        }
    }
    vars.release();
    fb.flip();
    if (fb.limit() / INSTANCE_SIZE != firstUnusedIndex) {
        throw new AssertionError();
    }
    transformInstanceData.updateData(fb);
}
Also used : Geometry(com.jme3.scene.Geometry) Matrix4f(com.jme3.math.Matrix4f) FloatBuffer(java.nio.FloatBuffer) TempVars(com.jme3.util.TempVars)

Example 14 with Matrix4f

use of com.jme3.math.Matrix4f in project jmonkeyengine by jMonkeyEngine.

the class OSVR method getHMDMatrixProjectionLeftEye.

@Override
public Matrix4f getHMDMatrixProjectionLeftEye(Camera cam) {
    if (eyeLeftInfo == null)
        return cam.getProjectionMatrix();
    if (eyeMatrix[EYE_LEFT] == null) {
        FloatBuffer tfb = FloatBuffer.allocate(16);
        com.jme3.system.osvr.osvrdisplay.OsvrDisplayLibrary.osvrClientGetViewerEyeSurfaceProjectionMatrixf(displayConfig, 0, (byte) EYE_LEFT, 0, cam.getFrustumNear(), cam.getFrustumFar(), (short) 0, tfb);
        eyeMatrix[EYE_LEFT] = new Matrix4f();
        eyeMatrix[EYE_LEFT].set(tfb.get(0), tfb.get(4), tfb.get(8), tfb.get(12), tfb.get(1), tfb.get(5), tfb.get(9), tfb.get(13), tfb.get(2), tfb.get(6), tfb.get(10), tfb.get(14), tfb.get(3), tfb.get(7), tfb.get(11), tfb.get(15));
    }
    return eyeMatrix[EYE_LEFT];
}
Also used : Matrix4f(com.jme3.math.Matrix4f) FloatBuffer(java.nio.FloatBuffer)

Example 15 with Matrix4f

use of com.jme3.math.Matrix4f in project jmonkeyengine by jMonkeyEngine.

the class OpenVR method getSeatedToAbsolutePosition.

@Override
public Vector3f getSeatedToAbsolutePosition() {
    if (environment.isSeatedExperience() == false)
        return Vector3f.ZERO;
    if (hmdSeatToStand == null) {
        hmdSeatToStand = new Vector3f();
        HmdMatrix34_t mat = vrsystemFunctions.GetSeatedZeroPoseToStandingAbsoluteTrackingPose.apply();
        Matrix4f tempmat = new Matrix4f();
        VRUtil.convertSteamVRMatrix3ToMatrix4f(mat, tempmat);
        tempmat.toTranslationVector(hmdSeatToStand);
    }
    return hmdSeatToStand;
}
Also used : HmdMatrix34_t(com.jme3.system.jopenvr.HmdMatrix34_t) Matrix4f(com.jme3.math.Matrix4f) Vector3f(com.jme3.math.Vector3f)

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