/** * <code>set</code> sets the values of this matrix from an array of * values assuming that the data is rowMajor order; * * @param matrix * the matrix to set the value to. */ public void set(float[] matrix) { set(matrix, true); }
/** * Internal use only. Sets the world matrix to use for future * rendering. This has no effect unless objects are rendered manually * using {@link Material#render(com.jme3.scene.Geometry, com.jme3.renderer.RenderManager) }. * Using {@link #renderGeometry(com.jme3.scene.Geometry) } will * override this value. * * @param mat The world matrix to set */ public void setWorldMatrix(Matrix4f mat) { worldMatrix.set(mat); }
/** * Create a new Matrix4f, given data in column-major format. * * @param array * An array of 16 floats in column-major format (translation in elements 12, 13 and 14). */ public Matrix4f(float[] array) { set(array, false); }
/** * Convert specific OpenVR {@link com.jme3.system.jopenvr.HmdMatrix44_t HmdMatrix34_t} into JME {@link Matrix4f Matrix4f} * @param hmdMatrix the input matrix * @param mat the converted matrix * @return the converted matrix */ public static Matrix4f convertSteamVRMatrix4ToMatrix4f(com.jme3.system.jopenvr.HmdMatrix44_t hmdMatrix, Matrix4f mat){ mat.set(hmdMatrix.m[0], hmdMatrix.m[1], hmdMatrix.m[2], hmdMatrix.m[3], hmdMatrix.m[4], hmdMatrix.m[5], hmdMatrix.m[6], hmdMatrix.m[7], hmdMatrix.m[8], hmdMatrix.m[9], hmdMatrix.m[10], hmdMatrix.m[11], hmdMatrix.m[12], hmdMatrix.m[13], hmdMatrix.m[14], hmdMatrix.m[15]); return mat; }
/** * Convert specific OpenVR {@link com.jme3.system.jopenvr.HmdMatrix34_t HmdMatrix34_t} into JME {@link Matrix4f Matrix4f} * @param hmdMatrix the input matrix * @param mat the converted matrix * @return the converted matrix */ public static Matrix4f convertSteamVRMatrix3ToMatrix4f(com.jme3.system.jopenvr.HmdMatrix34_t hmdMatrix, Matrix4f mat){ mat.set(hmdMatrix.m[0], hmdMatrix.m[1], hmdMatrix.m[2], hmdMatrix.m[3], hmdMatrix.m[4], hmdMatrix.m[5], hmdMatrix.m[6], hmdMatrix.m[7], hmdMatrix.m[8], hmdMatrix.m[9], hmdMatrix.m[10], hmdMatrix.m[11], 0f, 0f, 0f, 1f); return mat; }
private static Matrix4f buildTransform(double[] transform) { float[] m = new float[transform.length]; for(int i = 0; i < transform.length; ++i) m[i] = (float) transform[i]; Matrix4f matrix = new Matrix4f(); matrix.set(m, false); return matrix; } }
public Matrix4f mult(float scalar, Matrix4f store) { store.set(this); store.multLocal(scalar); return store; }
/** * Updates the view projection matrix. */ public void updateViewProjection() { if (overrideProjection) { viewProjectionMatrix.set(projectionMatrixOverride).multLocal(viewMatrix); } else { //viewProjectionMatrix.set(viewMatrix).multLocal(projectionMatrix); viewProjectionMatrix.set(projectionMatrix).multLocal(viewMatrix); } }
@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]; }
@Override public Matrix4f getHMDMatrixProjectionRightEye(Camera cam) { if( eyeRightInfo == null ) return cam.getProjectionMatrix(); if( eyeMatrix[EYE_RIGHT] == null ) { FloatBuffer tfb = FloatBuffer.allocate(16); com.jme3.system.osvr.osvrdisplay.OsvrDisplayLibrary.osvrClientGetViewerEyeSurfaceProjectionMatrixf(displayConfig, 0, (byte)EYE_RIGHT, 0, cam.getFrustumNear(), cam.getFrustumFar(), (short)0, tfb); eyeMatrix[EYE_RIGHT] = new Matrix4f(); eyeMatrix[EYE_RIGHT].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_RIGHT]; }
public Matrix4f mult(float scalar) { Matrix4f out = new Matrix4f(); out.set(this); out.multLocal(scalar); return out; }
public void setCamera(Camera cam, Matrix4f viewMatrix, Matrix4f projMatrix, Matrix4f viewProjMatrix) { this.viewMatrix.set(viewMatrix); this.projMatrix.set(projMatrix); this.viewProjMatrix.set(viewProjMatrix); camLoc.set(cam.getLocation()); cam.getLeft(camLeft); cam.getUp(camUp); cam.getDirection(camDir); near = cam.getFrustumNear(); far = cam.getFrustumFar(); }
/** * Overrides the projection matrix used by the camera. Will * use the matrix for computing the view projection matrix as well. * Use null argument to return to normal functionality. * * @param projMatrix */ public void setProjectionMatrix(Matrix4f projMatrix) { if (projMatrix == null) { overrideProjection = false; projectionMatrixOverride.loadIdentity(); } else { overrideProjection = true; projectionMatrixOverride.set(projMatrix); } updateViewProjection(); }
@Override public void updatePose(){ int result = VRCompositor.nVRCompositor_WaitGetPoses(trackedDevicePose.address(), trackedDevicePose.remaining(), 0, 0); // NPE when calling without a gamePoseArray. Issue filed with lwjgl #418 // int result = VRCompositor.VRCompositor_WaitGetPoses(trackedDevicePose, null); environment.getVRinput().updateControllerStates(); // read pose data from native for (int nDevice = 0; nDevice < VR.k_unMaxTrackedDeviceCount; ++nDevice ){ if( hmdTrackedDevicePoses[nDevice].bPoseIsValid() ){ convertSteamVRMatrix3ToMatrix4f(hmdTrackedDevicePoses[nDevice].mDeviceToAbsoluteTracking(), poseMatrices[nDevice]); } } if ( hmdTrackedDevicePoses[VR.k_unTrackedDeviceIndex_Hmd].bPoseIsValid()){ hmdPose.set(poseMatrices[VR.k_unTrackedDeviceIndex_Hmd]); } else { hmdPose.set(Matrix4f.IDENTITY); } }
public void setArg(int index, Matrix3f mat) { TempVars vars = TempVars.get(); try { Matrix4f m = vars.tempMat4; m.zero(); for (int i=0; i<3; ++i) { for (int j=0; j<3; ++j) { m.set(i, j, mat.get(i, j)); } } setArg(index, m); } finally { vars.release(); } }
@Override public void applyBindPose(Transform localTransform, Matrix4f inverseModelBindMatrix, Joint parent) { modelTransformMatrix.set(inverseModelBindMatrix).invertLocal(); // model transform = model bind if (parent != null) { ((MatrixJointModelTransform) parent.getJointModelTransform()).getModelTransformMatrix().invert().mult(modelTransformMatrix, modelTransformMatrix); } localTransform.fromTransformMatrix(modelTransformMatrix); }
/** * Convert specific OpenVR {@link org.lwjgl.openvr.HmdMatrix34 HmdMatrix34} into JME {@link Matrix4f Matrix4f} * @param hmdMatrix the input matrix * @param mat the converted matrix * @return the converted matrix */ public static Matrix4f convertSteamVRMatrix3ToMatrix4f(org.lwjgl.openvr.HmdMatrix34 hmdMatrix, Matrix4f mat){ mat.set(hmdMatrix.m(0), hmdMatrix.m(1), hmdMatrix.m(2), hmdMatrix.m(3), hmdMatrix.m(4), hmdMatrix.m(5), hmdMatrix.m(6), hmdMatrix.m(7), hmdMatrix.m(8), hmdMatrix.m(9), hmdMatrix.m(10), hmdMatrix.m(11), 0f, 0f, 0f, 1f); return mat; }
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); } boolean debugfrustums = false;
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); } boolean debugfrustums = false;
/** * Convert specific OpenVR {@link org.lwjgl.openvr.HmdMatrix34 HmdMatrix34_t} into JME {@link Matrix4f Matrix4f} * @param hmdMatrix the input matrix * @param mat the converted matrix * @return the converted matrix */ public static Matrix4f convertSteamVRMatrix4ToMatrix4f(org.lwjgl.openvr.HmdMatrix44 hmdMatrix, Matrix4f mat){ mat.set(hmdMatrix.m(0), hmdMatrix.m(1), hmdMatrix.m(2), hmdMatrix.m(3), hmdMatrix.m(4), hmdMatrix.m(5), hmdMatrix.m(6), hmdMatrix.m(7), hmdMatrix.m(8), hmdMatrix.m(9), hmdMatrix.m(10), hmdMatrix.m(11), hmdMatrix.m(12), hmdMatrix.m(13), hmdMatrix.m(14), hmdMatrix.m(15)); return mat; }