From 651e77953a63e6ef3de91b6197da8ae8e6cbd8c2 Mon Sep 17 00:00:00 2001 From: seint Date: Thu, 13 Apr 2017 08:40:34 +0200 Subject: [PATCH] VR controller clean integration --- .../main/java/com/jme3/app/VRAppState.java | 12 +- .../main/java/com/jme3/app/VRApplication.java | 12 +- .../main/java/com/jme3/app/VREnvironment.java | 14 +++ .../main/java/com/jme3/input/vr/OpenVR.java | 37 +++--- .../java/com/jme3/input/vr/OpenVRInput.java | 115 +++++++++++++----- .../input/vr/OpenVRTrackedController.java | 93 ++++++++++++++ .../main/java/com/jme3/input/vr/VRBounds.java | 10 +- .../jme3/input/vr/VRTrackedController.java | 40 ++++++ .../com/jme3/util/AbstractVRViewManager.java | 41 ++++--- .../java/com/jme3/util/VRViewManager.java | 16 ++- .../java/com/jme3/util/VRViewManagerOSVR.java | 8 +- .../com/jme3/util/VRViewManagerOpenVR.java | 44 +++++-- 12 files changed, 348 insertions(+), 94 deletions(-) create mode 100644 jme3-vr/src/main/java/com/jme3/input/vr/OpenVRTrackedController.java diff --git a/jme3-vr/src/main/java/com/jme3/app/VRAppState.java b/jme3-vr/src/main/java/com/jme3/app/VRAppState.java index 5b850c931..a468e71b9 100644 --- a/jme3-vr/src/main/java/com/jme3/app/VRAppState.java +++ b/jme3-vr/src/main/java/com/jme3/app/VRAppState.java @@ -241,7 +241,7 @@ public class VRAppState extends AbstractAppState { return application.getViewPort(); } - return environment.getVRViewManager().getLeftViewport(); + return environment.getVRViewManager().getLeftViewPort(); } /** @@ -253,7 +253,7 @@ public class VRAppState extends AbstractAppState { if( environment.getVRViewManager() == null ){ return application.getViewPort(); } - return environment.getVRViewManager().getRightViewport(); + return environment.getVRViewManager().getRightViewPort(); } /** @@ -263,12 +263,12 @@ public class VRAppState extends AbstractAppState { public void setBackgroundColors(ColorRGBA clr) { if( environment.getVRViewManager() == null ) { application.getViewPort().setBackgroundColor(clr); - } else if( environment.getVRViewManager().getLeftViewport() != null ) { + } else if( environment.getVRViewManager().getLeftViewPort() != null ) { - environment.getVRViewManager().getLeftViewport().setBackgroundColor(clr); + environment.getVRViewManager().getLeftViewPort().setBackgroundColor(clr); - if( environment.getVRViewManager().getRightViewport() != null ){ - environment.getVRViewManager().getRightViewport().setBackgroundColor(clr); + if( environment.getVRViewManager().getRightViewPort() != null ){ + environment.getVRViewManager().getRightViewPort().setBackgroundColor(clr); } } } diff --git a/jme3-vr/src/main/java/com/jme3/app/VRApplication.java b/jme3-vr/src/main/java/com/jme3/app/VRApplication.java index 698451248..9d502431d 100644 --- a/jme3-vr/src/main/java/com/jme3/app/VRApplication.java +++ b/jme3-vr/src/main/java/com/jme3/app/VRApplication.java @@ -254,7 +254,7 @@ public abstract class VRApplication implements Application, SystemListener { dummyCam = new Camera(); initStateManager(); - + // Create the GUI manager. guiManager = new VRGuiManager(null); @@ -1085,7 +1085,7 @@ public abstract class VRApplication implements Application, SystemListener { */ public ViewPort getLeftViewPort() { if( viewmanager == null ) return getViewPort(); - return viewmanager.getLeftViewport(); + return viewmanager.getLeftViewPort(); } /** @@ -1095,7 +1095,7 @@ public abstract class VRApplication implements Application, SystemListener { */ public ViewPort getRightViewPort() { if( viewmanager == null ) return getViewPort(); - return viewmanager.getRightViewport(); + return viewmanager.getRightViewPort(); } @@ -1106,9 +1106,9 @@ public abstract class VRApplication implements Application, SystemListener { public void setBackgroundColors(ColorRGBA clr) { if( viewmanager == null ) { getViewPort().setBackgroundColor(clr); - } else if( viewmanager.getLeftViewport() != null ) { - viewmanager.getLeftViewport().setBackgroundColor(clr); - if( viewmanager.getRightViewport() != null ) viewmanager.getRightViewport().setBackgroundColor(clr); + } else if( viewmanager.getLeftViewPort() != null ) { + viewmanager.getLeftViewPort().setBackgroundColor(clr); + if( viewmanager.getRightViewPort() != null ) viewmanager.getRightViewPort().setBackgroundColor(clr); } } diff --git a/jme3-vr/src/main/java/com/jme3/app/VREnvironment.java b/jme3-vr/src/main/java/com/jme3/app/VREnvironment.java index e9e6d0aac..006400604 100644 --- a/jme3-vr/src/main/java/com/jme3/app/VREnvironment.java +++ b/jme3-vr/src/main/java/com/jme3/app/VREnvironment.java @@ -8,6 +8,7 @@ import com.jme3.app.state.AppState; import com.jme3.input.vr.OSVR; import com.jme3.input.vr.OpenVR; import com.jme3.input.vr.VRAPI; +import com.jme3.input.vr.VRBounds; import com.jme3.input.vr.VRInputAPI; import com.jme3.renderer.Camera; import com.jme3.scene.Spatial; @@ -27,6 +28,8 @@ public class VREnvironment { private VRGuiManager guiManager = null; private VRMouseManager mouseManager = null; private VRViewManager viewmanager = null; + private VRBounds bounds = null; + /** * The underlying system VR API. By default set to {@link VRConstants#SETTING_VRAPI_OPENVR_VALUE}. @@ -73,6 +76,9 @@ public class VREnvironment { guiManager = new VRGuiManager(this); mouseManager = new VRMouseManager(this); + + bounds = new VRBounds(); + dummyCam = new Camera(); processSettings(); @@ -86,6 +92,14 @@ public class VREnvironment { return hardware; } + /** + * Get the VR bounds. + * @return the VR bounds. + */ + public VRBounds getVRBounds(){ + return bounds; + } + /** * Get the VR dedicated input. * @return the VR dedicated input. 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 8171bc48a..509e84987 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 @@ -46,14 +46,14 @@ public class OpenVR implements VRAPI { private static boolean initSuccess = false; private static boolean flipEyes = false; - private static IntBuffer hmdDisplayFrequency; - private static TrackedDevicePose_t.ByReference hmdTrackedDevicePoseReference; - protected static TrackedDevicePose_t[] hmdTrackedDevicePoses; + private IntBuffer hmdDisplayFrequency; + private TrackedDevicePose_t.ByReference hmdTrackedDevicePoseReference; + protected TrackedDevicePose_t[] hmdTrackedDevicePoses; - protected static IntByReference hmdErrorStore; + protected IntByReference hmdErrorStore; - private static final Quaternion rotStore = new Quaternion(); - private static final Vector3f posStore = new Vector3f(); + private final Quaternion rotStore = new Quaternion(); + private final Vector3f posStore = new Vector3f(); private static FloatByReference tlastVsync; @@ -65,20 +65,21 @@ public class OpenVR implements VRAPI { // for debugging latency private int frames = 0; - protected static Matrix4f[] poseMatrices; + protected Matrix4f[] poseMatrices; - 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 final Matrix4f hmdPose = Matrix4f.IDENTITY.clone(); + private Matrix4f hmdProjectionLeftEye; + private Matrix4f hmdProjectionRightEye; + private Matrix4f hmdPoseLeftEye; + private Matrix4f hmdPoseRightEye; - private static Vector3f hmdPoseLeftEyeVec, hmdPoseRightEyeVec, hmdSeatToStand; + private Vector3f hmdPoseLeftEyeVec, hmdPoseRightEyeVec, hmdSeatToStand; + + private float vsyncToPhotons; + private double timePerFrame, frameCountRun; + private long frameCount; + private OpenVRInput VRinput; - private static float vsyncToPhotons; - private static double timePerFrame, frameCountRun; - private static long frameCount; - private static OpenVRInput VRinput; private VREnvironment environment = null; @@ -181,7 +182,7 @@ public class OpenVR implements VRAPI { VRinput.updateConnectedControllers(); // init bounds & chaperone info - VRBounds.init(); + environment.getVRBounds().init(this); logger.config("Initializing OpenVR system [SUCCESS]"); initSuccess = true; diff --git a/jme3-vr/src/main/java/com/jme3/input/vr/OpenVRInput.java b/jme3-vr/src/main/java/com/jme3/input/vr/OpenVRInput.java index 0c565d0a1..6336cb4d9 100644 --- a/jme3-vr/src/main/java/com/jme3/input/vr/OpenVRInput.java +++ b/jme3-vr/src/main/java/com/jme3/input/vr/OpenVRInput.java @@ -5,6 +5,7 @@ */ package com.jme3.input.vr; +import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -183,28 +184,50 @@ public class OpenVRInput implements VRInputAPI { @Override public Vector3f getVelocity(int controllerIndex) { - int index = OpenVRInput.controllerIndex[controllerIndex]; - if( needsNewVelocity[index] ) { - OpenVR.hmdTrackedDevicePoses[index].readField("vVelocity"); - needsNewVelocity[index] = false; - } - tempVel.x = OpenVR.hmdTrackedDevicePoses[index].vVelocity.v[0]; - tempVel.y = OpenVR.hmdTrackedDevicePoses[index].vVelocity.v[1]; - tempVel.z = OpenVR.hmdTrackedDevicePoses[index].vVelocity.v[2]; - return tempVel; + + if (environment != null){ + + if (environment.getVRHardware() instanceof OpenVR){ + int index = OpenVRInput.controllerIndex[controllerIndex]; + if( needsNewVelocity[index] ) { + ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].readField("vVelocity"); + needsNewVelocity[index] = false; + } + tempVel.x = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vVelocity.v[0]; + tempVel.y = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vVelocity.v[1]; + tempVel.z = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vVelocity.v[2]; + return tempVel; + } else { + throw new IllegalStateException("VR hardware "+environment.getVRHardware().getClass().getSimpleName()+" is not a subclass of "+OpenVR.class.getSimpleName()); + } + } else { + throw new IllegalStateException("VR input is not attached to a VR environment."); + } } @Override public Vector3f getAngularVelocity(int controllerIndex) { - int index = OpenVRInput.controllerIndex[controllerIndex]; - if( needsNewAngVelocity[index] ) { - OpenVR.hmdTrackedDevicePoses[index].readField("vAngularVelocity"); - needsNewAngVelocity[index] = false; - } - tempVel.x = OpenVR.hmdTrackedDevicePoses[index].vAngularVelocity.v[0]; - tempVel.y = OpenVR.hmdTrackedDevicePoses[index].vAngularVelocity.v[1]; - tempVel.z = OpenVR.hmdTrackedDevicePoses[index].vAngularVelocity.v[2]; - return tempVel; + + if (environment != null){ + + if (environment.getVRHardware() instanceof OpenVR){ + + int index = OpenVRInput.controllerIndex[controllerIndex]; + if( needsNewAngVelocity[index] ) { + ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].readField("vAngularVelocity"); + needsNewAngVelocity[index] = false; + } + tempVel.x = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vAngularVelocity.v[0]; + tempVel.y = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vAngularVelocity.v[1]; + tempVel.z = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vAngularVelocity.v[2]; + return tempVel; + } else { + throw new IllegalStateException("VR hardware "+environment.getVRHardware().getClass().getSimpleName()+" is not a subclass of "+OpenVR.class.getSimpleName()); + } + } else { + throw new IllegalStateException("VR input is not attached to a VR environment."); + } + } @Override @@ -309,7 +332,16 @@ public class OpenVRInput implements VRInputAPI { return false; } - return OpenVR.hmdTrackedDevicePoses[controllerIndex[index]].bPoseIsValid != 0; + if (environment != null){ + + if (environment.getVRHardware() instanceof OpenVR){ + return ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[controllerIndex[index]].bPoseIsValid != 0; + } else { + throw new IllegalStateException("VR hardware "+environment.getVRHardware().getClass().getSimpleName()+" is not a subclass of "+OpenVR.class.getSimpleName()); + } + } else { + throw new IllegalStateException("VR input is not attached to a VR environment."); + } } @Override @@ -317,9 +349,19 @@ public class OpenVRInput implements VRInputAPI { if( isInputDeviceTracking(index) == false ){ return null; } - index = controllerIndex[index]; - VRUtil.convertMatrix4toQuat(OpenVR.poseMatrices[index], rotStore[index]); - return rotStore[index]; + + if (environment != null){ + + if (environment.getVRHardware() instanceof OpenVR){ + index = controllerIndex[index]; + VRUtil.convertMatrix4toQuat(((OpenVR)environment.getVRHardware()).poseMatrices[index], rotStore[index]); + return rotStore[index]; + } else { + throw new IllegalStateException("VR hardware "+environment.getVRHardware().getClass().getSimpleName()+" is not a subclass of "+OpenVR.class.getSimpleName()); + } + } else { + throw new IllegalStateException("VR input is not attached to a VR environment."); + } } @Override @@ -328,12 +370,23 @@ public class OpenVRInput implements VRInputAPI { return null; } - // the hmdPose comes in rotated funny, fix that here - index = controllerIndex[index]; - OpenVR.poseMatrices[index].toTranslationVector(posStore[index]); - posStore[index].x = -posStore[index].x; - posStore[index].z = -posStore[index].z; - return posStore[index]; + if (environment != null){ + + if (environment.getVRHardware() instanceof OpenVR){ + // the hmdPose comes in rotated funny, fix that here + index = controllerIndex[index]; + ((OpenVR)environment.getVRHardware()).poseMatrices[index].toTranslationVector(posStore[index]); + posStore[index].x = -posStore[index].x; + posStore[index].z = -posStore[index].z; + return posStore[index]; + } else { + throw new IllegalStateException("VR hardware "+environment.getVRHardware().getClass().getSimpleName()+" is not a subclass of "+OpenVR.class.getSimpleName()); + } + } else { + throw new IllegalStateException("VR input is not attached to a VR environment."); + } + + } @Override @@ -424,6 +477,12 @@ public class OpenVRInput implements VRInputAPI { controllerIndex[controllerCount] = i; + // Adding tracked controller to control. + if (trackedControllers == null){ + trackedControllers = new ArrayList(JOpenVRLibrary.k_unMaxTrackedDeviceCount); + } + trackedControllers.add(new OpenVRTrackedController(i, this, controllerName, manufacturerName, environment)); + // Send an Haptic pulse to the controller triggerHapticPulse(controllerCount, 1.0f); diff --git a/jme3-vr/src/main/java/com/jme3/input/vr/OpenVRTrackedController.java b/jme3-vr/src/main/java/com/jme3/input/vr/OpenVRTrackedController.java new file mode 100644 index 000000000..026830604 --- /dev/null +++ b/jme3-vr/src/main/java/com/jme3/input/vr/OpenVRTrackedController.java @@ -0,0 +1,93 @@ +package com.jme3.input.vr; + +import com.jme3.app.VREnvironment; +import com.jme3.math.Matrix4f; +import com.jme3.math.Quaternion; +import com.jme3.math.Vector3f; + +public class OpenVRTrackedController implements VRTrackedController{ + + /** + * The index of the controller within the unserlying VR API. + */ + private int controllerIndex = -1; + + /** + * The underlying VRAPI. + */ + private OpenVRInput hardware = null; + + /** + * The name of the controller. + */ + private String name; + + private VREnvironment environment; + + /** + * Wrap a new VR tracked controller on an OpenVR system. + * @param controllerIndex the index of the controller within the underlying VR system. + * @param hardware the underlying VR system. + * @param name the name of the controller. + * @param manufacturer the manufacturer of the controller. + * @param environment the VR environment. + */ + public OpenVRTrackedController(int controllerIndex, OpenVRInput hardware, String name, String manufacturer, VREnvironment environment){ + this.controllerIndex = controllerIndex; + this.hardware = hardware; + + this.name = name; + this.manufacturer = manufacturer; + + this.environment = environment; + } + + /** + * The manufacturer of the controller. + */ + private String manufacturer; + + @Override + public Vector3f getPosition() { + if (hardware != null){ + return hardware.getPosition(controllerIndex); + } else { + throw new IllegalStateException("No underlying VR API."); + } + } + + @Override + public Quaternion getOrientation() { + if (hardware != null){ + return hardware.getOrientation(controllerIndex); + } else { + throw new IllegalStateException("No underlying VR API."); + } + } + + @Override + public Matrix4f getPose(){ + + if (environment != null){ + if (hardware != null){ + return ((OpenVR)environment.getVRHardware()).poseMatrices[controllerIndex]; + } else { + throw new IllegalStateException("No underlying VR API."); + } + } else { + throw new IllegalStateException("VR tracked device is not attached to any environment."); + } + + + } + + @Override + public String getControllerName() { + return name; + } + + @Override + public String getControllerManufacturer() { + return manufacturer; + } +} diff --git a/jme3-vr/src/main/java/com/jme3/input/vr/VRBounds.java b/jme3-vr/src/main/java/com/jme3/input/vr/VRBounds.java index 15ce659ea..0f81b4105 100644 --- a/jme3-vr/src/main/java/com/jme3/input/vr/VRBounds.java +++ b/jme3-vr/src/main/java/com/jme3/input/vr/VRBounds.java @@ -16,19 +16,19 @@ public class VRBounds { private static Logger logger = Logger.getLogger(VRBounds.class.getName()); - private static VR_IVRChaperone_FnTable vrChaperone; - private static Vector2f playSize; + private VR_IVRChaperone_FnTable vrChaperone; + private Vector2f playSize; /** * Initialize the VR bounds. * @return true if the initialization is a success and false otherwise. */ - public static boolean init() { + public boolean init(OpenVR api) { logger.config("Initialize VR bounds..."); if( vrChaperone == null ) { - vrChaperone = new VR_IVRChaperone_FnTable(JOpenVRLibrary.VR_GetGenericInterface(JOpenVRLibrary.IVRChaperone_Version, OpenVR.hmdErrorStore).getPointer()); + vrChaperone = new VR_IVRChaperone_FnTable(JOpenVRLibrary.VR_GetGenericInterface(JOpenVRLibrary.IVRChaperone_Version, api.hmdErrorStore).getPointer()); if( vrChaperone != null ) { vrChaperone.setAutoSynch(false); vrChaperone.read(); @@ -53,7 +53,7 @@ public class VRBounds { * Get the size of the VR world. * @return the size of the VR world. */ - public static Vector2f getPlaySize() { + public Vector2f getPlaySize() { return playSize; } diff --git a/jme3-vr/src/main/java/com/jme3/input/vr/VRTrackedController.java b/jme3-vr/src/main/java/com/jme3/input/vr/VRTrackedController.java index 5fb2572a0..3ce20e5c0 100644 --- a/jme3-vr/src/main/java/com/jme3/input/vr/VRTrackedController.java +++ b/jme3-vr/src/main/java/com/jme3/input/vr/VRTrackedController.java @@ -1,5 +1,9 @@ package com.jme3.input.vr; +import com.jme3.math.Matrix4f; +import com.jme3.math.Quaternion; +import com.jme3.math.Vector3f; + /** * TODO * @author Julien Seinturier - (c) 2016 - JOrigin project - http:/www.jorigin.org @@ -7,4 +11,40 @@ package com.jme3.input.vr; */ public interface VRTrackedController { + /** + * Get the controller name. + * @return the controller name. + */ + public String getControllerName(); + + /** + * Get the controller manufacturer. + * @return the controller manufacturer. + */ + public String getControllerManufacturer(); + + /** + * Get the position of the tracked device. This value is the translation component of the device {@link #getPose() pose}. + * @return the position of the tracked device. + * @see #getOrientation() + * @see #getPose() + */ + public Vector3f getPosition(); + + /** + * Get the orientation of the tracked device. This value is the rotation component of the device {@link #getPose() pose}. + * @return the orientation of the tracked device. + * @see #getPosition() + * @see #getPose() + */ + public Quaternion getOrientation(); + + /** + * Get the pose of the tracked device. + * The pose is a 4x4 matrix than combine the {@link #getPosition() position} and the {@link #getOrientation() orientation} of the device. + * @return the pose of the tracked device. + * @see #getPosition() + * @see #getOrientation() + */ + public Matrix4f getPose(); } diff --git a/jme3-vr/src/main/java/com/jme3/util/AbstractVRViewManager.java b/jme3-vr/src/main/java/com/jme3/util/AbstractVRViewManager.java index 7a9b5ea56..f4f7e7f91 100644 --- a/jme3-vr/src/main/java/com/jme3/util/AbstractVRViewManager.java +++ b/jme3-vr/src/main/java/com/jme3/util/AbstractVRViewManager.java @@ -28,18 +28,20 @@ public abstract class AbstractVRViewManager implements VRViewManager { protected VREnvironment environment = null; protected Camera leftCamera; - protected ViewPort leftViewport; + protected ViewPort leftViewPort; protected FilterPostProcessor leftPostProcessor; protected Texture2D leftEyeTexture; protected Texture2D leftEyeDepth; protected Camera rightCamera; - protected ViewPort rightViewport; + protected ViewPort rightViewPort; protected FilterPostProcessor rightPostProcessor; protected Texture2D rightEyeTexture; protected Texture2D rightEyeDepth; - private float resMult = 1f; + protected ViewPort mirrorViewPort; + + private float resMult = 1f; private float heightAdjustment; @@ -54,15 +56,24 @@ public abstract class AbstractVRViewManager implements VRViewManager { } @Override - public ViewPort getLeftViewport() { - return leftViewport; + public ViewPort getLeftViewPort() { + return leftViewPort; } @Override - public ViewPort getRightViewport() { - return rightViewport; + public ViewPort getRightViewPort() { + return rightViewPort; } + /** + * Get the {@link ViewPort view port} attached to the mirror display. + * @return the view port attached to the mirror display. + */ + public ViewPort getMirrorViewPort() { + return mirrorViewPort; + } + + @Override public Texture2D getLeftTexture(){ return leftEyeTexture; @@ -124,7 +135,7 @@ public abstract class AbstractVRViewManager implements VRViewManager { public void moveScreenProcessingToEyes() { if (environment != null){ - if( getRightViewport() == null ){ + if( getRightViewPort() == null ){ return; } @@ -150,7 +161,7 @@ public abstract class AbstractVRViewManager implements VRViewManager { public void syncScreenProcessing(ViewPort sourceViewport) { if (environment != null){ - if( getRightViewport() == null ){ + if( getRightViewPort() == null ){ return; } @@ -163,13 +174,13 @@ public abstract class AbstractVRViewManager implements VRViewManager { // clear out all filters & processors, to start from scratch getRightPostProcessor().removeAllFilters(); getLeftPostProcessor().removeAllFilters(); - getLeftViewport().clearProcessors(); - getRightViewport().clearProcessors(); + getLeftViewPort().clearProcessors(); + getRightViewPort().clearProcessors(); // if we have no processors to sync, don't add the FilterPostProcessor if( sourceViewport.getProcessors().isEmpty() ) return; // add post processors we just made, which are empty - getLeftViewport().addProcessor(getLeftPostProcessor()); - getRightViewport().addProcessor(getRightPostProcessor()); + getLeftViewPort().addProcessor(getLeftPostProcessor()); + getRightViewPort().addProcessor(getRightPostProcessor()); // go through all of the filters in the processors list // add them to the left viewport processor & clone them to the right for(SceneProcessor sceneProcessor : sourceViewport.getProcessors()) { @@ -202,8 +213,8 @@ public abstract class AbstractVRViewManager implements VRViewManager { VRDirectionalLightShadowRenderer dlsr = (VRDirectionalLightShadowRenderer) sceneProcessor; VRDirectionalLightShadowRenderer dlsrRight = dlsr.clone(); dlsrRight.setLight(dlsr.getLight()); - getRightViewport().getProcessors().add(0, dlsrRight); - getLeftViewport().getProcessors().add(0, sceneProcessor); + getRightViewPort().getProcessors().add(0, dlsrRight); + getLeftViewPort().getProcessors().add(0, sceneProcessor); } } // make sure each has a translucent filter renderer diff --git a/jme3-vr/src/main/java/com/jme3/util/VRViewManager.java b/jme3-vr/src/main/java/com/jme3/util/VRViewManager.java index e2c503006..58a6c166e 100644 --- a/jme3-vr/src/main/java/com/jme3/util/VRViewManager.java +++ b/jme3-vr/src/main/java/com/jme3/util/VRViewManager.java @@ -42,17 +42,25 @@ public interface VRViewManager { /** * Get the {@link ViewPort viewport} attached to the left eye. * @return the {@link ViewPort viewport} attached to the left eye. - * @see #getRightViewport() + * @see #getRightViewPort() */ - public ViewPort getLeftViewport(); + public ViewPort getLeftViewPort(); /** * Get the {@link ViewPort viewport} attached to the right eye. * @return the {@link ViewPort viewport} attached to the right eye. - * @see #getLeftViewport() + * @see #getLeftViewPort() */ - public ViewPort getRightViewport(); + public ViewPort getRightViewPort(); + + /** + * Get the {@link ViewPort view port} attached to the mirror display. + * @return the view port attached to the mirror display. + * @see #getLeftViewPort() + * @see #getRightViewPort() + */ + public ViewPort getMirrorViewPort(); /** * Get the texture attached to the left eye. diff --git a/jme3-vr/src/main/java/com/jme3/util/VRViewManagerOSVR.java b/jme3-vr/src/main/java/com/jme3/util/VRViewManagerOSVR.java index 9b78396e5..e3d85406e 100644 --- a/jme3-vr/src/main/java/com/jme3/util/VRViewManagerOSVR.java +++ b/jme3-vr/src/main/java/com/jme3/util/VRViewManagerOSVR.java @@ -117,18 +117,18 @@ public class VRViewManagerOSVR extends AbstractVRViewManager{ /** * Get the {@link ViewPort viewport} attached to the left eye. * @return the {@link ViewPort viewport} attached to the left eye. - * @see #getRightViewport() + * @see #getRightViewPort() */ - public ViewPort getLeftViewport() { + public ViewPort getLeftViewPort() { return leftViewport; } /** * Get the {@link ViewPort viewport} attached to the right eye. * @return the {@link ViewPort viewport} attached to the right eye. - * @see #getLeftViewport() + * @see #getLeftViewPort() */ - public ViewPort getRightViewport() { + public ViewPort getRightViewPort() { return rightViewport; } diff --git a/jme3-vr/src/main/java/com/jme3/util/VRViewManagerOpenVR.java b/jme3-vr/src/main/java/com/jme3/util/VRViewManagerOpenVR.java index 49d08578b..545754a59 100644 --- a/jme3-vr/src/main/java/com/jme3/util/VRViewManagerOpenVR.java +++ b/jme3-vr/src/main/java/com/jme3/util/VRViewManagerOpenVR.java @@ -7,6 +7,7 @@ package com.jme3.util; import com.jme3.app.VREnvironment; import com.jme3.input.vr.OpenVR; import com.jme3.input.vr.VRAPI; +import com.jme3.input.vr.VRTrackedController; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.Quaternion; @@ -346,10 +347,10 @@ public class VRViewManagerOpenVR extends AbstractVRViewManager { return; } - leftEyeTexture = (Texture2D) getLeftViewport().getOutputFrameBuffer().getColorBuffer().getTexture(); - rightEyeTexture = (Texture2D)getRightViewport().getOutputFrameBuffer().getColorBuffer().getTexture(); - leftEyeDepth = (Texture2D) getLeftViewport().getOutputFrameBuffer().getDepthBuffer().getTexture(); - rightEyeDepth = (Texture2D)getRightViewport().getOutputFrameBuffer().getDepthBuffer().getTexture(); + leftEyeTexture = (Texture2D) getLeftViewPort().getOutputFrameBuffer().getColorBuffer().getTexture(); + rightEyeTexture = (Texture2D)getRightViewPort().getOutputFrameBuffer().getColorBuffer().getTexture(); + leftEyeDepth = (Texture2D) getLeftViewPort().getOutputFrameBuffer().getDepthBuffer().getTexture(); + rightEyeDepth = (Texture2D)getRightViewPort().getOutputFrameBuffer().getDepthBuffer().getTexture(); // main viewport is either going to be a distortion scene or nothing // mirroring is handled by copying framebuffers @@ -387,6 +388,7 @@ public class VRViewManagerOpenVR extends AbstractVRViewManager { if( environment.getApplication().getContext().getSettings().isSwapBuffers() ) { setupMirrorBuffers(environment.getCamera(), leftEyeTexture, false); + } } else { throw new IllegalStateException("This VR environment is not attached to any application."); @@ -414,9 +416,35 @@ public class VRViewManagerOpenVR extends AbstractVRViewManager { // grab the hardware handle VRAPI dev = environment.getVRHardware(); if( dev != null ) { + + // update the HMD's position & orientation dev.updatePose(); dev.getPositionAndOrientation(hmdPos, hmdRot); +/* + // TOREMOVE + Vector3f v = dev.getVRinput().getTrackedController(0).getPosition(); + Quaternion q = dev.getVRinput().getTrackedController(0).getOrientation(); + if ((v != null)&&(q != null)){ + hmdPos.set(v); + hmdRot.set(q); + } + + logger.severe("HMD controller "); + logger.severe(" Position "+hmdPos); + logger.severe(" Orientation "+hmdRot); + + VRTrackedController tc = null; + for(int i = 0; i < dev.getVRinput().getTrackedControllerCount(); i++){ + tc = dev.getVRinput().getTrackedController(i); + logger.severe("Tracked controller "+i+": "+tc.getControllerName()); + logger.severe(" Position "+tc.getPosition()); + logger.severe(" Orientation "+tc.getOrientation()); + logger.severe(""); + } +*/ + // TOREMOVE + if( obs != null ) { // update hmdPos based on obs rotation finalRotation.set(objRot); @@ -490,18 +518,18 @@ public class VRViewManagerOpenVR extends AbstractVRViewManager { //org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_FRAMEBUFFER_SRGB); if( !environment.isInstanceRendering()) { - leftViewport = setupViewBuffers(getLeftCamera(), LEFT_VIEW_NAME); + leftViewPort = setupViewBuffers(getLeftCamera(), LEFT_VIEW_NAME); rightCamera = getLeftCamera().clone(); if( environment.getVRHardware() != null ){ getRightCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(getRightCamera())); } - rightViewport = setupViewBuffers(getRightCamera(), RIGHT_VIEW_NAME); + rightViewPort = setupViewBuffers(getRightCamera(), RIGHT_VIEW_NAME); } else { if (environment.getApplication() != null){ logger.severe("THIS CODE NEED CHANGES !!!"); - leftViewport = environment.getApplication().getViewPort(); + leftViewPort = environment.getApplication().getViewPort(); //leftViewport.attachScene(app.getRootNode()); rightCamera = getLeftCamera().clone(); if( environment.getVRHardware() != null ){ @@ -520,7 +548,7 @@ public class VRViewManagerOpenVR extends AbstractVRViewManager { } // setup gui - environment.getVRGUIManager().setupGui(getLeftCamera(), getRightCamera(), getLeftViewport(), getRightViewport()); + environment.getVRGUIManager().setupGui(getLeftCamera(), getRightCamera(), getLeftViewPort(), getRightViewPort()); if( environment.getVRHardware() != null ) { // call these to cache the results internally