VR controller clean integration

fix-456
seint 8 years ago
parent 6cf1b57e00
commit 651e77953a
  1. 12
      jme3-vr/src/main/java/com/jme3/app/VRAppState.java
  2. 10
      jme3-vr/src/main/java/com/jme3/app/VRApplication.java
  3. 14
      jme3-vr/src/main/java/com/jme3/app/VREnvironment.java
  4. 37
      jme3-vr/src/main/java/com/jme3/input/vr/OpenVR.java
  5. 81
      jme3-vr/src/main/java/com/jme3/input/vr/OpenVRInput.java
  6. 93
      jme3-vr/src/main/java/com/jme3/input/vr/OpenVRTrackedController.java
  7. 10
      jme3-vr/src/main/java/com/jme3/input/vr/VRBounds.java
  8. 40
      jme3-vr/src/main/java/com/jme3/input/vr/VRTrackedController.java
  9. 39
      jme3-vr/src/main/java/com/jme3/util/AbstractVRViewManager.java
  10. 16
      jme3-vr/src/main/java/com/jme3/util/VRViewManager.java
  11. 8
      jme3-vr/src/main/java/com/jme3/util/VRViewManagerOSVR.java
  12. 44
      jme3-vr/src/main/java/com/jme3/util/VRViewManagerOpenVR.java

