فهرست منبع

OculusVR: Use correct coordinate space conversions, looking around now works

Campbell Suter 8 سال پیش
والد
کامیت
9747c556ff

+ 13 - 7
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;

+ 3 - 2
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