From 9747c556ffaa65a36138aa7c9647c4c1271d3d9a Mon Sep 17 00:00:00 2001 From: Campbell Suter Date: Sun, 1 Oct 2017 23:45:43 +1300 Subject: [PATCH] OculusVR: Use correct coordinate space conversions, looking around now works --- .../main/java/com/jme3/input/vr/OculusVR.java | 20 ++++++++++++------- .../com/jme3/util/VRViewManagerOculus.java | 5 +++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/jme3-vr/src/main/java/com/jme3/input/vr/OculusVR.java b/jme3-vr/src/main/java/com/jme3/input/vr/OculusVR.java index 5e6b93f90..56d49f705 100644 --- a/jme3-vr/src/main/java/com/jme3/input/vr/OculusVR.java +++ b/jme3-vr/src/main/java/com/jme3/input/vr/OculusVR.java @@ -327,7 +327,7 @@ public class OculusVR implements VRAPI { @Override public Quaternion getOrientation() { - return quatO2J(headPose.Orientation(), new Quaternion()).inverseLocal(); + return quatO2J(headPose.Orientation(), new Quaternion()); } @Override @@ -349,8 +349,6 @@ public class OculusVR implements VRAPI { matrixO2J(projections[eye], mat); - mat.transposeLocal(); // Apparently LibOVR has a different coordinate set - yay for us. - return mat; } @@ -552,6 +550,8 @@ public class OculusVR implements VRAPI { * @return The {@code to} argument. */ public static Matrix4f matrixO2J(OVRMatrix4f from, Matrix4f to) { + to.loadIdentity(); // For the additional columns (unless I'm badly misunderstanding matricies) + for (int x = 0; x < 4; x++) { for (int y = 0; y < 4; y++) { float val = from.M(x + y * 4); // TODO verify this @@ -559,6 +559,8 @@ public class OculusVR implements VRAPI { } } + to.transposeLocal(); // jME vs LibOVR coordinate spaces - Yay! + return to; } @@ -570,13 +572,16 @@ public class OculusVR implements VRAPI { * @return The {@code to} argument. */ public static Quaternion quatO2J(OVRQuatf from, Quaternion to) { + // jME and LibOVR do their coordinate spaces differently for rotations, so flip Y and W (thanks, jMonkeyVR). to.set( from.x(), - from.y(), + -from.y(), from.z(), - from.w() + -from.w() ); + to.normalizeLocal(); + return to; } @@ -588,10 +593,11 @@ public class OculusVR implements VRAPI { * @return The {@code to} argument. */ public static Vector3f vecO2J(OVRVector3f from, Vector3f to) { + // jME and LibOVR disagree on which way X and Z is, too. to.set( - from.x(), + -from.x(), from.y(), - from.z() + -from.z() ); return to; diff --git a/jme3-vr/src/main/java/com/jme3/util/VRViewManagerOculus.java b/jme3-vr/src/main/java/com/jme3/util/VRViewManagerOculus.java index 20968aa1f..4711963f6 100644 --- a/jme3-vr/src/main/java/com/jme3/util/VRViewManagerOculus.java +++ b/jme3-vr/src/main/java/com/jme3/util/VRViewManagerOculus.java @@ -187,8 +187,9 @@ public class VRViewManagerOculus extends AbstractVRViewManager { ovr_GetTextureSwapChainCurrentIndex(session(), hardware.getChain(eye), currentIndexB); int index = currentIndexB.get(); - // FIXME eyes inverted - (eye != ovrEye_Left ? leftViewPort : rightViewPort).setOutputFrameBuffer(hardware.getFramebuffers(eye)[index]); + // Constantly (each frame) rotating through a series of + // frame buffers, so make sure we write into the correct one. + (eye == ovrEye_Left ? leftViewPort : rightViewPort).setOutputFrameBuffer(hardware.getFramebuffers(eye)[index]); } // Now the game will render into the buffers given to us by LibOVR