@ -241,7 +241,7 @@ public class VRAppState extends AbstractAppState {
return application.getViewPort(); return application.getViewPort();
} }
return environment.getVRViewManager().getLeftViewport(); return environment.getVRViewManager().getLeftViewPort();
} }
/** /**
@ -253,7 +253,7 @@ public class VRAppState extends AbstractAppState {
if( environment.getVRViewManager() == null ){ if( environment.getVRViewManager() == null ){
return application.getViewPort(); 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) { public void setBackgroundColors(ColorRGBA clr) {
if( environment.getVRViewManager() == null ) { if( environment.getVRViewManager() == null ) {
application.getViewPort().setBackgroundColor(clr); 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 ){ if( environment.getVRViewManager().getRightViewPort() != null ){
environment.getVRViewManager().getRightViewport().setBackgroundColor(clr); environment.getVRViewManager().getRightViewPort().setBackgroundColor(clr);
} }
} }
} }

@ -1085,7 +1085,7 @@ public abstract class VRApplication implements Application, SystemListener {
*/ */
public ViewPort getLeftViewPort() { public ViewPort getLeftViewPort() {
if( viewmanager == null ) return getViewPort(); 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() { public ViewPort getRightViewPort() {
if( viewmanager == null ) return getViewPort(); 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) { public void setBackgroundColors(ColorRGBA clr) {
if( viewmanager == null ) { if( viewmanager == null ) {
getViewPort().setBackgroundColor(clr); getViewPort().setBackgroundColor(clr);
} else if( viewmanager.getLeftViewport() != null ) { } else if( viewmanager.getLeftViewPort() != null ) {
viewmanager.getLeftViewport().setBackgroundColor(clr); viewmanager.getLeftViewPort().setBackgroundColor(clr);
if( viewmanager.getRightViewport() != null ) viewmanager.getRightViewport().setBackgroundColor(clr); if( viewmanager.getRightViewPort() != null ) viewmanager.getRightViewPort().setBackgroundColor(clr);
} }
} }

@ -8,6 +8,7 @@ import com.jme3.app.state.AppState;
import com.jme3.input.vr.OSVR; import com.jme3.input.vr.OSVR;
import com.jme3.input.vr.OpenVR; import com.jme3.input.vr.OpenVR;
import com.jme3.input.vr.VRAPI; import com.jme3.input.vr.VRAPI;
import com.jme3.input.vr.VRBounds;
import com.jme3.input.vr.VRInputAPI; import com.jme3.input.vr.VRInputAPI;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
@ -27,6 +28,8 @@ public class VREnvironment {
private VRGuiManager guiManager = null; private VRGuiManager guiManager = null;
private VRMouseManager mouseManager = null; private VRMouseManager mouseManager = null;
private VRViewManager viewmanager = null; private VRViewManager viewmanager = null;
private VRBounds bounds = null;
/** /**
* The underlying system VR API. By default set to {@link VRConstants#SETTING_VRAPI_OPENVR_VALUE}. * 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); guiManager = new VRGuiManager(this);
mouseManager = new VRMouseManager(this); mouseManager = new VRMouseManager(this);
bounds = new VRBounds();
dummyCam = new Camera(); dummyCam = new Camera();
processSettings(); processSettings();
@ -86,6 +92,14 @@ public class VREnvironment {
return hardware; return hardware;
} }
/**
* Get the VR bounds.
* @return the VR bounds.
*/
public VRBounds getVRBounds(){
return bounds;
}
/** /**
* Get the VR dedicated input. * Get the VR dedicated input.
* @return the VR dedicated input. * @return the VR dedicated input.

@ -46,14 +46,14 @@ public class OpenVR implements VRAPI {
private static boolean initSuccess = false; private static boolean initSuccess = false;
private static boolean flipEyes = false; private static boolean flipEyes = false;
private static IntBuffer hmdDisplayFrequency; private IntBuffer hmdDisplayFrequency;
private static TrackedDevicePose_t.ByReference hmdTrackedDevicePoseReference; private TrackedDevicePose_t.ByReference hmdTrackedDevicePoseReference;
protected static TrackedDevicePose_t[] hmdTrackedDevicePoses; protected TrackedDevicePose_t[] hmdTrackedDevicePoses;
protected static IntByReference hmdErrorStore; protected IntByReference hmdErrorStore;
private static final Quaternion rotStore = new Quaternion(); private final Quaternion rotStore = new Quaternion();
private static final Vector3f posStore = new Vector3f(); private final Vector3f posStore = new Vector3f();
private static FloatByReference tlastVsync; private static FloatByReference tlastVsync;
@ -65,20 +65,21 @@ public class OpenVR implements VRAPI {
// for debugging latency // for debugging latency
private int frames = 0; private int frames = 0;
protected static Matrix4f[] poseMatrices; protected Matrix4f[] poseMatrices;
private static final Matrix4f hmdPose = Matrix4f.IDENTITY.clone(); private final Matrix4f hmdPose = Matrix4f.IDENTITY.clone();
private static Matrix4f hmdProjectionLeftEye; private Matrix4f hmdProjectionLeftEye;
private static Matrix4f hmdProjectionRightEye; private Matrix4f hmdProjectionRightEye;
private static Matrix4f hmdPoseLeftEye; private Matrix4f hmdPoseLeftEye;
private static Matrix4f hmdPoseRightEye; 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; private VREnvironment environment = null;
@ -181,7 +182,7 @@ public class OpenVR implements VRAPI {
VRinput.updateConnectedControllers(); VRinput.updateConnectedControllers();
// init bounds & chaperone info // init bounds & chaperone info
VRBounds.init(); environment.getVRBounds().init(this);
logger.config("Initializing OpenVR system [SUCCESS]"); logger.config("Initializing OpenVR system [SUCCESS]");
initSuccess = true; initSuccess = true;

@ -5,6 +5,7 @@
*/ */
package com.jme3.input.vr; package com.jme3.input.vr;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -183,28 +184,50 @@ public class OpenVRInput implements VRInputAPI {
@Override @Override
public Vector3f getVelocity(int controllerIndex) { public Vector3f getVelocity(int controllerIndex) {
if (environment != null){
if (environment.getVRHardware() instanceof OpenVR){
int index = OpenVRInput.controllerIndex[controllerIndex]; int index = OpenVRInput.controllerIndex[controllerIndex];
if( needsNewVelocity[index] ) { if( needsNewVelocity[index] ) {
OpenVR.hmdTrackedDevicePoses[index].readField("vVelocity"); ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].readField("vVelocity");
needsNewVelocity[index] = false; needsNewVelocity[index] = false;
} }
tempVel.x = OpenVR.hmdTrackedDevicePoses[index].vVelocity.v[0]; tempVel.x = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vVelocity.v[0];
tempVel.y = OpenVR.hmdTrackedDevicePoses[index].vVelocity.v[1]; tempVel.y = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vVelocity.v[1];
tempVel.z = OpenVR.hmdTrackedDevicePoses[index].vVelocity.v[2]; tempVel.z = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vVelocity.v[2];
return tempVel; 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 @Override
public Vector3f getAngularVelocity(int controllerIndex) { public Vector3f getAngularVelocity(int controllerIndex) {
if (environment != null){
if (environment.getVRHardware() instanceof OpenVR){
int index = OpenVRInput.controllerIndex[controllerIndex]; int index = OpenVRInput.controllerIndex[controllerIndex];
if( needsNewAngVelocity[index] ) { if( needsNewAngVelocity[index] ) {
OpenVR.hmdTrackedDevicePoses[index].readField("vAngularVelocity"); ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].readField("vAngularVelocity");
needsNewAngVelocity[index] = false; needsNewAngVelocity[index] = false;
} }
tempVel.x = OpenVR.hmdTrackedDevicePoses[index].vAngularVelocity.v[0]; tempVel.x = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vAngularVelocity.v[0];
tempVel.y = OpenVR.hmdTrackedDevicePoses[index].vAngularVelocity.v[1]; tempVel.y = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vAngularVelocity.v[1];
tempVel.z = OpenVR.hmdTrackedDevicePoses[index].vAngularVelocity.v[2]; tempVel.z = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vAngularVelocity.v[2];
return tempVel; 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 @Override
@ -309,7 +332,16 @@ public class OpenVRInput implements VRInputAPI {
return false; 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 @Override
@ -317,9 +349,19 @@ public class OpenVRInput implements VRInputAPI {
if( isInputDeviceTracking(index) == false ){ if( isInputDeviceTracking(index) == false ){
return null; return null;
} }
if (environment != null){
if (environment.getVRHardware() instanceof OpenVR){
index = controllerIndex[index]; index = controllerIndex[index];
VRUtil.convertMatrix4toQuat(OpenVR.poseMatrices[index], rotStore[index]); VRUtil.convertMatrix4toQuat(((OpenVR)environment.getVRHardware()).poseMatrices[index], rotStore[index]);
return 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 @Override
@ -328,12 +370,23 @@ public class OpenVRInput implements VRInputAPI {
return null; return null;
} }
if (environment != null){
if (environment.getVRHardware() instanceof OpenVR){
// the hmdPose comes in rotated funny, fix that here // the hmdPose comes in rotated funny, fix that here
index = controllerIndex[index]; index = controllerIndex[index];
OpenVR.poseMatrices[index].toTranslationVector(posStore[index]); ((OpenVR)environment.getVRHardware()).poseMatrices[index].toTranslationVector(posStore[index]);
posStore[index].x = -posStore[index].x; posStore[index].x = -posStore[index].x;
posStore[index].z = -posStore[index].z; posStore[index].z = -posStore[index].z;
return posStore[index]; 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 @Override
@ -424,6 +477,12 @@ public class OpenVRInput implements VRInputAPI {
controllerIndex[controllerCount] = i; controllerIndex[controllerCount] = i;
// Adding tracked controller to control.
if (trackedControllers == null){
trackedControllers = new ArrayList<VRTrackedController>(JOpenVRLibrary.k_unMaxTrackedDeviceCount);
}
trackedControllers.add(new OpenVRTrackedController(i, this, controllerName, manufacturerName, environment));
// Send an Haptic pulse to the controller // Send an Haptic pulse to the controller
triggerHapticPulse(controllerCount, 1.0f); triggerHapticPulse(controllerCount, 1.0f);

@ -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;
}
}

@ -16,19 +16,19 @@ public class VRBounds {
private static Logger logger = Logger.getLogger(VRBounds.class.getName()); private static Logger logger = Logger.getLogger(VRBounds.class.getName());
private static VR_IVRChaperone_FnTable vrChaperone; private VR_IVRChaperone_FnTable vrChaperone;
private static Vector2f playSize; private Vector2f playSize;
/** /**
* Initialize the VR bounds. * Initialize the VR bounds.
* @return <code>true</code> if the initialization is a success and <code>false</code> otherwise. * @return <code>true</code> if the initialization is a success and <code>false</code> otherwise.
*/ */
public static boolean init() { public boolean init(OpenVR api) {
logger.config("Initialize VR bounds..."); logger.config("Initialize VR bounds...");
if( vrChaperone == null ) { 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 ) { if( vrChaperone != null ) {
vrChaperone.setAutoSynch(false); vrChaperone.setAutoSynch(false);
vrChaperone.read(); vrChaperone.read();
@ -53,7 +53,7 @@ public class VRBounds {
* Get the size of the VR world. * Get the size of the VR world.
* @return the size of the VR world. * @return the size of the VR world.
*/ */
public static Vector2f getPlaySize() { public Vector2f getPlaySize() {
return playSize; return playSize;
} }

@ -1,5 +1,9 @@
package com.jme3.input.vr; package com.jme3.input.vr;
import com.jme3.math.Matrix4f;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
/** /**
* TODO * TODO
* @author Julien Seinturier - (c) 2016 - JOrigin project - <a href="http://www.jorigin.org">http:/www.jorigin.org</a> * @author Julien Seinturier - (c) 2016 - JOrigin project - <a href="http://www.jorigin.org">http:/www.jorigin.org</a>
@ -7,4 +11,40 @@ package com.jme3.input.vr;
*/ */
public interface VRTrackedController { 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();
} }

@ -28,17 +28,19 @@ public abstract class AbstractVRViewManager implements VRViewManager {
protected VREnvironment environment = null; protected VREnvironment environment = null;
protected Camera leftCamera; protected Camera leftCamera;
protected ViewPort leftViewport; protected ViewPort leftViewPort;
protected FilterPostProcessor leftPostProcessor; protected FilterPostProcessor leftPostProcessor;
protected Texture2D leftEyeTexture; protected Texture2D leftEyeTexture;
protected Texture2D leftEyeDepth; protected Texture2D leftEyeDepth;
protected Camera rightCamera; protected Camera rightCamera;
protected ViewPort rightViewport; protected ViewPort rightViewPort;
protected FilterPostProcessor rightPostProcessor; protected FilterPostProcessor rightPostProcessor;
protected Texture2D rightEyeTexture; protected Texture2D rightEyeTexture;
protected Texture2D rightEyeDepth; protected Texture2D rightEyeDepth;
protected ViewPort mirrorViewPort;
private float resMult = 1f; private float resMult = 1f;
private float heightAdjustment; private float heightAdjustment;
@ -54,15 +56,24 @@ public abstract class AbstractVRViewManager implements VRViewManager {
} }
@Override @Override
public ViewPort getLeftViewport() { public ViewPort getLeftViewPort() {
return leftViewport; return leftViewPort;
} }
@Override @Override
public ViewPort getRightViewport() { public ViewPort getRightViewPort() {
return rightViewport; 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 @Override
public Texture2D getLeftTexture(){ public Texture2D getLeftTexture(){
return leftEyeTexture; return leftEyeTexture;
@ -124,7 +135,7 @@ public abstract class AbstractVRViewManager implements VRViewManager {
public void moveScreenProcessingToEyes() { public void moveScreenProcessingToEyes() {
if (environment != null){ if (environment != null){
if( getRightViewport() == null ){ if( getRightViewPort() == null ){
return; return;
} }
@ -150,7 +161,7 @@ public abstract class AbstractVRViewManager implements VRViewManager {
public void syncScreenProcessing(ViewPort sourceViewport) { public void syncScreenProcessing(ViewPort sourceViewport) {
if (environment != null){ if (environment != null){
if( getRightViewport() == null ){ if( getRightViewPort() == null ){
return; return;
} }
@ -163,13 +174,13 @@ public abstract class AbstractVRViewManager implements VRViewManager {
// clear out all filters & processors, to start from scratch // clear out all filters & processors, to start from scratch
getRightPostProcessor().removeAllFilters(); getRightPostProcessor().removeAllFilters();
getLeftPostProcessor().removeAllFilters(); getLeftPostProcessor().removeAllFilters();
getLeftViewport().clearProcessors(); getLeftViewPort().clearProcessors();
getRightViewport().clearProcessors(); getRightViewPort().clearProcessors();
// if we have no processors to sync, don't add the FilterPostProcessor // if we have no processors to sync, don't add the FilterPostProcessor
if( sourceViewport.getProcessors().isEmpty() ) return; if( sourceViewport.getProcessors().isEmpty() ) return;
// add post processors we just made, which are empty // add post processors we just made, which are empty
getLeftViewport().addProcessor(getLeftPostProcessor()); getLeftViewPort().addProcessor(getLeftPostProcessor());
getRightViewport().addProcessor(getRightPostProcessor()); getRightViewPort().addProcessor(getRightPostProcessor());
// go through all of the filters in the processors list // go through all of the filters in the processors list
// add them to the left viewport processor & clone them to the right // add them to the left viewport processor & clone them to the right
for(SceneProcessor sceneProcessor : sourceViewport.getProcessors()) { for(SceneProcessor sceneProcessor : sourceViewport.getProcessors()) {
@ -202,8 +213,8 @@ public abstract class AbstractVRViewManager implements VRViewManager {
VRDirectionalLightShadowRenderer dlsr = (VRDirectionalLightShadowRenderer) sceneProcessor; VRDirectionalLightShadowRenderer dlsr = (VRDirectionalLightShadowRenderer) sceneProcessor;
VRDirectionalLightShadowRenderer dlsrRight = dlsr.clone(); VRDirectionalLightShadowRenderer dlsrRight = dlsr.clone();
dlsrRight.setLight(dlsr.getLight()); dlsrRight.setLight(dlsr.getLight());
getRightViewport().getProcessors().add(0, dlsrRight); getRightViewPort().getProcessors().add(0, dlsrRight);
getLeftViewport().getProcessors().add(0, sceneProcessor); getLeftViewPort().getProcessors().add(0, sceneProcessor);
} }
} }
// make sure each has a translucent filter renderer // make sure each has a translucent filter renderer

@ -42,17 +42,25 @@ public interface VRViewManager {
/** /**
* Get the {@link ViewPort viewport} attached to the left eye. * Get the {@link ViewPort viewport} attached to the left eye.
* @return 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. * Get the {@link ViewPort viewport} attached to the right eye.
* @return 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. * Get the texture attached to the left eye.

@ -117,18 +117,18 @@ public class VRViewManagerOSVR extends AbstractVRViewManager{
/** /**
* Get the {@link ViewPort viewport} attached to the left eye. * Get the {@link ViewPort viewport} attached to the left eye.
* @return 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; return leftViewport;
} }
/** /**
* Get the {@link ViewPort viewport} attached to the right eye. * Get the {@link ViewPort viewport} attached to the right eye.
* @return 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; return rightViewport;
} }

@ -7,6 +7,7 @@ package com.jme3.util;
import com.jme3.app.VREnvironment; import com.jme3.app.VREnvironment;
import com.jme3.input.vr.OpenVR; import com.jme3.input.vr.OpenVR;
import com.jme3.input.vr.VRAPI; import com.jme3.input.vr.VRAPI;
import com.jme3.input.vr.VRTrackedController;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
@ -346,10 +347,10 @@ public class VRViewManagerOpenVR extends AbstractVRViewManager {
return; return;
} }
leftEyeTexture = (Texture2D) getLeftViewport().getOutputFrameBuffer().getColorBuffer().getTexture(); leftEyeTexture = (Texture2D) getLeftViewPort().getOutputFrameBuffer().getColorBuffer().getTexture();
rightEyeTexture = (Texture2D)getRightViewport().getOutputFrameBuffer().getColorBuffer().getTexture(); rightEyeTexture = (Texture2D)getRightViewPort().getOutputFrameBuffer().getColorBuffer().getTexture();
leftEyeDepth = (Texture2D) getLeftViewport().getOutputFrameBuffer().getDepthBuffer().getTexture(); leftEyeDepth = (Texture2D) getLeftViewPort().getOutputFrameBuffer().getDepthBuffer().getTexture();
rightEyeDepth = (Texture2D)getRightViewport().getOutputFrameBuffer().getDepthBuffer().getTexture(); rightEyeDepth = (Texture2D)getRightViewPort().getOutputFrameBuffer().getDepthBuffer().getTexture();
// main viewport is either going to be a distortion scene or nothing // main viewport is either going to be a distortion scene or nothing
// mirroring is handled by copying framebuffers // mirroring is handled by copying framebuffers
@ -387,6 +388,7 @@ public class VRViewManagerOpenVR extends AbstractVRViewManager {
if( environment.getApplication().getContext().getSettings().isSwapBuffers() ) { if( environment.getApplication().getContext().getSettings().isSwapBuffers() ) {
setupMirrorBuffers(environment.getCamera(), leftEyeTexture, false); setupMirrorBuffers(environment.getCamera(), leftEyeTexture, false);
} }
} else { } else {
throw new IllegalStateException("This VR environment is not attached to any application."); 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 // grab the hardware handle
VRAPI dev = environment.getVRHardware(); VRAPI dev = environment.getVRHardware();
if( dev != null ) { if( dev != null ) {
// update the HMD's position & orientation // update the HMD's position & orientation
dev.updatePose(); dev.updatePose();
dev.getPositionAndOrientation(hmdPos, hmdRot); 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 ) { if( obs != null ) {
// update hmdPos based on obs rotation // update hmdPos based on obs rotation
finalRotation.set(objRot); finalRotation.set(objRot);
@ -490,18 +518,18 @@ public class VRViewManagerOpenVR extends AbstractVRViewManager {
//org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_FRAMEBUFFER_SRGB); //org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_FRAMEBUFFER_SRGB);
if( !environment.isInstanceRendering()) { if( !environment.isInstanceRendering()) {
leftViewport = setupViewBuffers(getLeftCamera(), LEFT_VIEW_NAME); leftViewPort = setupViewBuffers(getLeftCamera(), LEFT_VIEW_NAME);
rightCamera = getLeftCamera().clone(); rightCamera = getLeftCamera().clone();
if( environment.getVRHardware() != null ){ if( environment.getVRHardware() != null ){
getRightCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(getRightCamera())); getRightCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(getRightCamera()));
} }
rightViewport = setupViewBuffers(getRightCamera(), RIGHT_VIEW_NAME); rightViewPort = setupViewBuffers(getRightCamera(), RIGHT_VIEW_NAME);
} else { } else {
if (environment.getApplication() != null){ if (environment.getApplication() != null){
logger.severe("THIS CODE NEED CHANGES !!!"); logger.severe("THIS CODE NEED CHANGES !!!");
leftViewport = environment.getApplication().getViewPort(); leftViewPort = environment.getApplication().getViewPort();
//leftViewport.attachScene(app.getRootNode()); //leftViewport.attachScene(app.getRootNode());
rightCamera = getLeftCamera().clone(); rightCamera = getLeftCamera().clone();
if( environment.getVRHardware() != null ){ if( environment.getVRHardware() != null ){
@ -520,7 +548,7 @@ public class VRViewManagerOpenVR extends AbstractVRViewManager {
} }
// setup gui // setup gui
environment.getVRGUIManager().setupGui(getLeftCamera(), getRightCamera(), getLeftViewport(), getRightViewport()); environment.getVRGUIManager().setupGui(getLeftCamera(), getRightCamera(), getLeftViewPort(), getRightViewPort());
if( environment.getVRHardware() != null ) { if( environment.getVRHardware() != null ) {
// call these to cache the results internally // call these to cache the results internally

Loading…
Cancel
Save