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

empirephoenix-patch-1
Campbell Suter 7 years ago
parent 760277f61d
commit 9747c556ff
No known key found for this signature in database
GPG Key ID: 754A66CCF3F73C0F
  1. 20
      jme3-vr/src/main/java/com/jme3/input/vr/OculusVR.java
  2. 5
      jme3-vr/src/main/java/com/jme3/util/VRViewManagerOculus.java

@ -327,7 +327,7 @@ public class OculusVR implements VRAPI {
@Override @Override
public Quaternion getOrientation() { public Quaternion getOrientation() {
return quatO2J(headPose.Orientation(), new Quaternion()).inverseLocal(); return quatO2J(headPose.Orientation(), new Quaternion());
} }
@Override @Override
@ -349,8 +349,6 @@ public class OculusVR implements VRAPI {
matrixO2J(projections[eye], mat); matrixO2J(projections[eye], mat);
mat.transposeLocal(); // Apparently LibOVR has a different coordinate set - yay for us.
return mat; return mat;
} }
@ -552,6 +550,8 @@ public class OculusVR implements VRAPI {
* @return The {@code to} argument. * @return The {@code to} argument.
*/ */
public static Matrix4f matrixO2J(OVRMatrix4f from, Matrix4f to) { 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 x = 0; x < 4; x++) {
for (int y = 0; y < 4; y++) { for (int y = 0; y < 4; y++) {
float val = from.M(x + y * 4); // TODO verify this 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; return to;
} }
@ -570,13 +572,16 @@ public class OculusVR implements VRAPI {
* @return The {@code to} argument. * @return The {@code to} argument.
*/ */
public static Quaternion quatO2J(OVRQuatf from, Quaternion to) { 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( to.set(
from.x(), from.x(),
from.y(), -from.y(),
from.z(), from.z(),
from.w() -from.w()
); );
to.normalizeLocal();
return to; return to;
} }
@ -588,10 +593,11 @@ public class OculusVR implements VRAPI {
* @return The {@code to} argument. * @return The {@code to} argument.
*/ */
public static Vector3f vecO2J(OVRVector3f from, Vector3f to) { public static Vector3f vecO2J(OVRVector3f from, Vector3f to) {
// jME and LibOVR disagree on which way X and Z is, too.
to.set( to.set(
from.x(), -from.x(),
from.y(), from.y(),
from.z() -from.z()
); );
return to; return to;

@ -187,8 +187,9 @@ public class VRViewManagerOculus extends AbstractVRViewManager {
ovr_GetTextureSwapChainCurrentIndex(session(), hardware.getChain(eye), currentIndexB); ovr_GetTextureSwapChainCurrentIndex(session(), hardware.getChain(eye), currentIndexB);
int index = currentIndexB.get(); int index = currentIndexB.get();
// FIXME eyes inverted // Constantly (each frame) rotating through a series of
(eye != ovrEye_Left ? leftViewPort : rightViewPort).setOutputFrameBuffer(hardware.getFramebuffers(eye)[index]); // 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 // Now the game will render into the buffers given to us by LibOVR

Loading…
Cancel
Save