/** * Get the pose of an eye. * @param eyeIndex - An integer specifying the eye: 0 for the left eye, 1 for the right eye. * @return the pose, as a Matrix4f */ public Matrix4f getEyePose(int eyeIndex) { Matrix4f matrixReturn = new Matrix4f(headPose); matrixReturn.mul(eyePoses[eyeIndex]); return matrixReturn; }
private void jomlMatrix4f(org.joml.Matrix4f matrixInput, org.terasology.math.geom.Matrix4f matrixOut) { matrixOut.set(0, 0, matrixInput.m00()); matrixOut.set(0, 1, matrixInput.m10()); matrixOut.set(0, 2, matrixInput.m20()); matrixOut.set(0, 3, matrixInput.m30()); matrixOut.set(1, 0, matrixInput.m01()); matrixOut.set(1, 1, matrixInput.m11()); matrixOut.set(1, 2, matrixInput.m21()); matrixOut.set(1, 3, matrixInput.m31()); matrixOut.set(2, 0, matrixInput.m02()); matrixOut.set(2, 1, matrixInput.m12()); matrixOut.set(2, 2, matrixInput.m22()); matrixOut.set(2, 3, matrixInput.m32()); matrixOut.set(3, 0, matrixInput.m03()); matrixOut.set(3, 1, matrixInput.m13()); matrixOut.set(3, 2, matrixInput.m23()); matrixOut.set(3, 3, matrixInput.m33()); }
/** * A callback target for the controller listener. When this callback triggers, the pos of the mount point will * cuange to the value of the pose parameter. This is mainly designed as a callback, and not intended to be part * of the public interface of this class. * @param pose - the controller pose - a homogenous transformation matrix. * @param handIndex - the hand index - 0 for left and 1 for right. */ public void poseChanged(Matrix4f pose, int handIndex) { // do nothing for the second controller // TODO: put a hand for the second controller. if (handIndex != 0) { return; } trackingDataReceived = true; Matrix4f adjustedPose = pose.mul(toolAdjustmentMatrix); translate = new Vector3f(adjustedPose.m30(), adjustedPose.m31(), adjustedPose.m32()); org.joml.Vector4f jomlQuaternion = org.terasology.rendering.openvrprovider.OpenVRUtil.convertToQuaternion(adjustedPose); if (rotationQuaternion == null) { rotationQuaternion = new Quat4f(jomlQuaternion.x, jomlQuaternion.y, jomlQuaternion.z, jomlQuaternion.w); } else { rotationQuaternion.set(jomlQuaternion.x, jomlQuaternion.y, jomlQuaternion.z, jomlQuaternion.w); } } }
public Matrix4f getModelViewMatrix(GameItem gameItem, Matrix4f viewMatrix) { Vector3f rotation = gameItem.getRotation(); modelViewMatrix.identity().translate(gameItem.getPosition()). rotateX((float)Math.toRadians(-rotation.x)). rotateY((float)Math.toRadians(-rotation.y)). rotateZ((float)Math.toRadians(-rotation.z)). scale(gameItem.getScale()); Matrix4f viewCurr = new Matrix4f(viewMatrix); return viewCurr.mul(modelViewMatrix); } }
public Matrix4f buildModelLightViewMatrix(GameItem gameItem, Matrix4f matrix) { Vector3f rotation = gameItem.getRotation(); modelLightMatrix.identity().translate(gameItem.getPosition()). rotateX((float)Math.toRadians(-rotation.x)). rotateY((float)Math.toRadians(-rotation.y)). rotateZ((float)Math.toRadians(-rotation.z)). scale(gameItem.getScale()); modelLightViewMatrix.set(matrix); return modelLightViewMatrix.mul(modelLightMatrix); }
private Matrix4f updateGenericViewMatrix(Vector3f position, Vector3f rotation, Matrix4f matrix) { matrix.identity(); // First do the rotation so camera rotates over its position matrix.rotate((float)Math.toRadians(rotation.x), X_AXIS) .rotate((float)Math.toRadians(rotation.y), Y_AXIS); // Then do the translation matrix.translate(-position.x, -position.y, -position.z); return matrix; }
public void put4x3Transposed(Matrix4f m, int offset, FloatBuffer dest) { dest.put(offset, m.m00()); dest.put(offset+1, m.m10()); dest.put(offset+2, m.m20()); dest.put(offset+3, m.m30()); dest.put(offset+4, m.m01()); dest.put(offset+5, m.m11()); dest.put(offset+6, m.m21()); dest.put(offset+7, m.m31()); dest.put(offset+8, m.m02()); dest.put(offset+9, m.m12()); dest.put(offset+10, m.m22()); dest.put(offset+11, m.m32()); }
public final Matrix4f getOrtho2DProjectionMatrix(float left, float right, float bottom, float top) { ortho2DMatrix.identity(); ortho2DMatrix.setOrtho2D(left, right, bottom, top); return ortho2DMatrix; }
public void copy4x3(Matrix4f src, Matrix4f dest) { dest._m00(src.m00()); dest._m01(src.m01()); dest._m02(src.m02()); dest._m10(src.m10()); dest._m11(src.m11()); dest._m12(src.m12()); dest._m20(src.m20()); dest._m21(src.m21()); dest._m22(src.m22()); dest._m30(src.m30()); dest._m31(src.m31()); dest._m32(src.m32()); }
public void setUniform(String uniformName, Matrix4f[] matrices) { try (MemoryStack stack = MemoryStack.stackPush()) { int length = matrices != null ? matrices.length : 0; FloatBuffer fb = stack.mallocFloat(16 * length); for (int i = 0; i < length; i++) { matrices[i].get(16 * i, fb); } glUniformMatrix4fv(uniforms.get(uniformName), false, fb); } }
@Override public void setGlobalAttributes(float x, float y, float z, float sx, float sy, float sz) { global.identity(); global.translate(x, y, z); global.scale(sx, sy, sz); global.get(matBfr); for(ShaderProgram shader : shaders) { useProgram(shader); GL20.glUniformMatrix4fv(shader.ufs[GLOBAL], false, matBfr); } }
org.joml.Matrix4f leftEyePose = vrProvider.getState().getEyePose(0); org.joml.Matrix4f rightEyePose = vrProvider.getState().getEyePose(1); float halfIPD = (float) Math.sqrt(Math.pow(leftEyePose.m30() - rightEyePose.m30(), 2) + Math.pow(leftEyePose.m31() - rightEyePose.m31(), 2) + Math.pow(leftEyePose.m32() - rightEyePose.m32(), 2)) / 2.0f; leftEyePose = leftEyePose.invert(); // view matrix is inverse of pose matrix rightEyePose = rightEyePose.invert(); if (Math.sqrt(Math.pow(leftEyePose.m30(), 2) + Math.pow(leftEyePose.m31(), 2) + Math.pow(leftEyePose.m32(), 2)) < 0.25) { return;
/** * Get the projection matrix for an eye. * @param eyeIndex - An integer specifying the eye: 0 for the left eye, 1 for the right eye. * @return the projection matrix, as a Matrix4f. */ public Matrix4f getEyeProjectionMatrix(int eyeIndex) { return new Matrix4f(projectionMatrices[eyeIndex]); }
public final Matrix4f getOrtho2DProjectionMatrix(float left, float right, float bottom, float top) { return ortho2DMatrix.setOrtho2D(left, right, bottom, top); }
public Matrix4f getModelViewMatrix(GameItem gameItem, Matrix4f viewMatrix) { Vector3f rotation = gameItem.getRotation(); modelViewMatrix.identity().translate(gameItem.getPosition()). rotateX((float)Math.toRadians(-rotation.x)). rotateY((float)Math.toRadians(-rotation.y)). rotateZ((float)Math.toRadians(-rotation.z)). scale(gameItem.getScale()); Matrix4f viewCurr = new Matrix4f(viewMatrix); return viewCurr.mul(modelViewMatrix); }
public Matrix4f buildOrtoProjModelMatrix(GameItem gameItem, Matrix4f orthoMatrix) { Vector3f rotation = gameItem.getRotation(); modelMatrix.identity().translate(gameItem.getPosition()). rotateX((float) Math.toRadians(-rotation.x)). rotateY((float) Math.toRadians(-rotation.y)). rotateZ((float) Math.toRadians(-rotation.z)). scale(gameItem.getScale()); orthoModelMatrix.set(orthoMatrix); orthoModelMatrix.mul(modelMatrix); return orthoModelMatrix; } }