From ae7a134f1e8763bf25ecaf894ef3f2136288feda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rickard=20Ed=C3=A9n?= Date: Mon, 9 Oct 2017 07:44:03 +0200 Subject: [PATCH] added functionality to use front mounted vive camera --- .../main/java/com/jme3/input/vr/OpenVR.java | 56 +++++++++++++------ 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/jme3-vr/src/main/java/com/jme3/input/vr/OpenVR.java b/jme3-vr/src/main/java/com/jme3/input/vr/OpenVR.java index a9f3fdcfb..71007b5ca 100644 --- a/jme3-vr/src/main/java/com/jme3/input/vr/OpenVR.java +++ b/jme3-vr/src/main/java/com/jme3/input/vr/OpenVR.java @@ -18,6 +18,7 @@ import com.jme3.system.jopenvr.OpenVRUtil; import com.jme3.system.jopenvr.TrackedDevicePose_t; import com.jme3.system.jopenvr.VR_IVRCompositor_FnTable; import com.jme3.system.jopenvr.VR_IVRSystem_FnTable; +import com.jme3.system.jopenvr.VR_IVRTrackedCamera_FnTable; import com.jme3.util.VRUtil; import com.sun.jna.Memory; import com.sun.jna.Pointer; @@ -41,19 +42,20 @@ public class OpenVR implements VRAPI { private static final Logger logger = Logger.getLogger(OpenVR.class.getName()); private static VR_IVRCompositor_FnTable compositorFunctions; + private static VR_IVRTrackedCamera_FnTable cameraFunctions; private static VR_IVRSystem_FnTable vrsystemFunctions; private static boolean initSuccess = false; private static boolean flipEyes = false; - private IntBuffer hmdDisplayFrequency; - private TrackedDevicePose_t.ByReference hmdTrackedDevicePoseReference; - protected TrackedDevicePose_t[] hmdTrackedDevicePoses; + private static IntBuffer hmdDisplayFrequency; + private static TrackedDevicePose_t.ByReference hmdTrackedDevicePoseReference; + protected static TrackedDevicePose_t[] hmdTrackedDevicePoses; - protected IntByReference hmdErrorStore; + protected static IntByReference hmdErrorStore; - private final Quaternion rotStore = new Quaternion(); - private final Vector3f posStore = new Vector3f(); + private static final Quaternion rotStore = new Quaternion(); + private static final Vector3f posStore = new Vector3f(); private static FloatByReference tlastVsync; @@ -65,21 +67,20 @@ public class OpenVR implements VRAPI { // for debugging latency private int frames = 0; - protected Matrix4f[] poseMatrices; + protected static Matrix4f[] poseMatrices; - private final Matrix4f hmdPose = Matrix4f.IDENTITY.clone(); - private Matrix4f hmdProjectionLeftEye; - private Matrix4f hmdProjectionRightEye; - private Matrix4f hmdPoseLeftEye; - private Matrix4f hmdPoseRightEye; + private static final Matrix4f hmdPose = Matrix4f.IDENTITY.clone(); + private static Matrix4f hmdProjectionLeftEye; + private static Matrix4f hmdProjectionRightEye; + private static Matrix4f hmdPoseLeftEye; + private static Matrix4f hmdPoseRightEye; - private Vector3f hmdPoseLeftEyeVec, hmdPoseRightEyeVec, hmdSeatToStand; - - private float vsyncToPhotons; - private double timePerFrame, frameCountRun; - private long frameCount; - private OpenVRInput VRinput; + private static Vector3f hmdPoseLeftEyeVec, hmdPoseRightEyeVec, hmdSeatToStand; + private static float vsyncToPhotons; + private static double timePerFrame, frameCountRun; + private static long frameCount; + private static OpenVRInput VRinput; private VREnvironment environment = null; @@ -107,6 +108,10 @@ public class OpenVR implements VRAPI { return compositorFunctions; } + public VR_IVRTrackedCamera_FnTable getTrackedCamera(){ + return cameraFunctions; + } + @Override public String getName() { return "OpenVR"; @@ -235,6 +240,21 @@ public class OpenVR implements VRAPI { } return compositorFunctions != null; } + + public void initCamera(boolean allowed) { + hmdErrorStore.setValue(0); // clear the error store + if( allowed && vrsystemFunctions != null ) { + IntByReference intptr = JOpenVRLibrary.VR_GetGenericInterface(JOpenVRLibrary.IVRTrackedCamera_Version, hmdErrorStore); + if (intptr != null){ + cameraFunctions = new VR_IVRTrackedCamera_FnTable(intptr.getPointer()); + if(cameraFunctions != null && hmdErrorStore.getValue() == 0 ){ + cameraFunctions.setAutoSynch(false); + cameraFunctions.read(); + logger.config("OpenVR Camera initialized"); + } + } + } + } @Override public void destroy() {