use of org.joml.Quaternionf in project Terasology by MovingBlocks.
the class OpenVRStereoCamera method updateMatrices.
@Override
public void updateMatrices(float fov) {
prevViewProjectionMatrix.set(viewProjectionMatrix);
org.joml.Matrix4f leftEyeProjection = vrProvider.getState().getEyeProjectionMatrix(0);
org.joml.Matrix4f rightEyeProjection = vrProvider.getState().getEyeProjectionMatrix(1);
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;
// set camera orientation
Vector4f vecQuaternion = OpenVRUtil.convertToQuaternion(leftEyePose);
Quaternionf quaternion = new Quaternionf(vecQuaternion.x, vecQuaternion.y, vecQuaternion.z, vecQuaternion.w);
setOrientation(new Quat4f(quaternion.x, quaternion.y, quaternion.z, quaternion.w));
// view matrix is inverse of pose matrix
leftEyePose = leftEyePose.invert();
rightEyePose = rightEyePose.invert();
if (Math.sqrt(Math.pow(leftEyePose.m30(), 2) + Math.pow(leftEyePose.m31(), 2) + Math.pow(leftEyePose.m32(), 2)) < 0.25) {
return;
}
jomlMatrix4f(leftEyeProjection, projectionMatrixLeftEye);
jomlMatrix4f(rightEyeProjection, projectionMatrixRightEye);
projectionMatrix = projectionMatrixLeftEye;
jomlMatrix4f(leftEyePose, viewMatrixLeftEye);
jomlMatrix4f(rightEyePose, viewMatrixRightEye);
viewMatrix = viewMatrixLeftEye;
normViewMatrix = viewMatrixLeftEye;
reflectionMatrix.setRow(0, 1.0f, 0.0f, 0.0f, 0.0f);
reflectionMatrix.setRow(1, 0.0f, -1.0f, 0.0f, 2f * (-position.y + 32f));
reflectionMatrix.setRow(2, 0.0f, 0.0f, 1.0f, 0.0f);
reflectionMatrix.setRow(3, 0.0f, 0.0f, 0.0f, 1.0f);
viewMatrixReflected.mul(viewMatrix, reflectionMatrix);
reflectionMatrix.setRow(1, 0.0f, -1.0f, 0.0f, 0.0f);
normViewMatrixReflected.mul(normViewMatrix, reflectionMatrix);
viewTranslationLeftEye.setIdentity();
viewTranslationLeftEye.setTranslation(new Vector3f(halfIPD, 0.0f, 0.0f));
viewTranslationRightEye.setIdentity();
viewTranslationRightEye.setTranslation(new Vector3f(-halfIPD, 0.0f, 0.0f));
viewMatrixReflectedLeftEye.mul(viewMatrixReflected, viewTranslationLeftEye);
viewMatrixReflectedRightEye.mul(viewMatrixReflected, viewTranslationRightEye);
viewProjectionMatrixLeftEye = MatrixUtils.calcViewProjectionMatrix(viewMatrixLeftEye, projectionMatrixLeftEye);
viewProjectionMatrixRightEye = MatrixUtils.calcViewProjectionMatrix(viewMatrixRightEye, projectionMatrixRightEye);
inverseViewProjectionMatrixLeftEye = new Matrix4f(viewProjectionMatrixLeftEye);
inverseViewProjectionMatrixRightEye = new Matrix4f(viewProjectionMatrixRightEye);
inverseViewProjectionMatrixLeftEye.invert(viewProjectionMatrixLeftEye);
inverseViewProjectionMatrixRightEye.invert(viewProjectionMatrixRightEye);
inverseProjectionMatrixLeftEye = new Matrix4f(projectionMatrixLeftEye);
inverseProjectionMatrixRightEye = new Matrix4f(projectionMatrixRightEye);
inverseProjectionMatrixLeftEye.invert(projectionMatrixLeftEye);
inverseProjectionMatrixRightEye.invert(projectionMatrixRightEye);
updateFrustum();
}
Aggregations