Static lonks removal & OpenVR refactoring

Removing static call between classes
Refactoring OpenVR system package
fix-456
Julien Seinturier 8 years ago
parent 825b1baccb
commit 3520273dce
  1. 400
      jme3-vr/src/main/java/com/jme3/app/VRApplication.java
  2. 1
      jme3-vr/src/main/java/com/jme3/input/lwjgl/GlfwMouseInputVR.java
  3. 24
      jme3-vr/src/main/java/com/jme3/input/vr/OSVR.java
  4. 34
      jme3-vr/src/main/java/com/jme3/input/vr/OSVRInput.java
  5. 45
      jme3-vr/src/main/java/com/jme3/input/vr/OpenVR.java
  6. 70
      jme3-vr/src/main/java/com/jme3/input/vr/OpenVRInput.java
  7. 7
      jme3-vr/src/main/java/com/jme3/input/vr/VRAPI.java
  8. 5
      jme3-vr/src/main/java/com/jme3/input/vr/VRBounds.java
  9. 7
      jme3-vr/src/main/java/com/jme3/input/vr/VRInputAPI.java
  10. 22
      jme3-vr/src/main/java/com/jme3/post/CartoonSSAO.java
  11. 18
      jme3-vr/src/main/java/com/jme3/post/OpenVRFilter.java
  12. 8
      jme3-vr/src/main/java/com/jme3/post/PreNormalCaching.java
  13. 18
      jme3-vr/src/main/java/com/jme3/shadow/InstancedDirectionalShadowFilter.java
  14. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/AppOverrideKeys_t.java
  15. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/COpenVRContext.java
  16. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/CameraVideoStreamFrameHeader_t.java
  17. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/Compositor_CumulativeStats.java
  18. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/Compositor_FrameTiming.java
  19. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/Compositor_OverlaySettings.java
  20. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/DistortionCoordinates_t.java
  21. 6
      jme3-vr/src/main/java/com/jme3/system/jopenvr/HiddenAreaMesh_t.java
  22. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/HmdColor_t.java
  23. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/HmdMatrix34_t.java
  24. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/HmdMatrix44_t.java
  25. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/HmdQuad_t.java
  26. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/HmdQuaternion_t.java
  27. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/HmdRect2_t.java
  28. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/HmdVector2_t.java
  29. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/HmdVector3_t.java
  30. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/HmdVector3d_t.java
  31. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/HmdVector4_t.java
  32. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/JOpenVRLibrary.java
  33. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/NotificationBitmap_t.java
  34. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/RenderModel_ComponentState_t.java
  35. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/RenderModel_ControllerMode_State_t.java
  36. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/RenderModel_TextureMap_t.java
  37. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/RenderModel_Vertex_t.java
  38. 6
      jme3-vr/src/main/java/com/jme3/system/jopenvr/RenderModel_t.java
  39. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/Texture_t.java
  40. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/TrackedDevicePose_t.java
  41. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VRControllerAxis_t.java
  42. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VRControllerState_t.java
  43. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_ApplicationLaunch_t.java
  44. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_Chaperone_t.java
  45. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_Controller_t.java
  46. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_Data_t.java
  47. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_Ipd_t.java
  48. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_Keyboard_t.java
  49. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_Mouse_t.java
  50. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_Notification_t.java
  51. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_Overlay_t.java
  52. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_PerformanceTest_t.java
  53. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_Process_t.java
  54. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_Reserved_t.java
  55. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_ScreenshotProgress_t.java
  56. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_Screenshot_t.java
  57. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_Scroll_t.java
  58. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_SeatedZeroPoseReset_t.java
  59. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_Status_t.java
  60. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_TouchPadMove_t.java
  61. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VREvent_t.java
  62. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VROverlayIntersectionParams_t.java
  63. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VROverlayIntersectionResults_t.java
  64. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VRTextureBounds_t.java
  65. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VR_IVRApplications_FnTable.java
  66. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VR_IVRChaperoneSetup_FnTable.java
  67. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VR_IVRChaperone_FnTable.java
  68. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VR_IVRCompositor_FnTable.java
  69. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VR_IVRExtendedDisplay_FnTable.java
  70. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VR_IVRNotifications_FnTable.java
  71. 4
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VR_IVROverlay_FnTable.java
  72. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VR_IVRRenderModels_FnTable.java
  73. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VR_IVRResources_FnTable.java
  74. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VR_IVRScreenshots_FnTable.java
  75. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VR_IVRSettings_FnTable.java
  76. 10
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VR_IVRSystem_FnTable.java
  77. 2
      jme3-vr/src/main/java/com/jme3/system/jopenvr/VR_IVRTrackedCamera_FnTable.java
  78. 5
      jme3-vr/src/main/java/com/jme3/system/lwjgl/LwjglContextVR.java
  79. 3
      jme3-vr/src/main/java/com/jme3/system/lwjgl/LwjglWindowVR.java
  80. 13
      jme3-vr/src/main/java/jmevr/util/MeshUtil.java
  81. 128
      jme3-vr/src/main/java/jmevr/util/VRGuiManager.java
  82. 133
      jme3-vr/src/main/java/jmevr/util/VRMouseManager.java
  83. 5
      jme3-vr/src/main/java/jmevr/util/VRUtil.java
  84. 113
      jme3-vr/src/main/java/jmevr/util/VRViewManager.java
  85. 0
      jme3-vr/src/main/resources/Common/Util/gui_mesh.j3o
  86. 0
      jme3-vr/src/main/resources/Common/Util/gui_mesh.j3odata
  87. 0
      jme3-vr/src/main/resources/Common/Util/mouse.png

@ -38,6 +38,7 @@ import com.jme3.scene.Spatial.CullHint;
import com.jme3.system.AppSettings; import com.jme3.system.AppSettings;
import com.jme3.system.JmeContext; import com.jme3.system.JmeContext;
import com.jme3.system.JmeContext.Type; import com.jme3.system.JmeContext.Type;
import com.jme3.system.jopenvr.JOpenVRLibrary;
import com.jme3.system.JmeSystem; import com.jme3.system.JmeSystem;
import com.jme3.system.NanoTimer; import com.jme3.system.NanoTimer;
import com.jme3.system.SystemListener; import com.jme3.system.SystemListener;
@ -62,13 +63,13 @@ import java.util.logging.Logger;
import jmevr.util.VRViewManager; import jmevr.util.VRViewManager;
import jmevr.util.VRGuiManager; import jmevr.util.VRGuiManager;
import jmevr.util.VRGuiManager.POSITIONING_MODE; import jmevr.util.VRGuiManager.POSITIONING_MODE;
import jopenvr.JOpenVRLibrary; import jmevr.util.VRMouseManager;
import org.lwjgl.system.Platform; import org.lwjgl.system.Platform;
/** /**
* A JMonkey application dedicated to Virtual Reality. An application that use VR devices (HTC vive, ...) has to extends this one. * A JMonkey application dedicated to Virtual Reality. An application that use VR devices (HTC vive, ...) has to extends this one.<br>
* @author reden - phr00t - https://github.com/phr00t * @author reden - phr00t - https://github.com/phr00t
* @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>
*/ */
@ -80,23 +81,23 @@ public abstract class VRApplication implements Application, SystemListener {
/** /**
* The default FOV. * The default FOV.
*/ */
public static float DEFAULT_FOV = 108f; public float DEFAULT_FOV = 108f;
/** /**
* The default aspect ratio. * The default aspect ratio.
*/ */
public static float DEFAULT_ASPECT = 1f; public float DEFAULT_ASPECT = 1f;
/** /**
* Is the application is based on OSVR (default is <code>false</code>). * Is the application is based on OSVR (default is <code>false</code>).
*/ */
public static boolean CONSTRUCT_WITH_OSVR = false; public boolean CONSTRUCT_WITH_OSVR = false;
/** /**
* Is the application has not to start within VR mode (default is <code>false</code>). * Is the application has not to start within VR mode (default is <code>false</code>).
*/ */
public static boolean DISABLE_VR = false; public boolean DISABLE_VR = false;
/** /**
* VR application configuration parameters. * VR application configuration parameters.
@ -166,13 +167,23 @@ public abstract class VRApplication implements Application, SystemListener {
FORCE_DISABLE_MSAA FORCE_DISABLE_MSAA
} }
private static String OS; private VRAPI VRhardware = null;
private static VRAPI VRhardware; private VRGuiManager guiManager = null;
private static Camera dummyCam; private VRMouseManager mouseManager = null;
private static VRViewManager VRviewmanager; private VRViewManager viewmanager = null;
private static VRApplication mainApp;
private static Spatial observer; private String OS;
private static boolean VRSupportedOS, forceVR, disableSwapBuffers = true, tryOpenGL3 = true, seated, nogui, instanceVR, forceDisableMSAA;
private Camera dummyCam;
private Spatial observer;
private boolean VRSupportedOS;
private boolean forceVR;
private boolean disableSwapBuffers = true;
private boolean tryOpenGL3 = true;
private boolean seated;
private boolean nogui;
private boolean instanceVR;
private boolean forceDisableMSAA;
// things taken from LegacyApplication // things taken from LegacyApplication
private AppStateManager stateManager; private AppStateManager stateManager;
@ -202,29 +213,119 @@ public abstract class VRApplication implements Application, SystemListener {
private float fFar = 1000f, fNear = 1f; private float fFar = 1000f, fNear = 1f;
private int xWin = 1280, yWin = 720; private int xWin = 1280, yWin = 720;
//private static float distanceOfOptimization = 0f; private float resMult = 1f;
private static float resMult = 1f;
private static boolean useCompositor = true, compositorOS; private boolean useCompositor = true, compositorOS;
private final String RESET_HMD = "ResetHMD"; private final String RESET_HMD = "ResetHMD";
// no longer using LwjglCanvas, and this sometimes broke the graphics settings /**
/*static { * Create a new VR application and attach the given {@link AppState app states}.<br>
if( VR_IsHmdPresent() != 0 ) { * The application scene is made of a {@link #getRootNode() root node} that holds the scene spatials
System.setProperty("sun.java2d.opengl", "True"); * and a {@link #getGuiNode() GUI node} that is the root of the Graphical user interface.
* @param initialStates the {@link AppState app states} to attach to the application.
*/
public VRApplication(AppState... initialStates) {
this();
if (initialStates != null) {
for (AppState a : initialStates) {
if (a != null) {
stateManager.attach(a);
}
}
}
} }
} */
/** /**
* Get the distance of optimization. * Create a new VR application.<br>
* @return the distance of optimization. * The application scene is made of a {@link #getRootNode() root node} that holds the scene spatials
* and a {@link #getGuiNode() GUI node} that is the root of the Graphical user interface.
*/ */
/* public VRApplication() {
public static float getOptimizationDistance() { super();
return distanceOfOptimization;
rootNode = new Node("root");
guiNode = new Node("guiNode");
guiNode.setQueueBucket(Bucket.Gui);
guiNode.setCullHint(CullHint.Never);
dummyCam = new Camera();
initStateManager();
// Create the GUI manager.
guiManager = new VRGuiManager(this);
// Create a new view manager.
viewmanager = new VRViewManager(this);
// Create a new mouse manager.
mouseManager = new VRMouseManager(this);
// we are going to use OpenVR now, not the Oculus Rift
// OpenVR does support the Rift
OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
VRSupportedOS = !OS.contains("nux") && System.getProperty("sun.arch.data.model").equalsIgnoreCase("64"); //for the moment, linux/unix causes crashes, 64-bit only
compositorOS = OS.contains("indows");
if( !VRSupportedOS ) {
logger.warning("Non-supported OS: " + OS + ", architecture: " + System.getProperty("sun.arch.data.model"));
} else if( DISABLE_VR ) {
logger.warning("VR disabled via code.");
} else if( VRSupportedOS && DISABLE_VR == false ) {
if( CONSTRUCT_WITH_OSVR ) {
logger.config("Initializing OSVR...");
VRhardware = new OSVR(this);
} else {
logger.config("Initializing OpenVR...");
VRhardware = new OpenVR(this);
}
if( VRhardware.initialize() ) {
setPauseOnLostFocus(false);
}
}
}
/**
* Get the VR underlying hardware.
* @return the VR underlying hardware.
*/
public VRAPI getVRHardware() {
return VRhardware;
}
/**
* Get the VR dedicated input.
* @return the VR dedicated input.
*/
public VRInputAPI getVRinput() {
if( VRhardware == null ) return null;
return VRhardware.getVRinput();
}
/**
* Get the VR view manager.
* @return the VR view manager.
*/
public VRViewManager getVRViewManager() {
return viewmanager;
}
/**
* Get the GUI manager attached to this application.
* @return the GUI manager attached to this application.
*/
public VRGuiManager getVRGUIManager(){
return guiManager;
} }
/**
* Get the VR mouse manager attached to this application.
* @return the VR mouse manager attached to this application.
*/ */
public VRMouseManager getVRMouseManager(){
return mouseManager;
}
/** /**
* Set the frustrum values for the application. * Set the frustrum values for the application.
@ -252,7 +353,7 @@ public abstract class VRApplication implements Application, SystemListener {
*/ */
public void setResolutionMultiplier(float val) { public void setResolutionMultiplier(float val) {
resMult = val; resMult = val;
if( VRviewmanager != null ) VRviewmanager.setResolutionMultiplier(resMult); if( viewmanager != null ) viewmanager.setResolutionMultiplier(resMult);
} }
@ -260,7 +361,7 @@ public abstract class VRApplication implements Application, SystemListener {
* Is the SteamVR compositor is active. * Is the SteamVR compositor is active.
* @return <code>true</code> if the SteamVR compositor is active and <code>false</code> otherwise. * @return <code>true</code> if the SteamVR compositor is active and <code>false</code> otherwise.
*/ */
public static boolean compositorAllowed() { public boolean compositorAllowed() {
return useCompositor && compositorOS; return useCompositor && compositorOS;
} }
@ -268,7 +369,7 @@ public abstract class VRApplication implements Application, SystemListener {
* Get if the system currently support VR. * Get if the system currently support VR.
* @return <code>true</code> if the system currently support VR and <code>false</Code> otherwise. * @return <code>true</code> if the system currently support VR and <code>false</Code> otherwise.
*/ */
public static boolean isOSVRSupported() { public boolean isOSVRSupported() {
return VRSupportedOS; return VRSupportedOS;
} }
@ -284,67 +385,9 @@ public abstract class VRApplication implements Application, SystemListener {
* @param renderManager the {@link RenderManager render manager}. * @param renderManager the {@link RenderManager render manager}.
*/ */
public void simpleRender(RenderManager renderManager) { public void simpleRender(RenderManager renderManager) {
PreNormalCaching.resetCache(); PreNormalCaching.resetCache(isInVR());
}
/**
* Create a new VR application and attach the given {@link AppState app states}.
* @param initialStates the {@link AppState app states} to attach to the application.
*/
public VRApplication(AppState... initialStates) {
this();
if (initialStates != null) {
for (AppState a : initialStates) {
if (a != null) {
stateManager.attach(a);
}
}
} }
}
/**
* Create a new VR application.
*/
public VRApplication() {
super();
initStateManager();
rootNode = new Node("root");
guiNode = new Node("guiNode");
guiNode.setQueueBucket(Bucket.Gui);
guiNode.setCullHint(CullHint.Never);
dummyCam = new Camera();
mainApp = this;
// we are going to use OpenVR now, not the Oculus Rift
// OpenVR does support the Rift
OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
VRSupportedOS = !OS.contains("nux") && System.getProperty("sun.arch.data.model").equalsIgnoreCase("64"); //for the moment, linux/unix causes crashes, 64-bit only
compositorOS = OS.contains("indows");
if( !VRSupportedOS ) {
logger.warning("Non-supported OS: " + OS + ", architecture: " + System.getProperty("sun.arch.data.model"));
} else if( DISABLE_VR ) {
logger.warning("VR disabled via code.");
} else if( VRSupportedOS && DISABLE_VR == false ) {
if( CONSTRUCT_WITH_OSVR ) {
logger.config("Initializing OSVR...");
VRhardware = new OSVR();
} else {
logger.config("Initializing OpenVR...");
VRhardware = new OpenVR();
}
if( VRhardware.initialize() ) {
setPauseOnLostFocus(false);
}
}
}
/* /*
we do NOT want to get & modify the distortion scene camera, so we do NOT want to get & modify the distortion scene camera, so
@ -352,7 +395,7 @@ public abstract class VRApplication implements Application, SystemListener {
*/ */
@Override @Override
public Camera getCamera() { public Camera getCamera() {
if( isInVR() && VRviewmanager != null && VRviewmanager.getCamLeft() != null ) { if( isInVR() && viewmanager != null && viewmanager.getCamLeft() != null ) {
return dummyCam; return dummyCam;
} }
return cam; return cam;
@ -763,10 +806,10 @@ public abstract class VRApplication implements Application, SystemListener {
public void preconfigureVRApp(PreconfigParameter parm, boolean value) { public void preconfigureVRApp(PreconfigParameter parm, boolean value) {
switch( parm ) { switch( parm ) {
case SET_GUI_OVERDRAW: case SET_GUI_OVERDRAW:
VRGuiManager._enableGuiOverdraw(value); guiManager._enableGuiOverdraw(value);
break; break;
case SET_GUI_CURVED_SURFACE: case SET_GUI_CURVED_SURFACE:
VRGuiManager._enableCurvedSuface(value); guiManager._enableCurvedSuface(value);
break; break;
case FORCE_VR_MODE: case FORCE_VR_MODE:
forceVR = value; forceVR = value;
@ -775,7 +818,7 @@ public abstract class VRApplication implements Application, SystemListener {
// VRViewManager._setCustomDistortion(value); // VRViewManager._setCustomDistortion(value);
// break; // break;
case USE_VR_COMPOSITOR: case USE_VR_COMPOSITOR:
VRApplication.useCompositor = value; useCompositor = value;
if( value == false ) disableSwapBuffers = false; if( value == false ) disableSwapBuffers = false;
break; break;
case FLIP_EYES: case FLIP_EYES:
@ -786,7 +829,7 @@ public abstract class VRApplication implements Application, SystemListener {
instanceVR = value; instanceVR = value;
break; break;
case ENABLE_MIRROR_WINDOW: case ENABLE_MIRROR_WINDOW:
if( VRApplication.useCompositor == false ) { if( useCompositor == false ) {
disableSwapBuffers = false; disableSwapBuffers = false;
} else disableSwapBuffers = !value; } else disableSwapBuffers = !value;
break; break;
@ -813,7 +856,7 @@ public abstract class VRApplication implements Application, SystemListener {
* @param isSeated <code>true</code> if designed for sitting, <code>false</code> for standing/roomscale * @param isSeated <code>true</code> if designed for sitting, <code>false</code> for standing/roomscale
* @see #isSeatedExperience() * @see #isSeatedExperience()
*/ */
public static void setSeatedExperience(boolean isSeated) { public void setSeatedExperience(boolean isSeated) {
seated = isSeated; seated = isSeated;
if( VRhardware instanceof OpenVR ) { if( VRhardware instanceof OpenVR ) {
if( VRhardware.getCompositor() == null ) return; if( VRhardware.getCompositor() == null ) return;
@ -830,32 +873,23 @@ public abstract class VRApplication implements Application, SystemListener {
* @return <code>true</code> if the application is configured as a seated experience and <code>false</code> otherwise. * @return <code>true</code> if the application is configured as a seated experience and <code>false</code> otherwise.
* @see #setSeatedExperience(boolean) * @see #setSeatedExperience(boolean)
*/ */
public static boolean isSeatedExperience() { public boolean isSeatedExperience() {
return seated; return seated;
} }
/** /**
* Reset headset pose if seating experience. * Reset headset pose if seating experience.
*/ */
public static void resetSeatedPose(){ public void resetSeatedPose(){
if( VRSupportedOS == false || isSeatedExperience() == false ) return; if( VRSupportedOS == false || isSeatedExperience() == false ) return;
VRhardware.reset(); VRhardware.reset();
} }
/**
* Get the VR dedicated input.
* @return the VR dedicated input.
*/
public static VRInputAPI getVRinput() {
if( VRhardware == null ) return null;
return VRhardware.getVRinput();
}
/** /**
* Check if the rendering is instanced (see <a href="https://en.wikipedia.org/wiki/Geometry_instancing">Geometry instancing</a>). * Check if the rendering is instanced (see <a href="https://en.wikipedia.org/wiki/Geometry_instancing">Geometry instancing</a>).
* @return <code>true</code> if the rendering is instanced and <code>false</code> otherwise. * @return <code>true</code> if the rendering is instanced and <code>false</code> otherwise.
*/ */
public static boolean isInstanceVRRendering() { public boolean isInstanceVRRendering() {
return instanceVR && isInVR(); return instanceVR && isInVR();
} }
@ -863,7 +897,7 @@ public abstract class VRApplication implements Application, SystemListener {
* Check if the VR mode is enabled. * Check if the VR mode is enabled.
* @return <code>true</code> if the VR mode is enabled and <code>false</code> otherwise. * @return <code>true</code> if the VR mode is enabled and <code>false</code> otherwise.
*/ */
public static boolean isInVR() { public boolean isInVR() {
return DISABLE_VR == false && (forceVR || VRSupportedOS && VRhardware != null && VRhardware.isInitialized()); return DISABLE_VR == false && (forceVR || VRSupportedOS && VRhardware != null && VRhardware.isInitialized());
} }
@ -871,20 +905,12 @@ public abstract class VRApplication implements Application, SystemListener {
* Move filters from the main scene into the eye's. * Move filters from the main scene into the eye's.
* This removes filters from the main scene. * This removes filters from the main scene.
*/ */
public static void moveScreenProcessingToVR() { public void moveScreenProcessingToVR() {
if( isInVR() ) { if( isInVR() ) {
VRviewmanager.moveScreenProcessingToEyes(); viewmanager.moveScreenProcessingToEyes();
} }
} }
/**
* Get the VR underlying hardware.
* @return the VR underlying hardware.
*/
public static VRAPI getVRHardware() {
return VRhardware;
}
/** /**
* Get the GUI node from the application. * Get the GUI node from the application.
* @return the GUI node from the application. * @return the GUI node from the application.
@ -905,7 +931,7 @@ public abstract class VRApplication implements Application, SystemListener {
* Check if the application has a GUI overlay attached. * Check if the application has a GUI overlay attached.
* @return <code>true</code> if the application has a GUI overlay attached and <code>false</code> otherwise. * @return <code>true</code> if the application has a GUI overlay attached and <code>false</code> otherwise.
*/ */
public static boolean hasTraditionalGUIOverlay() { public boolean hasTraditionalGUIOverlay() {
return !nogui; return !nogui;
} }
@ -915,9 +941,9 @@ public abstract class VRApplication implements Application, SystemListener {
* @return the scene observer. * @return the scene observer.
* @see #setObserver(Spatial) * @see #setObserver(Spatial)
*/ */
public static Object getObserver() { public Object getObserver() {
if( observer == null ) { if( observer == null ) {
return mainApp.getCamera(); return getCamera();
} }
return observer; return observer;
} }
@ -926,16 +952,8 @@ public abstract class VRApplication implements Application, SystemListener {
* Set the scene observer. The VR headset will be linked to it. If no observer is set, the VR headset is linked to the the application {@link #getCamera() camera}. * Set the scene observer. The VR headset will be linked to it. If no observer is set, the VR headset is linked to the the application {@link #getCamera() camera}.
* @param observer the scene observer. * @param observer the scene observer.
*/ */
public static void setObserver(Spatial observer) { public void setObserver(Spatial observer) {
VRApplication.observer = observer; this.observer = observer;
}
/**
* Get the VR view manager.
* @return the VR view manager.
*/
public static VRViewManager getVRViewManager() {
return VRviewmanager;
} }
/* /*
@ -949,16 +967,16 @@ public abstract class VRApplication implements Application, SystemListener {
* @return the observer final rotation within the scene. * @return the observer final rotation within the scene.
* @see #getFinalObserverPosition() * @see #getFinalObserverPosition()
*/ */
public static Quaternion getFinalObserverRotation() { public Quaternion getFinalObserverRotation() {
if( VRviewmanager == null ) { if( viewmanager == null ) {
if( VRApplication.observer == null ) { if( observer == null ) {
return mainApp.getCamera().getRotation(); return getCamera().getRotation();
} else return VRApplication.observer.getWorldRotation(); } else return observer.getWorldRotation();
} }
if( VRApplication.observer == null ) { if( observer == null ) {
tempq.set(dummyCam.getRotation()); tempq.set(dummyCam.getRotation());
} else { } else {
tempq.set(VRApplication.observer.getWorldRotation()); tempq.set(observer.getWorldRotation());
} }
return tempq.multLocal(VRhardware.getOrientation()); return tempq.multLocal(VRhardware.getOrientation());
} }
@ -968,19 +986,19 @@ public abstract class VRApplication implements Application, SystemListener {
* @return the observer position. * @return the observer position.
* @see #getFinalObserverRotation() * @see #getFinalObserverRotation()
*/ */
public static Vector3f getFinalObserverPosition() { public Vector3f getFinalObserverPosition() {
if( VRviewmanager == null ) { if( viewmanager == null ) {
if( VRApplication.observer == null ) { if( observer == null ) {
return mainApp.getCamera().getLocation(); return getCamera().getLocation();
} else return VRApplication.observer.getWorldTranslation(); } else return observer.getWorldTranslation();
} }
Vector3f pos = VRhardware.getPosition(); Vector3f pos = VRhardware.getPosition();
if( VRApplication.observer == null ) { if( observer == null ) {
dummyCam.getRotation().mult(pos, pos); dummyCam.getRotation().mult(pos, pos);
return pos.addLocal(dummyCam.getLocation()); return pos.addLocal(dummyCam.getLocation());
} else { } else {
VRApplication.observer.getWorldRotation().mult(pos, pos); observer.getWorldRotation().mult(pos, pos);
return pos.addLocal(VRApplication.observer.getWorldTranslation()); return pos.addLocal(observer.getWorldTranslation());
} }
} }
@ -989,8 +1007,8 @@ public abstract class VRApplication implements Application, SystemListener {
* @param amount the VR headset height from the ground. * @param amount the VR headset height from the ground.
* @see #getVRHeightAdjustment() * @see #getVRHeightAdjustment()
*/ */
public static void setVRHeightAdjustment(float amount) { public void setVRHeightAdjustment(float amount) {
if( VRviewmanager != null ) VRviewmanager.setHeightAdjustment(amount); if( viewmanager != null ) viewmanager.setHeightAdjustment(amount);
} }
/** /**
@ -998,8 +1016,8 @@ public abstract class VRApplication implements Application, SystemListener {
* @return the VR headset height from the ground. * @return the VR headset height from the ground.
* @see #setVRHeightAdjustment(float) * @see #setVRHeightAdjustment(float)
*/ */
public static float getVRHeightAdjustment() { public float getVRHeightAdjustment() {
if( VRviewmanager != null ) return VRviewmanager.getHeightAdjustment(); if( viewmanager != null ) return viewmanager.getHeightAdjustment();
return 0f; return 0f;
} }
@ -1008,9 +1026,9 @@ public abstract class VRApplication implements Application, SystemListener {
* @return the VR headset left viewport. * @return the VR headset left viewport.
* @see #getRightViewPort() * @see #getRightViewPort()
*/ */
public static ViewPort getLeftViewPort() { public ViewPort getLeftViewPort() {
if( VRviewmanager == null ) return mainApp.getViewPort(); if( viewmanager == null ) return getViewPort();
return VRviewmanager.getViewPortLeft(); return viewmanager.getViewPortLeft();
} }
/** /**
@ -1018,9 +1036,9 @@ public abstract class VRApplication implements Application, SystemListener {
* @return the VR headset right viewport. * @return the VR headset right viewport.
* @see #getLeftViewPort() * @see #getLeftViewPort()
*/ */
public static ViewPort getRightViewPort() { public ViewPort getRightViewPort() {
if( VRviewmanager == null ) return mainApp.getViewPort(); if( viewmanager == null ) return getViewPort();
return VRviewmanager.getViewPortRight(); return viewmanager.getViewPortRight();
} }
@ -1028,22 +1046,15 @@ public abstract class VRApplication implements Application, SystemListener {
* Set the background color for both left and right view ports. * Set the background color for both left and right view ports.
* @param clr the background color. * @param clr the background color.
*/ */
public static void setBackgroundColors(ColorRGBA clr) { public void setBackgroundColors(ColorRGBA clr) {
if( VRviewmanager == null ) { if( viewmanager == null ) {
mainApp.getViewPort().setBackgroundColor(clr); getViewPort().setBackgroundColor(clr);
} else if( VRviewmanager.getViewPortLeft() != null ) { } else if( viewmanager.getViewPortLeft() != null ) {
VRviewmanager.getViewPortLeft().setBackgroundColor(clr); viewmanager.getViewPortLeft().setBackgroundColor(clr);
if( VRviewmanager.getViewPortRight() != null ) VRviewmanager.getViewPortRight().setBackgroundColor(clr); if( viewmanager.getViewPortRight() != null ) viewmanager.getViewPortRight().setBackgroundColor(clr);
} }
} }
/**
* Get the instance of VR application that is currently running.
* @return the instance of VR application that is currently running.
*/
public static VRApplication getMainVRApp() {
return mainApp;
}
/** /**
* Runs tasks enqueued via {@link #enqueue(Callable)} * Runs tasks enqueued via {@link #enqueue(Callable)}
@ -1094,34 +1105,36 @@ public abstract class VRApplication implements Application, SystemListener {
// simple update and root node // simple update and root node
simpleUpdate(tpf); simpleUpdate(tpf);
// render states
stateManager.render(renderManager);
// update VR pose & cameras
if( viewmanager != null ) {
viewmanager.update(tpf);
} else if( observer != null ) {
getCamera().setFrame(observer.getWorldTranslation(), observer.getWorldRotation());
}
// Updates scene and gui states.
rootNode.updateLogicalState(tpf); rootNode.updateLogicalState(tpf);
guiNode.updateLogicalState(tpf); guiNode.updateLogicalState(tpf);
rootNode.updateGeometricState(); rootNode.updateGeometricState();
if( VRApplication.isInVR() == false || VRGuiManager.getPositioningMode() == POSITIONING_MODE.MANUAL ) { if( isInVR() == false || guiManager.getPositioningMode() == POSITIONING_MODE.MANUAL ) {
// only update geometric state here if GUI is in manual mode, or not in VR // only update geometric state here if GUI is in manual mode, or not in VR
// it will get updated automatically in the viewmanager update otherwise // it will get updated automatically in the viewmanager update otherwise
guiNode.updateGeometricState(); guiNode.updateGeometricState();
} }
// render states
stateManager.render(renderManager);
// update VR pose & cameras
if( VRviewmanager != null ) {
VRviewmanager.update(tpf);
} else if( VRApplication.observer != null ) {
getCamera().setFrame(VRApplication.observer.getWorldTranslation(), VRApplication.observer.getWorldRotation());
}
renderManager.render(tpf, context.isRenderable()); renderManager.render(tpf, context.isRenderable());
simpleRender(renderManager); simpleRender(renderManager);
stateManager.postRender(); stateManager.postRender();
// update compositor? // update compositor?
if( VRviewmanager != null ) { if( viewmanager != null ) {
VRviewmanager.sendTextures(); viewmanager.sendTextures();
} }
} }
@ -1270,6 +1283,9 @@ public abstract class VRApplication implements Application, SystemListener {
@Override @Override
public void initialize() { public void initialize() {
logger.config("Initialize VR application.");
initialize_internal(); initialize_internal();
cam.setFrustumFar(fFar); cam.setFrustumFar(fFar);
cam.setFrustumNear(fNear); cam.setFrustumNear(fNear);
@ -1278,8 +1294,8 @@ public abstract class VRApplication implements Application, SystemListener {
if( VRhardware != null ) { if( VRhardware != null ) {
VRhardware.initVRCompositor(compositorAllowed()); VRhardware.initVRCompositor(compositorAllowed());
} }
VRviewmanager = new VRViewManager(this); viewmanager = new VRViewManager(this);
VRviewmanager.setResolutionMultiplier(resMult); viewmanager.setResolutionMultiplier(resMult);
inputManager.addMapping(RESET_HMD, new KeyTrigger(KeyInput.KEY_F9)); inputManager.addMapping(RESET_HMD, new KeyTrigger(KeyInput.KEY_F9));
setLostFocusBehavior(LostFocusBehavior.Disabled); setLostFocusBehavior(LostFocusBehavior.Disabled);
} else { } else {
@ -1287,25 +1303,25 @@ public abstract class VRApplication implements Application, SystemListener {
guiViewPort.attachScene(guiNode); guiViewPort.attachScene(guiNode);
} }
if( VRviewmanager != null ) { if( viewmanager != null ) {
VRviewmanager.initialize(this); viewmanager.initialize();
} }
simpleInitApp(); simpleInitApp();
// any filters created, move them now // any filters created, move them now
if( VRviewmanager != null ) { if( viewmanager != null ) {
VRviewmanager.moveScreenProcessingToEyes(); viewmanager.moveScreenProcessingToEyes();
// print out camera information // print out camera information
if( isInVR() ) { if( isInVR() ) {
logger.info("VR Initialization Information"); logger.info("VR Initialization Information");
if( VRviewmanager.getCamLeft() != null ){ if( viewmanager.getCamLeft() != null ){
logger.info("camLeft: " + VRviewmanager.getCamLeft().toString()); logger.info("camLeft: " + viewmanager.getCamLeft().toString());
} }
if( VRviewmanager.getCamRight() != null ){ if( viewmanager.getCamRight() != null ){
logger.info("camRight: " + VRviewmanager.getCamRight().toString()); logger.info("camRight: " + viewmanager.getCamRight().toString());
} }
} }
} }

@ -242,7 +242,6 @@ public class GlfwMouseInputVR implements MouseInput {
return; return;
} }
//FIXME: Needs LWJGL 3.1.0
cursorPosCallback.free(); cursorPosCallback.free();
scrollCallback.free(); scrollCallback.free();
mouseButtonCallback.free(); mouseButtonCallback.free();

@ -9,6 +9,7 @@ https://github.com/sensics/OSVR-RenderManager/blob/master/examples/RenderManager
*/ */
package com.jme3.input.vr; package com.jme3.input.vr;
import com.jme3.app.VRApplication;
import com.jme3.math.Matrix4f; import com.jme3.math.Matrix4f;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
@ -19,6 +20,7 @@ import com.ochafik.lang.jnaerator.runtime.NativeSizeByReference;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.ptr.PointerByReference; import com.sun.jna.ptr.PointerByReference;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import java.util.logging.Logger;
import osvrclientkit.OsvrClientKitLibrary; import osvrclientkit.OsvrClientKitLibrary;
import osvrdisplay.OsvrDisplayLibrary; import osvrdisplay.OsvrDisplayLibrary;
@ -39,6 +41,8 @@ import osvrrendermanageropengl.OsvrRenderManagerOpenGLLibrary;
*/ */
public class OSVR implements VRAPI { public class OSVR implements VRAPI {
private static final Logger logger = Logger.getLogger(OSVR.class.getName());
/** /**
* The first viewer index. * The first viewer index.
*/ */
@ -106,6 +110,16 @@ public class OSVR implements VRAPI {
boolean initSuccess = false; boolean initSuccess = false;
boolean flipEyes = false; boolean flipEyes = false;
private VRApplication application = null;
/**
* Create a new <a href="http://www.osvr.org/">OSVR</a> system attached to the given application.
* @param application the application to which the input is attached.
*/
public OSVR(VRApplication application){
this.application = application;
}
/** /**
* Access to the underlying OSVR structures. * Access to the underlying OSVR structures.
* @param leftView the left viewport. * @param leftView the left viewport.
@ -130,9 +144,12 @@ public class OSVR implements VRAPI {
@Override @Override
public boolean initialize() { public boolean initialize() {
logger.config("Initialize OSVR system.");
hmdPose.setAutoSynch(false); hmdPose.setAutoSynch(false);
context = OsvrClientKitLibrary.osvrClientInit(defaultJString, 0); context = OsvrClientKitLibrary.osvrClientInit(defaultJString, 0);
VRinput = new OSVRInput(); VRinput = new OSVRInput(application);
initSuccess = context != null && VRinput.init(); initSuccess = context != null && VRinput.init();
if( initSuccess ) { if( initSuccess ) {
PointerByReference grabDisplay = new PointerByReference(); PointerByReference grabDisplay = new PointerByReference();
@ -444,4 +461,9 @@ public class OSVR implements VRAPI {
return HmdType.OSVR; return HmdType.OSVR;
} }
@Override
public VRApplication getApplication() {
return application;
}
} }

@ -5,6 +5,8 @@
*/ */
package com.jme3.input.vr; package com.jme3.input.vr;
import java.util.logging.Logger;
import com.jme3.app.VRApplication; import com.jme3.app.VRApplication;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
@ -32,6 +34,8 @@ import osvrtimevalue.OSVR_TimeValue;
*/ */
public class OSVRInput implements VRInputAPI { public class OSVRInput implements VRInputAPI {
private static final Logger logger = Logger.getLogger(OSVRInput.class.getName());
// position example: https://github.com/OSVR/OSVR-Core/blob/master/examples/clients/TrackerState.c // position example: https://github.com/OSVR/OSVR-Core/blob/master/examples/clients/TrackerState.c
// button example: https://github.com/OSVR/OSVR-Core/blob/master/examples/clients/ButtonCallback.c // button example: https://github.com/OSVR/OSVR-Core/blob/master/examples/clients/ButtonCallback.c
// analog example: https://github.com/OSVR/OSVR-Core/blob/master/examples/clients/AnalogCallback.c // analog example: https://github.com/OSVR/OSVR-Core/blob/master/examples/clients/AnalogCallback.c
@ -59,6 +63,8 @@ public class OSVRInput implements VRInputAPI {
private static final Vector2f lastCallAxis[] = new Vector2f[16]; private static final Vector2f lastCallAxis[] = new Vector2f[16];
private static float axisMultiplier = 1f; private static float axisMultiplier = 1f;
private VRApplication application = null;
/** /**
* Get the system String that identifies a controller. * Get the system String that identifies a controller.
* @param left is the controller is the left one (<code>false</code> if the right controller is needed). * @param left is the controller is the left one (<code>false</code> if the right controller is needed).
@ -82,6 +88,16 @@ public class OSVRInput implements VRInputAPI {
*/ */
public static byte[] rightHand = { '/', 'm', 'e', '/', 'h', 'a', 'n', 'd', 's', '/', 'r', 'i', 'g', 'h', 't', (byte)0 }; public static byte[] rightHand = { '/', 'm', 'e', '/', 'h', 'a', 'n', 'd', 's', '/', 'r', 'i', 'g', 'h', 't', (byte)0 };
/**
* Create a new <a href="http://www.osvr.org/">OSVR</a> input attached to the given application.
* @param application the application to which the input is attached.
*/
public OSVRInput(VRApplication application){
this.application = application;
}
@Override @Override
public boolean isButtonDown(int controllerIndex, VRInputType checkButton) { public boolean isButtonDown(int controllerIndex, VRInputType checkButton) {
return buttonState[controllerIndex][checkButton.getValue()] != 0f; return buttonState[controllerIndex][checkButton.getValue()] != 0f;
@ -150,13 +166,15 @@ public class OSVRInput implements VRInputAPI {
private OSVR_ClientInterface getInterface(byte[] str) { private OSVR_ClientInterface getInterface(byte[] str) {
PointerByReference pbr = new PointerByReference(); PointerByReference pbr = new PointerByReference();
OsvrClientKitLibrary.osvrClientGetInterface((OsvrClientKitLibrary.OSVR_ClientContext)VRApplication.getVRHardware().getVRSystem(), str, pbr); OsvrClientKitLibrary.osvrClientGetInterface((OsvrClientKitLibrary.OSVR_ClientContext)application.getVRHardware().getVRSystem(), str, pbr);
return new OSVR_ClientInterface(pbr.getValue()); return new OSVR_ClientInterface(pbr.getValue());
} }
@Override @Override
public boolean init() { public boolean init() {
logger.config("Initialize OSVR input.");
buttonHandler = new Callback() { buttonHandler = new Callback() {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public void invoke(Pointer userdata, Pointer timeval, OSVR_ButtonReport report) { public void invoke(Pointer userdata, Pointer timeval, OSVR_ButtonReport report) {
@ -284,9 +302,9 @@ public class OSVRInput implements VRInputAPI {
@Override @Override
public Quaternion getFinalObserverRotation(int index) { public Quaternion getFinalObserverRotation(int index) {
VRViewManager vrvm = VRApplication.getVRViewManager(); VRViewManager vrvm = application.getVRViewManager();
if( vrvm == null || isInputDeviceTracking(index) == false ) return null; if( vrvm == null || isInputDeviceTracking(index) == false ) return null;
Object obs = VRApplication.getObserver(); Object obs = application.getObserver();
if( obs instanceof Camera ) { if( obs instanceof Camera ) {
tempq.set(((Camera)obs).getRotation()); tempq.set(((Camera)obs).getRotation());
} else { } else {
@ -297,9 +315,9 @@ public class OSVRInput implements VRInputAPI {
@Override @Override
public Vector3f getFinalObserverPosition(int index) { public Vector3f getFinalObserverPosition(int index) {
VRViewManager vrvm = VRApplication.getVRViewManager(); VRViewManager vrvm = application.getVRViewManager();
if( vrvm == null || isInputDeviceTracking(index) == false ) return null; if( vrvm == null || isInputDeviceTracking(index) == false ) return null;
Object obs = VRApplication.getObserver(); Object obs = application.getObserver();
Vector3f pos = getPosition(index); Vector3f pos = getPosition(index);
if( obs instanceof Camera ) { if( obs instanceof Camera ) {
((Camera)obs).getRotation().mult(pos, pos); ((Camera)obs).getRotation().mult(pos, pos);
@ -330,4 +348,10 @@ public class OSVRInput implements VRInputAPI {
axisMultiplier = set; axisMultiplier = set;
} }
@Override
public VRApplication getApplication() {
return application;
}
} }

@ -11,6 +11,12 @@ import com.jme3.math.Quaternion;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.system.jopenvr.HmdMatrix34_t;
import com.jme3.system.jopenvr.HmdMatrix44_t;
import com.jme3.system.jopenvr.JOpenVRLibrary;
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.sun.jna.Memory; import com.sun.jna.Memory;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
@ -18,14 +24,9 @@ import java.nio.IntBuffer;
import java.nio.LongBuffer; import java.nio.LongBuffer;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import jmevr.util.VRUtil; import jmevr.util.VRUtil;
import jopenvr.HmdMatrix34_t;
import jopenvr.HmdMatrix44_t;
import jopenvr.JOpenVRLibrary;
import jopenvr.TrackedDevicePose_t;
import jopenvr.VR_IVRCompositor_FnTable;
import jopenvr.VR_IVRSystem_FnTable;
/** /**
* A class that wraps an <a href="https://github.com/ValveSoftware/openvr/wiki/API-Documentation">OpenVR</a> system. * A class that wraps an <a href="https://github.com/ValveSoftware/openvr/wiki/API-Documentation">OpenVR</a> system.
@ -34,6 +35,8 @@ import jopenvr.VR_IVRSystem_FnTable;
*/ */
public class OpenVR implements VRAPI { public class OpenVR implements VRAPI {
private static final Logger logger = Logger.getLogger(OpenVR.class.getName());
private static VR_IVRCompositor_FnTable compositorFunctions; private static VR_IVRCompositor_FnTable compositorFunctions;
private static VR_IVRSystem_FnTable vrsystemFunctions; private static VR_IVRSystem_FnTable vrsystemFunctions;
@ -74,6 +77,16 @@ public class OpenVR implements VRAPI {
private static long frameCount; private static long frameCount;
private static OpenVRInput VRinput; private static OpenVRInput VRinput;
private VRApplication application = null;
/**
* Create a new <a href="https://github.com/ValveSoftware/openvr/wiki/API-Documentation">OpenVR</a> system attached to the given application.
* @param application the application to which the input is attached.
*/
public OpenVR(VRApplication application){
this.application = application;
}
@Override @Override
public OpenVRInput getVRinput() { public OpenVRInput getVRinput() {
return VRinput; return VRinput;
@ -116,6 +129,9 @@ public class OpenVR implements VRAPI {
@Override @Override
public boolean initialize() { public boolean initialize() {
logger.config("Initializing OpenVR system.");
hmdErrorStore = IntBuffer.allocate(1); hmdErrorStore = IntBuffer.allocate(1);
vrsystemFunctions = null; vrsystemFunctions = null;
JOpenVRLibrary.VR_InitInternal(hmdErrorStore, JOpenVRLibrary.EVRApplicationType.EVRApplicationType_VRApplication_Scene); JOpenVRLibrary.VR_InitInternal(hmdErrorStore, JOpenVRLibrary.EVRApplicationType.EVRApplicationType_VRApplication_Scene);
@ -155,9 +171,9 @@ public class OpenVR implements VRAPI {
} }
// init controllers for the first time // init controllers for the first time
VRinput = new OpenVRInput(); VRinput = new OpenVRInput(application);
VRinput.init(); VRinput.init();
VRApplication.getVRinput().updateConnectedControllers(); VRinput.updateConnectedControllers();
// init bounds & chaperone info // init bounds & chaperone info
VRBounds.init(); VRBounds.init();
@ -176,7 +192,7 @@ public class OpenVR implements VRAPI {
System.out.println("OpenVR Compositor initialized OK!"); System.out.println("OpenVR Compositor initialized OK!");
compositorFunctions.setAutoSynch(false); compositorFunctions.setAutoSynch(false);
compositorFunctions.read(); compositorFunctions.read();
if( VRApplication.isSeatedExperience() ) { if( application.isSeatedExperience() ) {
compositorFunctions.SetTrackingSpace.apply(JOpenVRLibrary.ETrackingUniverseOrigin.ETrackingUniverseOrigin_TrackingUniverseSeated); compositorFunctions.SetTrackingSpace.apply(JOpenVRLibrary.ETrackingUniverseOrigin.ETrackingUniverseOrigin_TrackingUniverseSeated);
} else { } else {
compositorFunctions.SetTrackingSpace.apply(JOpenVRLibrary.ETrackingUniverseOrigin.ETrackingUniverseOrigin_TrackingUniverseStanding); compositorFunctions.SetTrackingSpace.apply(JOpenVRLibrary.ETrackingUniverseOrigin.ETrackingUniverseOrigin_TrackingUniverseStanding);
@ -314,7 +330,7 @@ public class OpenVR implements VRAPI {
frameCount = nowCount; frameCount = nowCount;
vrsystemFunctions.GetDeviceToAbsoluteTrackingPose.apply( vrsystemFunctions.GetDeviceToAbsoluteTrackingPose.apply(
VRApplication.isSeatedExperience()?JOpenVRLibrary.ETrackingUniverseOrigin.ETrackingUniverseOrigin_TrackingUniverseSeated: application.isSeatedExperience()?JOpenVRLibrary.ETrackingUniverseOrigin.ETrackingUniverseOrigin_TrackingUniverseSeated:
JOpenVRLibrary.ETrackingUniverseOrigin.ETrackingUniverseOrigin_TrackingUniverseStanding, JOpenVRLibrary.ETrackingUniverseOrigin.ETrackingUniverseOrigin_TrackingUniverseStanding,
fSecondsUntilPhotons, hmdTrackedDevicePoseReference, JOpenVRLibrary.k_unMaxTrackedDeviceCount); fSecondsUntilPhotons, hmdTrackedDevicePoseReference, JOpenVRLibrary.k_unMaxTrackedDeviceCount);
} }
@ -331,7 +347,7 @@ public class OpenVR implements VRAPI {
VRInput._updateConnectedControllers(); VRInput._updateConnectedControllers();
}*/ }*/
//update controllers pose information //update controllers pose information
VRApplication.getVRinput().updateControllerStates(); application.getVRinput().updateControllerStates();
// read pose data from native // read pose data from native
for (int nDevice = 0; nDevice < JOpenVRLibrary.k_unMaxTrackedDeviceCount; ++nDevice ){ for (int nDevice = 0; nDevice < JOpenVRLibrary.k_unMaxTrackedDeviceCount; ++nDevice ){
@ -405,7 +421,7 @@ public class OpenVR implements VRAPI {
@Override @Override
public Vector3f getSeatedToAbsolutePosition() { public Vector3f getSeatedToAbsolutePosition() {
if( VRApplication.isSeatedExperience() == false ) return Vector3f.ZERO; if( application.isSeatedExperience() == false ) return Vector3f.ZERO;
if( hmdSeatToStand == null ) { if( hmdSeatToStand == null ) {
hmdSeatToStand = new Vector3f(); hmdSeatToStand = new Vector3f();
HmdMatrix34_t mat = vrsystemFunctions.GetSeatedZeroPoseToStandingAbsoluteTrackingPose.apply(); HmdMatrix34_t mat = vrsystemFunctions.GetSeatedZeroPoseToStandingAbsoluteTrackingPose.apply();
@ -483,4 +499,9 @@ public class OpenVR implements VRAPI {
} }
} }
@Override
public VRApplication getApplication() {
return application;
}
} }

@ -5,18 +5,20 @@
*/ */
package com.jme3.input.vr; package com.jme3.input.vr;
import java.util.logging.Logger;
import com.jme3.app.VRApplication; import com.jme3.app.VRApplication;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.system.jopenvr.JOpenVRLibrary;
import com.jme3.system.jopenvr.VRControllerState_t;
import com.jme3.system.jopenvr.VR_IVRSystem_FnTable;
import jmevr.util.VRUtil; import jmevr.util.VRUtil;
import jmevr.util.VRViewManager; import jmevr.util.VRViewManager;
import jopenvr.JOpenVRLibrary;
import jopenvr.VRControllerState_t;
import jopenvr.VR_IVRSystem_FnTable;
/* /*
make helper functions to pull the following easily from raw data (DONE) make helper functions to pull the following easily from raw data (DONE)
@ -64,31 +66,43 @@ Button press: 2, touch: 2
*/ */
public class OpenVRInput implements VRInputAPI { public class OpenVRInput implements VRInputAPI {
private static final VRControllerState_t[] cStates = new VRControllerState_t[JOpenVRLibrary.k_unMaxTrackedDeviceCount]; private static final Logger logger = Logger.getLogger(OpenVRInput.class.getName());
private final VRControllerState_t[] cStates = new VRControllerState_t[JOpenVRLibrary.k_unMaxTrackedDeviceCount];
private static final Quaternion[] rotStore = new Quaternion[JOpenVRLibrary.k_unMaxTrackedDeviceCount]; private final Quaternion[] rotStore = new Quaternion[JOpenVRLibrary.k_unMaxTrackedDeviceCount];
private static final Vector3f[] posStore = new Vector3f[JOpenVRLibrary.k_unMaxTrackedDeviceCount]; private final Vector3f[] posStore = new Vector3f[JOpenVRLibrary.k_unMaxTrackedDeviceCount];
private static final int[] controllerIndex = new int[JOpenVRLibrary.k_unMaxTrackedDeviceCount]; private static final int[] controllerIndex = new int[JOpenVRLibrary.k_unMaxTrackedDeviceCount];
private static int controllerCount = 0; private int controllerCount = 0;
private final Vector2f tempAxis = new Vector2f(), temp2Axis = new Vector2f();
private static final Vector2f tempAxis = new Vector2f(), temp2Axis = new Vector2f(); private final Vector2f lastCallAxis[] = new Vector2f[JOpenVRLibrary.k_unMaxTrackedDeviceCount];
private static final Vector2f lastCallAxis[] = new Vector2f[JOpenVRLibrary.k_unMaxTrackedDeviceCount]; private final boolean needsNewVelocity[] = new boolean[JOpenVRLibrary.k_unMaxTrackedDeviceCount];
private static final boolean needsNewVelocity[] = new boolean[JOpenVRLibrary.k_unMaxTrackedDeviceCount]; private final boolean needsNewAngVelocity[] = new boolean[JOpenVRLibrary.k_unMaxTrackedDeviceCount];
private static final boolean needsNewAngVelocity[] = new boolean[JOpenVRLibrary.k_unMaxTrackedDeviceCount]; private final boolean buttonDown[][] = new boolean[JOpenVRLibrary.k_unMaxTrackedDeviceCount][16];
private static final boolean buttonDown[][] = new boolean[JOpenVRLibrary.k_unMaxTrackedDeviceCount][16]; private float axisMultiplier = 1f;
private static float axisMultiplier = 1f; private final Vector3f tempVel = new Vector3f();
private static final Vector3f tempVel = new Vector3f(); private final Quaternion tempq = new Quaternion();
private static final Quaternion tempq = new Quaternion(); private VRApplication application;
/**
* Create a new <a href="https://github.com/ValveSoftware/openvr/wiki/API-Documentation">OpenVR</a> input attached to the given application.
* @param application the application to which the input is attached.
*/
public OpenVRInput(VRApplication application){
this.application = application;
}
@Override @Override
public float getAxisMultiplier() { public float getAxisMultiplier() {
@ -229,6 +243,9 @@ public class OpenVRInput implements VRInputAPI {
@Override @Override
public boolean init() { public boolean init() {
logger.config("Initialize OpenVR input.");
for(int i=0;i<JOpenVRLibrary.k_unMaxTrackedDeviceCount;i++) { for(int i=0;i<JOpenVRLibrary.k_unMaxTrackedDeviceCount;i++) {
rotStore[i] = new Quaternion(); rotStore[i] = new Quaternion();
posStore[i] = new Vector3f(); posStore[i] = new Vector3f();
@ -262,7 +279,7 @@ public class OpenVRInput implements VRInputAPI {
@Override @Override
public boolean isInputFocused() { public boolean isInputFocused() {
return ((VR_IVRSystem_FnTable)VRApplication.getVRHardware().getVRSystem()).IsInputFocusCapturedByAnotherProcess.apply() == 0; return ((VR_IVRSystem_FnTable)application.getVRHardware().getVRSystem()).IsInputFocusCapturedByAnotherProcess.apply() == 0;
} }
@Override @Override
@ -292,9 +309,9 @@ public class OpenVRInput implements VRInputAPI {
@Override @Override
public Quaternion getFinalObserverRotation(int index) { public Quaternion getFinalObserverRotation(int index) {
VRViewManager vrvm = VRApplication.getVRViewManager(); VRViewManager vrvm = application.getVRViewManager();
if( vrvm == null || isInputDeviceTracking(index) == false ) return null; if( vrvm == null || isInputDeviceTracking(index) == false ) return null;
Object obs = VRApplication.getObserver(); Object obs = application.getObserver();
if( obs instanceof Camera ) { if( obs instanceof Camera ) {
tempq.set(((Camera)obs).getRotation()); tempq.set(((Camera)obs).getRotation());
} else { } else {
@ -305,9 +322,9 @@ public class OpenVRInput implements VRInputAPI {
@Override @Override
public Vector3f getFinalObserverPosition(int index) { public Vector3f getFinalObserverPosition(int index) {
VRViewManager vrvm = VRApplication.getVRViewManager(); VRViewManager vrvm = application.getVRViewManager();
if( vrvm == null || isInputDeviceTracking(index) == false ) return null; if( vrvm == null || isInputDeviceTracking(index) == false ) return null;
Object obs = VRApplication.getObserver(); Object obs = application.getObserver();
Vector3f pos = getPosition(index); Vector3f pos = getPosition(index);
if( obs instanceof Camera ) { if( obs instanceof Camera ) {
((Camera)obs).getRotation().mult(pos, pos); ((Camera)obs).getRotation().mult(pos, pos);
@ -320,9 +337,9 @@ public class OpenVRInput implements VRInputAPI {
@Override @Override
public void triggerHapticPulse(int controllerIndex, float seconds) { public void triggerHapticPulse(int controllerIndex, float seconds) {
if( VRApplication.isInVR() == false || isInputDeviceTracking(controllerIndex) == false ) return; if( application.isInVR() == false || isInputDeviceTracking(controllerIndex) == false ) return;
// apparently only axis ID of 0 works // apparently only axis ID of 0 works
((VR_IVRSystem_FnTable)VRApplication.getVRHardware().getVRSystem()).TriggerHapticPulse.apply(OpenVRInput.controllerIndex[controllerIndex], ((VR_IVRSystem_FnTable)application.getVRHardware().getVRSystem()).TriggerHapticPulse.apply(OpenVRInput.controllerIndex[controllerIndex],
0, (short)Math.round(3f * seconds / 1e-3f)); 0, (short)Math.round(3f * seconds / 1e-3f));
} }
@ -330,7 +347,7 @@ public class OpenVRInput implements VRInputAPI {
public void updateConnectedControllers() { public void updateConnectedControllers() {
controllerCount = 0; controllerCount = 0;
for(int i=0;i<JOpenVRLibrary.k_unMaxTrackedDeviceCount;i++) { for(int i=0;i<JOpenVRLibrary.k_unMaxTrackedDeviceCount;i++) {
if( ((OpenVR)VRApplication.getVRHardware()).getVRSystem().GetTrackedDeviceClass.apply(i) == JOpenVRLibrary.ETrackedDeviceClass.ETrackedDeviceClass_TrackedDeviceClass_Controller ) { if( ((OpenVR)application.getVRHardware()).getVRSystem().GetTrackedDeviceClass.apply(i) == JOpenVRLibrary.ETrackedDeviceClass.ETrackedDeviceClass_TrackedDeviceClass_Controller ) {
controllerIndex[controllerCount] = i; controllerIndex[controllerCount] = i;
controllerCount++; controllerCount++;
} }
@ -341,11 +358,16 @@ public class OpenVRInput implements VRInputAPI {
public void updateControllerStates() { public void updateControllerStates() {
for(int i=0;i<controllerCount;i++) { for(int i=0;i<controllerCount;i++) {
int index = controllerIndex[i]; int index = controllerIndex[i];
((OpenVR)VRApplication.getVRHardware()).getVRSystem().GetControllerState.apply(index, cStates[index]); ((OpenVR)application.getVRHardware()).getVRSystem().GetControllerState.apply(index, cStates[index]);
cStates[index].readField("ulButtonPressed"); cStates[index].readField("ulButtonPressed");
cStates[index].readField("rAxis"); cStates[index].readField("rAxis");
needsNewVelocity[index] = true; needsNewVelocity[index] = true;
needsNewAngVelocity[index] = true; needsNewAngVelocity[index] = true;
} }
} }
@Override
public VRApplication getApplication() {
return application;
}
} }

@ -5,6 +5,7 @@
*/ */
package com.jme3.input.vr; package com.jme3.input.vr;
import com.jme3.app.VRApplication;
import com.jme3.math.Matrix4f; import com.jme3.math.Matrix4f;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
@ -31,6 +32,12 @@ public interface VRAPI {
*/ */
public boolean initVRCompositor(boolean allowed); public boolean initVRCompositor(boolean allowed);
/**
* Get the VR application to which this input is attached.
* @return the VR application to which this input is attached.
*/
public VRApplication getApplication();
/** /**
* Get the object that wraps natively the VR system. * Get the object that wraps natively the VR system.
* @return the object that wraps natively the VR system. * @return the object that wraps natively the VR system.

@ -1,9 +1,10 @@
package com.jme3.input.vr; package com.jme3.input.vr;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import com.jme3.system.jopenvr.JOpenVRLibrary;
import com.jme3.system.jopenvr.VR_IVRChaperone_FnTable;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import jopenvr.JOpenVRLibrary;
import jopenvr.VR_IVRChaperone_FnTable;
/** /**
* A class that represents VR world bounds. * A class that represents VR world bounds.

@ -5,6 +5,7 @@
*/ */
package com.jme3.input.vr; package com.jme3.input.vr;
import com.jme3.app.VRApplication;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
@ -185,4 +186,10 @@ public interface VRInputAPI {
* @param seconds the duration of the pulse in seconds. * @param seconds the duration of the pulse in seconds.
*/ */
public void triggerHapticPulse(int controllerIndex, float seconds); public void triggerHapticPulse(int controllerIndex, float seconds);
/**
* Get the VR application to which this input is attached.
* @return the VR application to which this input is attached.
*/
public VRApplication getApplication();
} }

@ -4,7 +4,6 @@
*/ */
package com.jme3.post; package com.jme3.post;
import com.jme3.app.VRApplication;
import com.jme3.asset.AssetManager; import com.jme3.asset.AssetManager;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
@ -28,22 +27,27 @@ public class CartoonSSAO extends Filter{
private boolean useOutline = true; private boolean useOutline = true;
private float downsample = 1f, applyDistance = 0.0005f; private float downsample = 1f, applyDistance = 0.0005f;
private boolean instancedRendering = false;
RenderManager renderManager; RenderManager renderManager;
ViewPort viewPort; ViewPort viewPort;
/** /**
* Create a Screen Space Ambient Occlusion Filter * Create a Screen Space Ambient Occlusion Filter.
* @param instancedRendering <code>true</code> if this filter has to use instance rendering and <code>false</code> (default) otherwise.
*/ */
public CartoonSSAO() { public CartoonSSAO(boolean instancedRendering) {
super("CartoonSSAO"); super("CartoonSSAO");
this.instancedRendering = instancedRendering;
} }
/** /**
* Create a Screen Space Ambient Occlusion Filter * Create a Screen Space Ambient Occlusion Filter.
* @param downsample factor to divide resolution by for filter, >1 increases speed but degrades quality * @param downsample factor to divide resolution by for filter, >1 increases speed but degrades quality.
* @param instancedRendering <code>true</code> if this filter has to use instance rendering and <code>false</code> (default) otherwise.
*/ */
public CartoonSSAO(float downsample) { public CartoonSSAO(float downsample, boolean instancedRendering) {
this(); this(instancedRendering);
this.downsample = downsample; this.downsample = downsample;
} }
@ -52,7 +56,7 @@ public class CartoonSSAO extends Filter{
* @param cloneFrom the original filter. * @param cloneFrom the original filter.
*/ */
public CartoonSSAO(CartoonSSAO cloneFrom) { public CartoonSSAO(CartoonSSAO cloneFrom) {
this(cloneFrom.downsample); this(cloneFrom.downsample, cloneFrom.instancedRendering);
} }
@Override @Override
@ -149,7 +153,7 @@ public class CartoonSSAO extends Filter{
material.setVector2("FrustumNearFar", frustumNearFar); material.setVector2("FrustumNearFar", frustumNearFar);
material.setFloat("Distance", applyDistance); material.setFloat("Distance", applyDistance);
if( useOutline == false ) material.setBoolean("disableOutline", true); if( useOutline == false ) material.setBoolean("disableOutline", true);
if( VRApplication.isInstanceVRRendering() ) material.setBoolean("useInstancing", true); if( instancedRendering ) material.setBoolean("useInstancing", true);
} }
} }

@ -13,12 +13,11 @@ import com.jme3.renderer.Renderer;
import com.jme3.renderer.ViewPort; import com.jme3.renderer.ViewPort;
import com.jme3.scene.Mesh; import com.jme3.scene.Mesh;
import com.jme3.scene.VertexBuffer; import com.jme3.scene.VertexBuffer;
import com.jme3.system.jopenvr.DistortionCoordinates_t;
import com.jme3.system.jopenvr.JOpenVRLibrary;
import com.jme3.system.jopenvr.VR_IVRSystem_FnTable;
import com.jme3.texture.FrameBuffer; import com.jme3.texture.FrameBuffer;
import jopenvr.DistortionCoordinates_t;
import jopenvr.JOpenVRLibrary;
import jopenvr.VR_IVRSystem_FnTable;
/** /**
* DO NOT USE * DO NOT USE
* @author phr00t * @author phr00t
@ -29,11 +28,14 @@ public class OpenVRFilter extends Filter {
private Mesh distortionMesh; private Mesh distortionMesh;
private VRApplication application = null;
/** /**
* DO NOT USE * DO NOT USE
* @param application the VR application.
*/ */
public OpenVRFilter() { public OpenVRFilter(VRApplication application) {
this.application = application;
} }
/** /**
@ -104,7 +106,7 @@ public class OpenVRFilter extends Filter {
verts[vertPos+2] = 0f; // z verts[vertPos+2] = 0f; // z
vertPos += 3; vertPos += 3;
DistortionCoordinates_t dc0 = ((VR_IVRSystem_FnTable)VRApplication.getVRHardware().getVRSystem()).ComputeDistortion.apply(JOpenVRLibrary.EVREye.EVREye_Eye_Left, u, v); DistortionCoordinates_t dc0 = ((VR_IVRSystem_FnTable)application.getVRHardware().getVRSystem()).ComputeDistortion.apply(JOpenVRLibrary.EVREye.EVREye_Eye_Left, u, v);
texcoordR[coordPos] = dc0.rfRed[0]; texcoordR[coordPos] = dc0.rfRed[0];
texcoordR[coordPos+1] = 1 - dc0.rfRed[1]; texcoordR[coordPos+1] = 1 - dc0.rfRed[1];
@ -128,7 +130,7 @@ public class OpenVRFilter extends Filter {
verts[vertPos+2] = 0f; // z verts[vertPos+2] = 0f; // z
vertPos += 3; vertPos += 3;
DistortionCoordinates_t dc0 = ((VR_IVRSystem_FnTable)VRApplication.getVRHardware().getVRSystem()).ComputeDistortion.apply(JOpenVRLibrary.EVREye.EVREye_Eye_Right, u, v); DistortionCoordinates_t dc0 = ((VR_IVRSystem_FnTable)application.getVRHardware().getVRSystem()).ComputeDistortion.apply(JOpenVRLibrary.EVREye.EVREye_Eye_Right, u, v);
texcoordR[coordPos] = dc0.rfRed[0]; texcoordR[coordPos] = dc0.rfRed[0];
texcoordR[coordPos+1] = 1 - dc0.rfRed[1]; texcoordR[coordPos+1] = 1 - dc0.rfRed[1];

@ -5,7 +5,6 @@
*/ */
package com.jme3.post; package com.jme3.post;
import com.jme3.app.VRApplication;
import com.jme3.post.Filter.Pass; import com.jme3.post.Filter.Pass;
import com.jme3.renderer.Caps; import com.jme3.renderer.Caps;
import com.jme3.renderer.RenderManager; import com.jme3.renderer.RenderManager;
@ -55,10 +54,11 @@ public class PreNormalCaching {
} }
/** /**
* * Reset the cache
* @param stereo <code>true</code> if the rendering is stereo based and <code>false</code> otherwise.
*/ */
public static void resetCache() { public static void resetCache(boolean stereo) {
if( VRApplication.isInVR() == false ) { if( stereo == false ) {
// only use this feature if we are NOT in VR // only use this feature if we are NOT in VR
// we can't use the same normal information for another eye, // we can't use the same normal information for another eye,
// because it will be different! // because it will be different!

@ -6,9 +6,9 @@
package com.jme3.shadow; package com.jme3.shadow;
import com.jme3.app.VRApplication; import com.jme3.app.VRApplication;
import com.jme3.asset.AssetManager;
import com.jme3.math.Matrix4f; import com.jme3.math.Matrix4f;
import com.jme3.math.Vector4f; import com.jme3.math.Vector4f;
import com.jme3.renderer.Camera;
/** /**
* An instanced version of the {@link DirectionalLightShadowFilterVR directional light shadow filter}. * An instanced version of the {@link DirectionalLightShadowFilterVR directional light shadow filter}.
@ -19,22 +19,26 @@ public class InstancedDirectionalShadowFilter extends DirectionalLightShadowFilt
private final Vector4f temp4f = new Vector4f(), temp4f2 = new Vector4f(); private final Vector4f temp4f = new Vector4f(), temp4f2 = new Vector4f();
private VRApplication application;
/** /**
* Create a new instanced version of the {@link DirectionalLightShadowFilterVR directional light shadow filter}. * Create a new instanced version of the {@link DirectionalLightShadowFilterVR directional light shadow filter}.
* @param assetManager the asset manager to use. * @param application the VR application that this filter is attached to.
* @param camera
* @param shadowMapSize the size of the rendered shadowmaps (512, 1024, 2048, etc...) * @param shadowMapSize the size of the rendered shadowmaps (512, 1024, 2048, etc...)
* @param nbSplits the number of shadow maps rendered (the more shadow maps the more quality, the less fps). * @param nbSplits the number of shadow maps rendered (the more shadow maps the more quality, the less fps).
* @param instancedRendering <code>true</code> if this filter has to use instance rendering and <code>false</code> otherwise.
*/ */
public InstancedDirectionalShadowFilter(AssetManager assetManager, int shadowMapSize, int nbSplits) { public InstancedDirectionalShadowFilter(VRApplication application, Camera camera, int shadowMapSize, int nbSplits, boolean instancedRendering) {
super(assetManager, shadowMapSize, nbSplits, "Common/MatDefs/VR/PostShadowFilter.j3md"); super(application.getAssetManager(), shadowMapSize, nbSplits, "Common/MatDefs/VR/PostShadowFilter.j3md");
} }
@Override @Override
protected void preFrame(float tpf) { protected void preFrame(float tpf) {
shadowRenderer.preFrame(tpf); shadowRenderer.preFrame(tpf);
if( VRApplication.isInstanceVRRendering() ) { if( application.isInstanceVRRendering() ) {
material.setMatrix4("ViewProjectionMatrixInverseRight", VRApplication.getVRViewManager().getCamRight().getViewProjectionMatrix().invert()); material.setMatrix4("ViewProjectionMatrixInverseRight", application.getVRViewManager().getCamRight().getViewProjectionMatrix().invert());
Matrix4f m = VRApplication.getVRViewManager().getCamRight().getViewProjectionMatrix(); Matrix4f m = application.getVRViewManager().getCamRight().getViewProjectionMatrix();
material.setVector4("ViewProjectionMatrixRow2Right", temp4f2.set(m.m20, m.m21, m.m22, m.m23)); material.setVector4("ViewProjectionMatrixRow2Right", temp4f2.set(m.m20, m.m21, m.m22, m.m23));
} }
material.setMatrix4("ViewProjectionMatrixInverse", viewPort.getCamera().getViewProjectionMatrix().invert()); material.setMatrix4("ViewProjectionMatrixInverse", viewPort.getCamera().getViewProjectionMatrix().invert());

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.IntByReference;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;
@ -13,7 +13,7 @@ public class HiddenAreaMesh_t extends Structure {
* const struct vr::HmdVector2_t *<br> * const struct vr::HmdVector2_t *<br>
* C type : HmdVector2_t* * C type : HmdVector2_t*
*/ */
public jopenvr.HmdVector2_t.ByReference pVertexData; public com.jme3.system.jopenvr.HmdVector2_t.ByReference pVertexData;
public int unTriangleCount; public int unTriangleCount;
public HiddenAreaMesh_t() { public HiddenAreaMesh_t() {
super(); super();
@ -25,7 +25,7 @@ public class HiddenAreaMesh_t extends Structure {
* @param pVertexData const struct vr::HmdVector2_t *<br> * @param pVertexData const struct vr::HmdVector2_t *<br>
* C type : HmdVector2_t* * C type : HmdVector2_t*
*/ */
public HiddenAreaMesh_t(jopenvr.HmdVector2_t.ByReference pVertexData, int unTriangleCount) { public HiddenAreaMesh_t(com.jme3.system.jopenvr.HmdVector2_t.ByReference pVertexData, int unTriangleCount) {
super(); super();
this.pVertexData = pVertexData; this.pVertexData = pVertexData;
this.unTriangleCount = unTriangleCount; this.unTriangleCount = unTriangleCount;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Library; import com.sun.jna.Library;
import com.sun.jna.Native; import com.sun.jna.Native;
import com.sun.jna.NativeLibrary; import com.sun.jna.NativeLibrary;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import com.sun.jna.ptr.ShortByReference; import com.sun.jna.ptr.ShortByReference;
@ -14,7 +14,7 @@ public class RenderModel_t extends Structure {
* const struct vr::RenderModel_Vertex_t *<br> * const struct vr::RenderModel_Vertex_t *<br>
* C type : RenderModel_Vertex_t* * C type : RenderModel_Vertex_t*
*/ */
public jopenvr.RenderModel_Vertex_t.ByReference rVertexData; public com.jme3.system.jopenvr.RenderModel_Vertex_t.ByReference rVertexData;
public int unVertexCount; public int unVertexCount;
/** /**
* const uint16_t *<br> * const uint16_t *<br>
@ -37,7 +37,7 @@ public class RenderModel_t extends Structure {
* C type : uint16_t*<br> * C type : uint16_t*<br>
* @param diffuseTextureId C type : TextureID_t * @param diffuseTextureId C type : TextureID_t
*/ */
public RenderModel_t(jopenvr.RenderModel_Vertex_t.ByReference rVertexData, int unVertexCount, ShortByReference rIndexData, int unTriangleCount, int diffuseTextureId) { public RenderModel_t(com.jme3.system.jopenvr.RenderModel_Vertex_t.ByReference rVertexData, int unVertexCount, ShortByReference rIndexData, int unTriangleCount, int diffuseTextureId) {
super(); super();
this.rVertexData = rVertexData; this.rVertexData = rVertexData;
this.unVertexCount = unVertexCount; this.unVertexCount = unVertexCount;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Union; import com.sun.jna.Union;
/** /**

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import java.util.Arrays; import java.util.Arrays;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
@ -369,7 +369,7 @@ public class VR_IVROverlay_FnTable extends Structure {
void apply(int eTrackingOrigin, HmdMatrix34_t pmatTrackingOriginToKeyboardTransform); void apply(int eTrackingOrigin, HmdMatrix34_t pmatTrackingOriginToKeyboardTransform);
}; };
public interface SetKeyboardPositionForOverlay_callback extends Callback { public interface SetKeyboardPositionForOverlay_callback extends Callback {
void apply(long ulOverlayHandle, jopenvr.HmdRect2_t.ByValue avoidRect); void apply(long ulOverlayHandle, com.jme3.system.jopenvr.HmdRect2_t.ByValue avoidRect);
}; };
public VR_IVROverlay_FnTable() { public VR_IVROverlay_FnTable() {
super(); super();

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
@ -31,7 +31,7 @@ public class VR_IVRSystem_FnTable extends Structure {
/** C type : GetD3D9AdapterIndex_callback* */ /** C type : GetD3D9AdapterIndex_callback* */
public VR_IVRSystem_FnTable.GetD3D9AdapterIndex_callback GetD3D9AdapterIndex; public VR_IVRSystem_FnTable.GetD3D9AdapterIndex_callback GetD3D9AdapterIndex;
/** C type : GetDXGIOutputInfo_callback* */ /** C type : GetDXGIOutputInfo_callback* */
public jopenvr.VR_IVRExtendedDisplay_FnTable.GetDXGIOutputInfo_callback GetDXGIOutputInfo; public com.jme3.system.jopenvr.VR_IVRExtendedDisplay_FnTable.GetDXGIOutputInfo_callback GetDXGIOutputInfo;
/** C type : IsDisplayOnDesktop_callback* */ /** C type : IsDisplayOnDesktop_callback* */
public VR_IVRSystem_FnTable.IsDisplayOnDesktop_callback IsDisplayOnDesktop; public VR_IVRSystem_FnTable.IsDisplayOnDesktop_callback IsDisplayOnDesktop;
/** C type : SetDisplayVisibility_callback* */ /** C type : SetDisplayVisibility_callback* */
@ -159,13 +159,13 @@ public class VR_IVRSystem_FnTable extends Structure {
void apply(IntBuffer pnWidth, IntBuffer pnHeight); void apply(IntBuffer pnWidth, IntBuffer pnHeight);
}; };
public interface GetProjectionMatrix_callback extends Callback { public interface GetProjectionMatrix_callback extends Callback {
jopenvr.HmdMatrix44_t.ByValue apply(int eEye, float fNearZ, float fFarZ, int eProjType); com.jme3.system.jopenvr.HmdMatrix44_t.ByValue apply(int eEye, float fNearZ, float fFarZ, int eProjType);
}; };
public interface GetProjectionRaw_callback extends Callback { public interface GetProjectionRaw_callback extends Callback {
void apply(int eEye, FloatByReference pfLeft, FloatByReference pfRight, FloatByReference pfTop, FloatByReference pfBottom); void apply(int eEye, FloatByReference pfLeft, FloatByReference pfRight, FloatByReference pfTop, FloatByReference pfBottom);
}; };
public interface ComputeDistortion_callback extends Callback { public interface ComputeDistortion_callback extends Callback {
jopenvr.DistortionCoordinates_t.ByValue apply(int eEye, float fU, float fV); com.jme3.system.jopenvr.DistortionCoordinates_t.ByValue apply(int eEye, float fU, float fV);
}; };
public interface GetEyeToHeadTransform_callback extends Callback { public interface GetEyeToHeadTransform_callback extends Callback {
HmdMatrix34_t.ByValue apply(int eEye); HmdMatrix34_t.ByValue apply(int eEye);
@ -292,7 +292,7 @@ public class VR_IVRSystem_FnTable extends Structure {
Pointer apply(int eType); Pointer apply(int eType);
}; };
public interface GetHiddenAreaMesh_callback extends Callback { public interface GetHiddenAreaMesh_callback extends Callback {
jopenvr.HiddenAreaMesh_t.ByValue apply(int eEye); com.jme3.system.jopenvr.HiddenAreaMesh_t.ByValue apply(int eEye);
}; };
public interface GetControllerState_callback extends Callback { public interface GetControllerState_callback extends Callback {
byte apply(int unControllerDeviceIndex, VRControllerState_t pControllerState); byte apply(int unControllerDeviceIndex, VRControllerState_t pControllerState);

@ -1,4 +1,4 @@
package jopenvr; package com.jme3.system.jopenvr;
import com.sun.jna.Callback; import com.sun.jna.Callback;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;

@ -44,6 +44,7 @@ import com.jme3.renderer.opengl.*;
import com.jme3.system.*; import com.jme3.system.*;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.ARBDebugOutput;
import org.lwjgl.opengl.ARBFramebufferObject; import org.lwjgl.opengl.ARBFramebufferObject;
import org.lwjgl.opengl.EXTFramebufferMultisample; import org.lwjgl.opengl.EXTFramebufferMultisample;
import org.lwjgl.opengl.GLCapabilities; import org.lwjgl.opengl.GLCapabilities;
@ -189,12 +190,10 @@ public abstract class LwjglContextVR implements JmeContext {
throw new UnsupportedOperationException("Unsupported renderer: " + settings.getRenderer()); throw new UnsupportedOperationException("Unsupported renderer: " + settings.getRenderer());
} }
//FIXME: Needs LWJGL 3.1.0
/*
if (capabilities.GL_ARB_debug_output && settings.getBoolean("GraphicsDebug")) { if (capabilities.GL_ARB_debug_output && settings.getBoolean("GraphicsDebug")) {
ARBDebugOutput.glDebugMessageCallbackARB(new LwjglGLDebugOutputHandler(), 0); ARBDebugOutput.glDebugMessageCallbackARB(new LwjglGLDebugOutputHandler(), 0);
} }
*/
renderer.setMainFrameBufferSrgb(settings.isGammaCorrection()); renderer.setMainFrameBufferSrgb(settings.isGammaCorrection());
renderer.setLinearizeSrgbImages(settings.isGammaCorrection()); renderer.setLinearizeSrgbImages(settings.isGammaCorrection());

@ -245,8 +245,7 @@ public abstract class LwjglWindowVR extends LwjglContextVR implements Runnable {
if (Type.Display.equals(type)) { if (Type.Display.equals(type)) {
glfwShowWindow(window); glfwShowWindow(window);
//FIXME: Needs LGJGL 3.1.0 glfwFocusWindow(window);
//glfwFocusWindow(window);
} }
// Add a resize callback which delegates to the listener // Add a resize callback which delegates to the listener

@ -7,10 +7,9 @@ package jmevr.util;
import com.jme3.app.VRApplication; import com.jme3.app.VRApplication;
import com.jme3.scene.Mesh; import com.jme3.scene.Mesh;
import com.jme3.scene.VertexBuffer; import com.jme3.scene.VertexBuffer;
import com.jme3.system.jopenvr.DistortionCoordinates_t;
import jopenvr.DistortionCoordinates_t; import com.jme3.system.jopenvr.JOpenVRLibrary;
import jopenvr.JOpenVRLibrary; import com.jme3.system.jopenvr.VR_IVRSystem_FnTable;
import jopenvr.VR_IVRSystem_FnTable;
/** /**
* *
@ -18,7 +17,7 @@ import jopenvr.VR_IVRSystem_FnTable;
*/ */
public class MeshUtil { public class MeshUtil {
public static Mesh setupDistortionMesh(int eye) { public static Mesh setupDistortionMesh(int eye, VRApplication application) {
Mesh distortionMesh = new Mesh(); Mesh distortionMesh = new Mesh();
float m_iLensGridSegmentCountH = 43, m_iLensGridSegmentCountV = 43; float m_iLensGridSegmentCountH = 43, m_iLensGridSegmentCountV = 43;
@ -46,7 +45,7 @@ public class MeshUtil {
vertPos += 3; vertPos += 3;
DistortionCoordinates_t dc0; DistortionCoordinates_t dc0;
if( VRApplication.getVRHardware().getVRSystem() == null ) { if( application.getVRHardware().getVRSystem() == null ) {
// default to no distortion // default to no distortion
texcoordR[coordPos] = u; texcoordR[coordPos] = u;
texcoordR[coordPos + 1] = 1 - v; texcoordR[coordPos + 1] = 1 - v;
@ -55,7 +54,7 @@ public class MeshUtil {
texcoordB[coordPos] = u; texcoordB[coordPos] = u;
texcoordB[coordPos + 1] = 1 - v; texcoordB[coordPos + 1] = 1 - v;
} else { } else {
dc0 = ((VR_IVRSystem_FnTable)VRApplication.getVRHardware().getVRSystem()).ComputeDistortion.apply(eye, u, v); dc0 = ((VR_IVRSystem_FnTable)application.getVRHardware().getVRSystem()).ComputeDistortion.apply(eye, u, v);
texcoordR[coordPos] = dc0.rfRed[0]; texcoordR[coordPos] = dc0.rfRed[0];
texcoordR[coordPos + 1] = 1 - dc0.rfRed[1]; texcoordR[coordPos + 1] = 1 - dc0.rfRed[1];

@ -36,13 +36,31 @@ public class VRGuiManager {
MANUAL, AUTO_CAM_ALL, AUTO_CAM_ALL_SKIP_PITCH, AUTO_OBSERVER_POS_CAM_ROTATION, AUTO_OBSERVER_ALL, AUTO_OBSERVER_ALL_CAMHEIGHT MANUAL, AUTO_CAM_ALL, AUTO_CAM_ALL_SKIP_PITCH, AUTO_OBSERVER_POS_CAM_ROTATION, AUTO_OBSERVER_ALL, AUTO_OBSERVER_ALL_CAMHEIGHT
} }
private static Camera camLeft, camRight; private Camera camLeft, camRight;
private static float guiDistance = 1.5f, guiScale = 1f, guiPositioningElastic; private float guiDistance = 1.5f, guiScale = 1f, guiPositioningElastic;
private static POSITIONING_MODE posMode = POSITIONING_MODE.AUTO_CAM_ALL; private POSITIONING_MODE posMode = POSITIONING_MODE.AUTO_CAM_ALL;
private static final Matrix3f orient = new Matrix3f(); private final Matrix3f orient = new Matrix3f();
private static Vector2f screenSize; private Vector2f screenSize;
protected static boolean wantsReposition; protected boolean wantsReposition;
private VRApplication application = null;
/**
* Create a new GUI manager attached to the given application.
* @param application the VR application that this manager is attached to.
*/
public VRGuiManager(VRApplication application){
this.application = application;
}
/**
* Get the VR application to which this GUI manager is attached.
* @return the VR application to which this GUI manager is attached.
*/
public VRApplication getApplication(){
return application;
}
/** /**
* *
@ -52,63 +70,64 @@ public class VRGuiManager {
* *
* @param elastic amount of elasticity * @param elastic amount of elasticity
*/ */
public static void setPositioningElasticity(float elastic) { public void setPositioningElasticity(float elastic) {
guiPositioningElastic = elastic; guiPositioningElastic = elastic;
} }
public static float getPositioningElasticity() { public float getPositioningElasticity() {
return guiPositioningElastic; return guiPositioningElastic;
} }
public static void setPositioningMode(POSITIONING_MODE mode) { public void setPositioningMode(POSITIONING_MODE mode) {
posMode = mode; posMode = mode;
} }
public static Vector2f getCanvasSize() { public Vector2f getCanvasSize() {
if( screenSize == null ) { if( screenSize == null ) {
if( VRApplication.isInVR() && VRApplication.getVRHardware() != null ) { if( application.isInVR() && application.getVRHardware() != null ) {
screenSize = new Vector2f(); screenSize = new Vector2f();
VRApplication.getVRHardware().getRenderSize(screenSize); application.getVRHardware().getRenderSize(screenSize);
screenSize.multLocal(VRApplication.getVRViewManager().getResolutionMuliplier()); screenSize.multLocal(application.getVRViewManager().getResolutionMuliplier());
} else { } else {
AppSettings as = VRApplication.getMainVRApp().getContext().getSettings(); AppSettings as = application.getContext().getSettings();
screenSize = new Vector2f(as.getWidth(), as.getHeight()); screenSize = new Vector2f(as.getWidth(), as.getHeight());
} }
} }
return screenSize; return screenSize;
} }
private static Vector2f ratio; private Vector2f ratio;
public static Vector2f getCanvasToWindowRatio() {
public Vector2f getCanvasToWindowRatio() {
if( ratio == null ) { if( ratio == null ) {
ratio = new Vector2f(); ratio = new Vector2f();
Vector2f canvas = getCanvasSize(); Vector2f canvas = getCanvasSize();
int width = Integer.min(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getWidth(), int width = Integer.min(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getWidth(),
VRApplication.getMainVRApp().getContext().getSettings().getWidth()); application.getContext().getSettings().getWidth());
int height = Integer.min(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getHeight(), int height = Integer.min(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getHeight(),
VRApplication.getMainVRApp().getContext().getSettings().getHeight()); application.getContext().getSettings().getHeight());
ratio.x = Float.max(1f, canvas.x / width); ratio.x = Float.max(1f, canvas.x / width);
ratio.y = Float.max(1f, canvas.y / height); ratio.y = Float.max(1f, canvas.y / height);
} }
return ratio; return ratio;
} }
public static POSITIONING_MODE getPositioningMode() { public POSITIONING_MODE getPositioningMode() {
return posMode; return posMode;
} }
public static void positionGui() { public void positionGui() {
wantsReposition = true; wantsReposition = true;
} }
private static final Vector3f EoldPos = new Vector3f(); private final Vector3f EoldPos = new Vector3f();
private static final Quaternion EoldDir = new Quaternion(); private final Quaternion EoldDir = new Quaternion();
private static void positionTo(Vector3f pos, Quaternion dir, float tpf) { private void positionTo(Vector3f pos, Quaternion dir, float tpf) {
Vector3f guiPos = guiQuadNode.getLocalTranslation(); Vector3f guiPos = guiQuadNode.getLocalTranslation();
guiPos.set(0f, 0f, guiDistance); guiPos.set(0f, 0f, guiDistance);
dir.mult(guiPos, guiPos); dir.mult(guiPos, guiPos);
guiPos.x += pos.x; guiPos.x += pos.x;
guiPos.y += pos.y + VRApplication.getVRHeightAdjustment(); guiPos.y += pos.y + application.getVRHeightAdjustment();
guiPos.z += pos.z; guiPos.z += pos.z;
if( guiPositioningElastic > 0f && posMode != POSITIONING_MODE.MANUAL ) { if( guiPositioningElastic > 0f && posMode != POSITIONING_MODE.MANUAL ) {
// mix pos & dir with current pos & dir // mix pos & dir with current pos & dir
@ -117,14 +136,15 @@ public class VRGuiManager {
} }
} }
protected static void updateGuiQuadGeometricState() { protected void updateGuiQuadGeometricState() {
guiQuadNode.updateGeometricState(); guiQuadNode.updateGeometricState();
} }
protected static void positionGuiNow(float tpf) { protected void positionGuiNow(float tpf) {
wantsReposition = false; wantsReposition = false;
if( VRApplication.isInVR() == false ) return; if( application.isInVR() == false ) return;
guiQuadNode.setLocalScale(guiDistance * guiScale * 4f, 4f * guiDistance * guiScale, 1f); guiQuadNode.setLocalScale(guiDistance * guiScale * 4f, 4f * guiDistance * guiScale, 1f);
switch( posMode ) { switch( posMode ) {
case MANUAL: case MANUAL:
case AUTO_CAM_ALL_SKIP_PITCH: case AUTO_CAM_ALL_SKIP_PITCH:
@ -135,9 +155,10 @@ public class VRGuiManager {
positionTo(temppos, camLeft.getRotation(), tpf); positionTo(temppos, camLeft.getRotation(), tpf);
} }
rotateScreenTo(camLeft.getRotation(), tpf); rotateScreenTo(camLeft.getRotation(), tpf);
break; break;
case AUTO_OBSERVER_POS_CAM_ROTATION: case AUTO_OBSERVER_POS_CAM_ROTATION:
Object obs = VRApplication.getObserver(); Object obs = application.getObserver();
if( obs != null ) { if( obs != null ) {
if( obs instanceof Camera ) { if( obs instanceof Camera ) {
positionTo(((Camera)obs).getLocation(), camLeft.getRotation(), tpf); positionTo(((Camera)obs).getLocation(), camLeft.getRotation(), tpf);
@ -146,10 +167,11 @@ public class VRGuiManager {
} }
} }
rotateScreenTo(camLeft.getRotation(), tpf); rotateScreenTo(camLeft.getRotation(), tpf);
break; break;
case AUTO_OBSERVER_ALL: case AUTO_OBSERVER_ALL:
case AUTO_OBSERVER_ALL_CAMHEIGHT: case AUTO_OBSERVER_ALL_CAMHEIGHT:
obs = VRApplication.getObserver(); obs = application.getObserver();
if( obs != null ) { if( obs != null ) {
Quaternion q; Quaternion q;
if( obs instanceof Camera ) { if( obs instanceof Camera ) {
@ -164,14 +186,19 @@ public class VRGuiManager {
} }
positionTo(temppos, q, tpf); positionTo(temppos, q, tpf);
rotateScreenTo(q, tpf); rotateScreenTo(q, tpf);
} }
break; break;
} }
} }
private static final Vector3f look = new Vector3f(), left = new Vector3f(), temppos = new Vector3f(), up = new Vector3f(); private final Vector3f look = new Vector3f(), left = new Vector3f(), temppos = new Vector3f(), up = new Vector3f();
private static final Quaternion tempq = new Quaternion(); private final Quaternion tempq = new Quaternion();
private static void rotateScreenTo(Quaternion dir, float tpf) {
private void rotateScreenTo(Quaternion dir, float tpf) {
dir.getRotationColumn(2, look).negateLocal(); dir.getRotationColumn(2, look).negateLocal();
dir.getRotationColumn(0, left).negateLocal(); dir.getRotationColumn(0, left).negateLocal();
orient.fromAxes(left, dir.getRotationColumn(1, up), look); orient.fromAxes(left, dir.getRotationColumn(1, up), look);
@ -186,24 +213,24 @@ public class VRGuiManager {
} }
} }
public static void setGuiDistance(float newGuiDistance) { public void setGuiDistance(float newGuiDistance) {
guiDistance = newGuiDistance; guiDistance = newGuiDistance;
} }
public static void setGuiScale(float scale) { public void setGuiScale(float scale) {
guiScale = scale; guiScale = scale;
} }
public static float getGuiDistance() { public float getGuiDistance() {
return guiDistance; return guiDistance;
} }
public static void adjustGuiDistance(float adjustAmount) { public void adjustGuiDistance(float adjustAmount) {
guiDistance += adjustAmount; guiDistance += adjustAmount;
} }
protected static void setupGui(Camera leftcam, Camera rightcam, ViewPort left, ViewPort right) { protected void setupGui(Camera leftcam, Camera rightcam, ViewPort left, ViewPort right) {
if( VRApplication.hasTraditionalGUIOverlay() ) { if( application.hasTraditionalGUIOverlay() ) {
camLeft = leftcam; camLeft = leftcam;
camRight = rightcam; camRight = rightcam;
Spatial guiScene = getGuiQuad(camLeft); Spatial guiScene = getGuiQuad(camLeft);
@ -216,32 +243,31 @@ public class VRGuiManager {
/* /*
do not use, set by preconfigure routine in VRApplication do not use, set by preconfigure routine in VRApplication
*/ */
public static void _enableCurvedSuface(boolean set) { public void _enableCurvedSuface(boolean set) {
useCurvedSurface = set; useCurvedSurface = set;
} }
/* /*
do not use, set by preconfigure routine in VRApplication do not use, set by preconfigure routine in VRApplication
*/ */
public static void _enableGuiOverdraw(boolean set) { public void _enableGuiOverdraw(boolean set) {
overdraw = set; overdraw = set;
} }
private static boolean useCurvedSurface = false, overdraw = false; private boolean useCurvedSurface = false, overdraw = false;
private static Geometry guiQuad; private Geometry guiQuad;
private static Node guiQuadNode; private Node guiQuadNode;
private static ViewPort offView; private ViewPort offView;
private static Texture2D guiTexture; private Texture2D guiTexture;
private static Spatial getGuiQuad(Camera sourceCam){ private Spatial getGuiQuad(Camera sourceCam){
if( guiQuadNode == null ) { if( guiQuadNode == null ) {
VRApplication sourceApp = VRApplication.getMainVRApp();
Vector2f guiCanvasSize = getCanvasSize(); Vector2f guiCanvasSize = getCanvasSize();
Camera offCamera = sourceCam.clone(); Camera offCamera = sourceCam.clone();
offCamera.setParallelProjection(true); offCamera.setParallelProjection(true);
offCamera.setLocation(Vector3f.ZERO); offCamera.setLocation(Vector3f.ZERO);
offCamera.lookAt(Vector3f.UNIT_Z, Vector3f.UNIT_Y); offCamera.lookAt(Vector3f.UNIT_Z, Vector3f.UNIT_Y);
offView = sourceApp.getRenderManager().createPreView("GUI View", offCamera); offView = application.getRenderManager().createPreView("GUI View", offCamera);
offView.setClearFlags(true, true, true); offView.setClearFlags(true, true, true);
offView.setBackgroundColor(ColorRGBA.BlackNoAlpha); offView.setBackgroundColor(ColorRGBA.BlackNoAlpha);
@ -261,15 +287,15 @@ public class VRGuiManager {
offView.setOutputFrameBuffer(offBuffer); offView.setOutputFrameBuffer(offBuffer);
// setup framebuffer's scene // setup framebuffer's scene
offView.attachScene(sourceApp.getGuiNode()); offView.attachScene(application.getGuiNode());
if( useCurvedSurface ) { if( useCurvedSurface ) {
guiQuad = (Geometry)VRApplication.getMainVRApp().getAssetManager().loadModel("jmevr/util/gui_mesh.j3o"); guiQuad = (Geometry)application.getAssetManager().loadModel("Common/Util/gui_mesh.j3o");
} else { } else {
guiQuad = new Geometry("guiQuad", new CenterQuad(1f, 1f)); guiQuad = new Geometry("guiQuad", new CenterQuad(1f, 1f));
} }
Material mat = new Material(sourceApp.getAssetManager(), "Common/MatDefs/VR/GuiOverlay.j3md"); Material mat = new Material(application.getAssetManager(), "Common/MatDefs/VR/GuiOverlay.j3md");
mat.getAdditionalRenderState().setDepthTest(!overdraw); mat.getAdditionalRenderState().setDepthTest(!overdraw);
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
mat.getAdditionalRenderState().setDepthWrite(false); mat.getAdditionalRenderState().setDepthWrite(false);

@ -5,6 +5,8 @@
*/ */
package jmevr.util; package jmevr.util;
import java.util.logging.Logger;
import com.jme3.app.VRApplication; import com.jme3.app.VRApplication;
import com.jme3.input.MouseInput; import com.jme3.input.MouseInput;
import com.jme3.input.controls.AnalogListener; import com.jme3.input.controls.AnalogListener;
@ -24,81 +26,110 @@ import com.jme3.ui.Picture;
*/ */
public class VRMouseManager { public class VRMouseManager {
private static final int AVERAGE_AMNT = 4; private static final Logger logger = Logger.getLogger(VRMouseManager.class.getName());
private static int avgCounter;
private VRApplication application = null;
private final int AVERAGE_AMNT = 4;
private int avgCounter;
private static Picture mouseImage; private Picture mouseImage;
private static int recentCenterCount = 0; private int recentCenterCount = 0;
private static final Vector2f cursorPos = new Vector2f(); private final Vector2f cursorPos = new Vector2f();
private static float ySize, sensitivity = 8f, acceleration = 2f; private float ySize, sensitivity = 8f, acceleration = 2f;
private static final float[] lastXmv = new float[AVERAGE_AMNT], lastYmv = new float[AVERAGE_AMNT]; private final float[] lastXmv = new float[AVERAGE_AMNT], lastYmv = new float[AVERAGE_AMNT];
private static boolean thumbstickMode; private boolean thumbstickMode;
private static float moveScale = 1f; private float moveScale = 1f;
private static float avg(float[] arr) { private float avg(float[] arr) {
float amt = 0f; float amt = 0f;
for(float f : arr) amt += f; for(float f : arr) amt += f;
return amt / arr.length; return amt / arr.length;
} }
protected static void init() { public VRMouseManager(VRApplication application){
this.application = application;
}
/**
* Get the VR application to which this mouse manager is attached.
* @return the VR application to which this mouse manager is attached.
*/
public VRApplication getApplication(){
return application;
}
protected void init() {
logger.config("Initializing VR mouse manager.");
// load default mouseimage // load default mouseimage
mouseImage = new Picture("mouse"); mouseImage = new Picture("mouse");
setImage("jmevr/util/mouse.png"); setImage("Common/Util/mouse.png");
// hide default cursor by making it invisible // hide default cursor by making it invisible
MouseInput mi = VRApplication.getMainVRApp().getContext().getMouseInput(); MouseInput mi = application.getContext().getMouseInput();
if( mi instanceof GlfwMouseInputVR ){ if( mi instanceof GlfwMouseInputVR ){
((GlfwMouseInputVR)mi).hideActiveCursor(); ((GlfwMouseInputVR)mi).hideActiveCursor();
} }
centerMouse(); centerMouse();
} }
public static void setThumbstickMode(boolean set) { public void setThumbstickMode(boolean set) {
thumbstickMode = set; thumbstickMode = set;
} }
public static boolean isThumbstickMode() { public boolean isThumbstickMode() {
return thumbstickMode; return thumbstickMode;
} }
public static void setSpeed(float sensitivity, float acceleration) { public void setSpeed(float sensitivity, float acceleration) {
VRMouseManager.sensitivity = sensitivity; this.sensitivity = sensitivity;
VRMouseManager.acceleration = acceleration; this.acceleration = acceleration;
} }
public static float getSpeedSensitivity() { public float getSpeedSensitivity() {
return sensitivity; return sensitivity;
} }
public static float getSpeedAcceleration() { public float getSpeedAcceleration() {
return acceleration; return acceleration;
} }
public static void setMouseMoveScale(float set) { public void setMouseMoveScale(float set) {
moveScale = set; moveScale = set;
} }
public static void setImage(String texture) { public void setImage(String texture) {
if( VRApplication.isInVR() == false ) return; if( application.isInVR() == false ){
Texture tex = VRApplication.getMainVRApp().getAssetManager().loadTexture(texture); Texture tex = application.getAssetManager().loadTexture(texture);
mouseImage.setTexture(VRApplication.getMainVRApp().getAssetManager(), (Texture2D)tex, true); mouseImage.setTexture(application.getAssetManager(), (Texture2D)tex, true);
ySize = tex.getImage().getHeight(); ySize = tex.getImage().getHeight();
mouseImage.setHeight(ySize); mouseImage.setHeight(ySize);
mouseImage.setWidth(tex.getImage().getWidth()); mouseImage.setWidth(tex.getImage().getWidth());
mouseImage.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha); mouseImage.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
mouseImage.getMaterial().getAdditionalRenderState().setDepthWrite(false); mouseImage.getMaterial().getAdditionalRenderState().setDepthWrite(false);
} else {
Texture tex = application.getAssetManager().loadTexture(texture);
mouseImage.setTexture(application.getAssetManager(), (Texture2D)tex, true);
ySize = tex.getImage().getHeight();
mouseImage.setHeight(ySize);
mouseImage.setWidth(tex.getImage().getWidth());
mouseImage.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
mouseImage.getMaterial().getAdditionalRenderState().setDepthWrite(false);
}
} }
public static void updateAnalogAsMouse(int inputIndex, AnalogListener mouseListener, String mouseXName, String mouseYName, float tpf) { public void updateAnalogAsMouse(int inputIndex, AnalogListener mouseListener, String mouseXName, String mouseYName, float tpf) {
// got a tracked controller to use as the "mouse" // got a tracked controller to use as the "mouse"
if( VRApplication.isInVR() == false || if( application.isInVR() == false ||
VRApplication.getVRinput() == null || application.getVRinput() == null ||
VRApplication.getVRinput().isInputDeviceTracking(inputIndex) == false ) return; application.getVRinput().isInputDeviceTracking(inputIndex) == false ) return;
Vector2f tpDelta; Vector2f tpDelta;
if( thumbstickMode ) { if( thumbstickMode ) {
tpDelta = VRApplication.getVRinput().getAxis(inputIndex, VRInputType.ViveTrackpadAxis); tpDelta = application.getVRinput().getAxis(inputIndex, VRInputType.ViveTrackpadAxis);
} else { } else {
tpDelta = VRApplication.getVRinput().getAxisDeltaSinceLastCall(inputIndex, VRInputType.ViveTrackpadAxis); tpDelta = application.getVRinput().getAxisDeltaSinceLastCall(inputIndex, VRInputType.ViveTrackpadAxis);
} }
float Xamount = (float)Math.pow(Math.abs(tpDelta.x) * sensitivity, acceleration); float Xamount = (float)Math.pow(Math.abs(tpDelta.x) * sensitivity, acceleration);
float Yamount = (float)Math.pow(Math.abs(tpDelta.y) * sensitivity, acceleration); float Yamount = (float)Math.pow(Math.abs(tpDelta.y) * sensitivity, acceleration);
@ -109,13 +140,13 @@ public class VRMouseManager {
if( tpDelta.x != 0f && mouseXName != null ) mouseListener.onAnalog(mouseXName, Xamount * 0.2f, tpf); if( tpDelta.x != 0f && mouseXName != null ) mouseListener.onAnalog(mouseXName, Xamount * 0.2f, tpf);
if( tpDelta.y != 0f && mouseYName != null ) mouseListener.onAnalog(mouseYName, Yamount * 0.2f, tpf); if( tpDelta.y != 0f && mouseYName != null ) mouseListener.onAnalog(mouseYName, Yamount * 0.2f, tpf);
} }
if( VRApplication.getMainVRApp().getInputManager().isCursorVisible() ) { if( application.getInputManager().isCursorVisible() ) {
int index = (avgCounter+1) % AVERAGE_AMNT; int index = (avgCounter+1) % AVERAGE_AMNT;
lastXmv[index] = Xamount * 133f; lastXmv[index] = Xamount * 133f;
lastYmv[index] = Yamount * 133f; lastYmv[index] = Yamount * 133f;
cursorPos.x -= avg(lastXmv); cursorPos.x -= avg(lastXmv);
cursorPos.y -= avg(lastYmv); cursorPos.y -= avg(lastYmv);
Vector2f maxsize = VRGuiManager.getCanvasSize(); Vector2f maxsize = application.getVRGUIManager().getCanvasSize();
if( cursorPos.x > maxsize.x ) cursorPos.x = maxsize.x; if( cursorPos.x > maxsize.x ) cursorPos.x = maxsize.x;
if( cursorPos.x < 0f ) cursorPos.x = 0f; if( cursorPos.x < 0f ) cursorPos.x = 0f;
if( cursorPos.y > maxsize.y ) cursorPos.y = maxsize.y; if( cursorPos.y > maxsize.y ) cursorPos.y = maxsize.y;
@ -123,39 +154,39 @@ public class VRMouseManager {
} }
} }
public static Vector2f getCursorPosition() { public Vector2f getCursorPosition() {
if( VRApplication.isInVR() ) { if( application.isInVR() ) {
return cursorPos; return cursorPos;
} }
return VRApplication.getMainVRApp().getInputManager().getCursorPosition(); return application.getInputManager().getCursorPosition();
} }
public static void centerMouse() { public void centerMouse() {
// set mouse in center of the screen if newly added // set mouse in center of the screen if newly added
Vector2f size = VRGuiManager.getCanvasSize(); Vector2f size = application.getVRGUIManager().getCanvasSize();
MouseInput mi = VRApplication.getMainVRApp().getContext().getMouseInput(); MouseInput mi = application.getContext().getMouseInput();
AppSettings as = VRApplication.getMainVRApp().getContext().getSettings(); AppSettings as = application.getContext().getSettings();
if( mi instanceof GlfwMouseInputVR ) ((GlfwMouseInputVR)mi).setCursorPosition((int)(as.getWidth() / 2f), (int)(as.getHeight() / 2f)); if( mi instanceof GlfwMouseInputVR ) ((GlfwMouseInputVR)mi).setCursorPosition((int)(as.getWidth() / 2f), (int)(as.getHeight() / 2f));
if( VRApplication.isInVR() ) { if( application.isInVR() ) {
cursorPos.x = size.x / 2f; cursorPos.x = size.x / 2f;
cursorPos.y = size.y / 2f; cursorPos.y = size.y / 2f;
recentCenterCount = 2; recentCenterCount = 2;
} }
} }
protected static void update(float tpf) { protected void update(float tpf) {
// if we are showing the cursor, add our picture as it // if we are showing the cursor, add our picture as it
VRApplication vrapp = VRApplication.getMainVRApp();
if( vrapp.getInputManager().isCursorVisible() ) { if( application.getInputManager().isCursorVisible() ) {
if( mouseImage.getParent() == null ) { if( mouseImage.getParent() == null ) {
VRApplication.getMainVRApp().getGuiNode().attachChild(mouseImage); application.getGuiNode().attachChild(mouseImage);
centerMouse(); centerMouse();
// the "real" mouse pointer should stay hidden // the "real" mouse pointer should stay hidden
org.lwjgl.glfw.GLFW.glfwSetInputMode(((LwjglWindowVR)VRApplication.getMainVRApp().getContext()).getWindowHandle(), org.lwjgl.glfw.GLFW.glfwSetInputMode(((LwjglWindowVR)application.getContext()).getWindowHandle(),
org.lwjgl.glfw.GLFW.GLFW_CURSOR, org.lwjgl.glfw.GLFW.GLFW_CURSOR_DISABLED); org.lwjgl.glfw.GLFW.GLFW_CURSOR, org.lwjgl.glfw.GLFW.GLFW_CURSOR_DISABLED);
} }
// handle mouse movements, which may be in addition to (or exclusive from) tracked movement // handle mouse movements, which may be in addition to (or exclusive from) tracked movement
MouseInput mi = VRApplication.getMainVRApp().getContext().getMouseInput(); MouseInput mi = application.getContext().getMouseInput();
if( mi instanceof GlfwMouseInputVR ) { if( mi instanceof GlfwMouseInputVR ) {
if( recentCenterCount <= 0 ) { if( recentCenterCount <= 0 ) {
//Vector2f winratio = VRGuiManager.getCanvasToWindowRatio(); //Vector2f winratio = VRGuiManager.getCanvasToWindowRatio();
@ -163,14 +194,16 @@ public class VRMouseManager {
cursorPos.y += ((GlfwMouseInputVR)mi).getLastDeltaY();// * winratio.y; cursorPos.y += ((GlfwMouseInputVR)mi).getLastDeltaY();// * winratio.y;
if( cursorPos.x < 0f ) cursorPos.x = 0f; if( cursorPos.x < 0f ) cursorPos.x = 0f;
if( cursorPos.y < 0f ) cursorPos.y = 0f; if( cursorPos.y < 0f ) cursorPos.y = 0f;
if( cursorPos.x > VRGuiManager.getCanvasSize().x ) cursorPos.x = VRGuiManager.getCanvasSize().x; if( cursorPos.x > application.getVRGUIManager().getCanvasSize().x ) cursorPos.x = application.getVRGUIManager().getCanvasSize().x;
if( cursorPos.y > VRGuiManager.getCanvasSize().y ) cursorPos.y = VRGuiManager.getCanvasSize().y; if( cursorPos.y > application.getVRGUIManager().getCanvasSize().y ) cursorPos.y = application.getVRGUIManager().getCanvasSize().y;
} else recentCenterCount--; } else recentCenterCount--;
((GlfwMouseInputVR)mi).clearDeltas(); ((GlfwMouseInputVR)mi).clearDeltas();
} }
// ok, update the cursor graphic position // ok, update the cursor graphic position
Vector2f currentPos = getCursorPosition(); Vector2f currentPos = getCursorPosition();
mouseImage.setLocalTranslation(currentPos.x, currentPos.y - ySize, VRGuiManager.getGuiDistance() + 1f); mouseImage.setLocalTranslation(currentPos.x, currentPos.y - ySize, application.getVRGUIManager().getGuiDistance() + 1f);
mouseImage.updateGeometricState();
} else if( mouseImage.getParent() != null ) { } else if( mouseImage.getParent() != null ) {
mouseImage.removeFromParent(); mouseImage.removeFromParent();
} }

@ -7,9 +7,10 @@ package jmevr.util;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.math.Matrix4f; import com.jme3.math.Matrix4f;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.system.jopenvr.HmdMatrix34_t;
import com.jme3.system.jopenvr.HmdMatrix44_t;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import jopenvr.HmdMatrix34_t;
import jopenvr.HmdMatrix44_t;
/** /**
* *

@ -28,6 +28,9 @@ import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.shadow.DirectionalLightShadowFilter; import com.jme3.shadow.DirectionalLightShadowFilter;
import com.jme3.shadow.VRDirectionalLightShadowRenderer; import com.jme3.shadow.VRDirectionalLightShadowRenderer;
import com.jme3.system.jopenvr.JOpenVRLibrary;
import com.jme3.system.jopenvr.Texture_t;
import com.jme3.system.jopenvr.VRTextureBounds_t;
import com.jme3.system.lwjgl.LwjglWindow; import com.jme3.system.lwjgl.LwjglWindow;
import com.jme3.texture.FrameBuffer; import com.jme3.texture.FrameBuffer;
import com.jme3.texture.Image; import com.jme3.texture.Image;
@ -37,13 +40,9 @@ import com.jme3.ui.Picture;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.ptr.PointerByReference; import com.sun.jna.ptr.PointerByReference;
import static com.jme3.app.VRApplication.isInVR;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.util.logging.Logger;
import jopenvr.JOpenVRLibrary;
import jopenvr.Texture_t;
import jopenvr.VRTextureBounds_t;
import osvrrendermanageropengl.OSVR_RenderBufferOpenGL; import osvrrendermanageropengl.OSVR_RenderBufferOpenGL;
import osvrrendermanageropengl.OSVR_ViewportDescription; import osvrrendermanageropengl.OSVR_ViewportDescription;
import osvrrendermanageropengl.OsvrRenderManagerOpenGLLibrary; import osvrrendermanageropengl.OsvrRenderManagerOpenGLLibrary;
@ -54,6 +53,8 @@ import osvrrendermanageropengl.OsvrRenderManagerOpenGLLibrary;
*/ */
public class VRViewManager { public class VRViewManager {
private static final Logger logger = Logger.getLogger(VRViewManager.class.getName());
private final VRApplication app; private final VRApplication app;
private Camera camLeft,camRight; private Camera camLeft,camRight;
private ViewPort viewPortLeft, viewPortRight; private ViewPort viewPortLeft, viewPortRight;
@ -112,7 +113,7 @@ public class VRViewManager {
private void initTextureSubmitStructs() { private void initTextureSubmitStructs() {
texTypeLeft = new Texture_t(); texTypeLeft = new Texture_t();
texTypeRight = new Texture_t(); texTypeRight = new Texture_t();
if( VRApplication.getVRHardware() instanceof OpenVR ) { if( app.getVRHardware() instanceof OpenVR ) {
texBoundsLeft = new VRTextureBounds_t(); texBoundsLeft = new VRTextureBounds_t();
texBoundsRight = new VRTextureBounds_t(); texBoundsRight = new VRTextureBounds_t();
// left eye // left eye
@ -146,7 +147,7 @@ public class VRViewManager {
texTypeRight.setAutoRead(false); texTypeRight.setAutoRead(false);
texTypeRight.setAutoWrite(false); texTypeRight.setAutoWrite(false);
texTypeRight.handle = -1; texTypeRight.handle = -1;
} else if( VRApplication.getVRHardware() instanceof OSVR ) { } else if( app.getVRHardware() instanceof OSVR ) {
// must be OSVR // must be OSVR
osvr_renderBuffer = new OSVR_RenderBufferOpenGL.ByValue[2]; osvr_renderBuffer = new OSVR_RenderBufferOpenGL.ByValue[2];
osvr_renderBuffer[OSVR.EYE_LEFT] = new OSVR_RenderBufferOpenGL.ByValue(); osvr_renderBuffer[OSVR.EYE_LEFT] = new OSVR_RenderBufferOpenGL.ByValue();
@ -182,16 +183,16 @@ public class VRViewManager {
private void registerOSVRBuffer(OSVR_RenderBufferOpenGL.ByValue buf) { private void registerOSVRBuffer(OSVR_RenderBufferOpenGL.ByValue buf) {
OsvrRenderManagerOpenGLLibrary.osvrRenderManagerStartRegisterRenderBuffers(grabRBS); OsvrRenderManagerOpenGLLibrary.osvrRenderManagerStartRegisterRenderBuffers(grabRBS);
OsvrRenderManagerOpenGLLibrary.osvrRenderManagerRegisterRenderBufferOpenGL(grabRBS.getValue(), buf); OsvrRenderManagerOpenGLLibrary.osvrRenderManagerRegisterRenderBufferOpenGL(grabRBS.getValue(), buf);
OsvrRenderManagerOpenGLLibrary.osvrRenderManagerFinishRegisterRenderBuffers(((OSVR)VRApplication.getVRHardware()).getCompositor(), grabRBS.getValue(), (byte)0); OsvrRenderManagerOpenGLLibrary.osvrRenderManagerFinishRegisterRenderBuffers(((OSVR)app.getVRHardware()).getCompositor(), grabRBS.getValue(), (byte)0);
} }
public void sendTextures() { public void sendTextures() {
if( isInVR() ) { if( app.isInVR() ) {
VRAPI api = VRApplication.getVRHardware(); VRAPI api = app.getVRHardware();
if( api.getCompositor() != null ) { if( api.getCompositor() != null ) {
// using the compositor... // using the compositor...
int errl = 0, errr = 0; int errl = 0, errr = 0;
if( VRApplication.isInstanceVRRendering() ) { if( app.isInstanceVRRendering() ) {
if( texTypeLeft.handle == -1 || texTypeLeft.handle != getFullTexId() ) { if( texTypeLeft.handle == -1 || texTypeLeft.handle != getFullTexId() ) {
texTypeLeft.handle = getFullTexId(); texTypeLeft.handle = getFullTexId();
if( texTypeLeft.handle != -1 ) { if( texTypeLeft.handle != -1 ) {
@ -268,32 +269,36 @@ public class VRViewManager {
return viewPortRight; return viewPortRight;
} }
public void initialize(VRApplication app) { public void initialize() {
logger.config("Initializing VR view manager.");
initTextureSubmitStructs(); initTextureSubmitStructs();
setupCamerasAndViews(); setupCamerasAndViews();
setupVRScene(); setupVRScene();
moveScreenProcessingToEyes(); moveScreenProcessingToEyes();
if( VRApplication.hasTraditionalGUIOverlay() ) { if( app.hasTraditionalGUIOverlay() ) {
VRMouseManager.init();
app.getVRMouseManager().init();
// update the pose to position the gui correctly on start // update the pose to position the gui correctly on start
update(0f); update(0f);
VRGuiManager.positionGui(); app.getVRGUIManager().positionGui();
} }
// if we are OSVR, our primary mirror window needs to be the same size as the render manager's output... // if we are OSVR, our primary mirror window needs to be the same size as the render manager's output...
if( VRApplication.getVRHardware() instanceof OSVR ) { if( app.getVRHardware() instanceof OSVR ) {
int origWidth = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getWidth(); int origWidth = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getWidth();
int origHeight = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getHeight(); int origHeight = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getHeight();
long window = ((LwjglWindow)VRApplication.getMainVRApp().getContext()).getWindowHandle(); long window = ((LwjglWindow)app.getContext()).getWindowHandle();
Vector2f windowSize = new Vector2f(); Vector2f windowSize = new Vector2f();
((OSVR)VRApplication.getVRHardware()).getRenderSize(windowSize); ((OSVR)app.getVRHardware()).getRenderSize(windowSize);
windowSize.x = Math.max(windowSize.x * 2f, camLeft.getWidth()); windowSize.x = Math.max(windowSize.x * 2f, camLeft.getWidth());
org.lwjgl.glfw.GLFW.glfwSetWindowSize(window, (int)windowSize.x, (int)windowSize.y); org.lwjgl.glfw.GLFW.glfwSetWindowSize(window, (int)windowSize.x, (int)windowSize.y);
VRApplication.getMainVRApp().getContext().getSettings().setResolution((int)windowSize.x, (int)windowSize.y); app.getContext().getSettings().setResolution((int)windowSize.x, (int)windowSize.y);
VRApplication.getMainVRApp().reshape((int)windowSize.x, (int)windowSize.y); app.reshape((int)windowSize.x, (int)windowSize.y);
org.lwjgl.glfw.GLFW.glfwSetWindowPos(window, origWidth - (int)windowSize.x, 32); org.lwjgl.glfw.GLFW.glfwSetWindowPos(window, origWidth - (int)windowSize.x, 32);
//FIXME: Need to update LWJGL org.lwjgl.glfw.GLFW.glfwFocusWindow(window);
//org.lwjgl.glfw.GLFW.glfwFocusWindow(window);
org.lwjgl.glfw.GLFW.glfwSetCursorPos(window, origWidth / 2.0, origHeight / 2.0); org.lwjgl.glfw.GLFW.glfwSetCursorPos(window, origWidth / 2.0, origHeight / 2.0);
} }
@ -310,7 +315,7 @@ public class VRViewManager {
private void prepareCameraSize(Camera cam, float xMult) { private void prepareCameraSize(Camera cam, float xMult) {
Vector2f size = new Vector2f(); Vector2f size = new Vector2f();
VRAPI vrhmd = VRApplication.getVRHardware(); VRAPI vrhmd = app.getVRHardware();
if( vrhmd == null ) { if( vrhmd == null ) {
size.x = 1280f; size.x = 1280f;
@ -326,7 +331,7 @@ public class VRViewManager {
size.y = app.getContext().getSettings().getHeight(); size.y = app.getContext().getSettings().getHeight();
} }
if( VRApplication.isInstanceVRRendering() ) size.x *= 2f; if( app.isInstanceVRRendering() ) size.x *= 2f;
// other adjustments // other adjustments
size.x *= xMult; size.x *= xMult;
@ -341,7 +346,7 @@ public class VRViewManager {
*/ */
private void setupVRScene(){ private void setupVRScene(){
// no special scene to setup if we are doing instancing // no special scene to setup if we are doing instancing
if( VRApplication.isInstanceVRRendering() ) { if( app.isInstanceVRRendering() ) {
// distortion has to be done with compositor here... we want only one pass on our end! // distortion has to be done with compositor here... we want only one pass on our end!
if( app.getContext().getSettings().isSwapBuffers() ) { if( app.getContext().getSettings().isSwapBuffers() ) {
setupMirrorBuffers(app.getCamera(), dualEyeTex, true); setupMirrorBuffers(app.getCamera(), dualEyeTex, true);
@ -359,17 +364,17 @@ public class VRViewManager {
app.getViewPort().detachScene(app.getGuiNode()); app.getViewPort().detachScene(app.getGuiNode());
// only setup distortion scene if compositor isn't running (or using custom mesh distortion option) // only setup distortion scene if compositor isn't running (or using custom mesh distortion option)
if( VRApplication.getVRHardware().getCompositor() == null ) { if( app.getVRHardware().getCompositor() == null ) {
Node distortionScene = new Node(); Node distortionScene = new Node();
Material leftMat = new Material(app.getAssetManager(), "Common/MatDefs/VR/OpenVR.j3md"); Material leftMat = new Material(app.getAssetManager(), "Common/MatDefs/VR/OpenVR.j3md");
leftMat.setTexture("Texture", leftEyeTex); leftMat.setTexture("Texture", leftEyeTex);
Geometry leftEye = new Geometry("box", MeshUtil.setupDistortionMesh(JOpenVRLibrary.EVREye.EVREye_Eye_Left)); Geometry leftEye = new Geometry("box", MeshUtil.setupDistortionMesh(JOpenVRLibrary.EVREye.EVREye_Eye_Left, app));
leftEye.setMaterial(leftMat); leftEye.setMaterial(leftMat);
distortionScene.attachChild(leftEye); distortionScene.attachChild(leftEye);
Material rightMat = new Material(app.getAssetManager(), "Common/MatDefs/VR/OpenVR.j3md"); Material rightMat = new Material(app.getAssetManager(), "Common/MatDefs/VR/OpenVR.j3md");
rightMat.setTexture("Texture", rightEyeTex); rightMat.setTexture("Texture", rightEyeTex);
Geometry rightEye = new Geometry("box", MeshUtil.setupDistortionMesh(JOpenVRLibrary.EVREye.EVREye_Eye_Right)); Geometry rightEye = new Geometry("box", MeshUtil.setupDistortionMesh(JOpenVRLibrary.EVREye.EVREye_Eye_Right, app));
rightEye.setMaterial(rightMat); rightEye.setMaterial(rightMat);
distortionScene.attachChild(rightEye); distortionScene.attachChild(rightEye);
@ -394,7 +399,7 @@ public class VRViewManager {
public void update(float tpf) { public void update(float tpf) {
// grab the observer // grab the observer
Object obs = VRApplication.getObserver(); Object obs = app.getObserver();
Quaternion objRot; Quaternion objRot;
Vector3f objPos; Vector3f objPos;
if( obs instanceof Camera ) { if( obs instanceof Camera ) {
@ -405,7 +410,7 @@ public class VRViewManager {
objPos = ((Spatial)obs).getWorldTranslation(); objPos = ((Spatial)obs).getWorldTranslation();
} }
// grab the hardware handle // grab the hardware handle
VRAPI dev = VRApplication.getVRHardware(); VRAPI dev = app.getVRHardware();
if( dev != null ) { if( dev != null ) {
// update the HMD's position & orientation // update the HMD's position & orientation
dev.updatePose(); dev.updatePose();
@ -424,14 +429,14 @@ public class VRViewManager {
camRight.setFrame(objPos, objRot); camRight.setFrame(objPos, objRot);
} }
if( VRApplication.hasTraditionalGUIOverlay() ) { if( app.hasTraditionalGUIOverlay() ) {
// update the mouse? // update the mouse?
VRMouseManager.update(tpf); app.getVRMouseManager().update(tpf);
// update GUI position? // update GUI position?
if( VRGuiManager.wantsReposition || VRGuiManager.getPositioningMode() != VRGuiManager.POSITIONING_MODE.MANUAL ) { if( app.getVRGUIManager().wantsReposition || app.getVRGUIManager().getPositioningMode() != VRGuiManager.POSITIONING_MODE.MANUAL ) {
VRGuiManager.positionGuiNow(tpf); app.getVRGUIManager().positionGuiNow(tpf);
VRGuiManager.updateGuiQuadGeometricState(); app.getVRGUIManager().updateGuiQuadGeometricState();
} }
} }
} }
@ -449,8 +454,8 @@ public class VRViewManager {
*/ */
public void moveScreenProcessingToEyes() { public void moveScreenProcessingToEyes() {
if( viewPortRight == null ) return; if( viewPortRight == null ) return;
syncScreenProcessing(VRApplication.getMainVRApp().getViewPort()); syncScreenProcessing(app.getViewPort());
VRApplication.getMainVRApp().getViewPort().clearProcessors(); app.getViewPort().clearProcessors();
} }
/* /*
@ -521,14 +526,14 @@ public class VRViewManager {
float fNear = origCam.getFrustumNear(); float fNear = origCam.getFrustumNear();
// if we are using OSVR get the eye info here // if we are using OSVR get the eye info here
if( VRApplication.getVRHardware() instanceof OSVR ) { if( app.getVRHardware() instanceof OSVR ) {
((OSVR)VRApplication.getVRHardware()).getEyeInfo(); ((OSVR)app.getVRHardware()).getEyeInfo();
} }
// restore frustrum on distortion scene cam, if needed // restore frustrum on distortion scene cam, if needed
if( VRApplication.isInstanceVRRendering() ) { if( app.isInstanceVRRendering() ) {
camLeft = origCam; camLeft = origCam;
} else if( VRApplication.compositorAllowed() == false ) { } else if( app.compositorAllowed() == false ) {
origCam.setFrustumFar(100f); origCam.setFrustumFar(100f);
origCam.setFrustumNear(1f); origCam.setFrustumNear(1f);
camLeft = origCam.clone(); camLeft = origCam.clone();
@ -537,38 +542,38 @@ public class VRViewManager {
camLeft = origCam.clone(); camLeft = origCam.clone();
} }
camLeft.setFrustumPerspective(VRApplication.DEFAULT_FOV, VRApplication.DEFAULT_ASPECT, fNear, fFar); camLeft.setFrustumPerspective(app.DEFAULT_FOV, app.DEFAULT_ASPECT, fNear, fFar);
prepareCameraSize(camLeft, 1f); prepareCameraSize(camLeft, 1f);
if( VRApplication.getVRHardware() != null ) camLeft.setProjectionMatrix(VRApplication.getVRHardware().getHMDMatrixProjectionLeftEye(camLeft)); if( app.getVRHardware() != null ) camLeft.setProjectionMatrix(app.getVRHardware().getHMDMatrixProjectionLeftEye(camLeft));
//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( VRApplication.isInstanceVRRendering() == false ) { if( app.isInstanceVRRendering() == false ) {
viewPortLeft = setupViewBuffers(camLeft, LEFT_VIEW_NAME); viewPortLeft = setupViewBuffers(camLeft, LEFT_VIEW_NAME);
camRight = camLeft.clone(); camRight = camLeft.clone();
if( VRApplication.getVRHardware() != null ) camRight.setProjectionMatrix(VRApplication.getVRHardware().getHMDMatrixProjectionRightEye(camRight)); if( app.getVRHardware() != null ) camRight.setProjectionMatrix(app.getVRHardware().getHMDMatrixProjectionRightEye(camRight));
viewPortRight = setupViewBuffers(camRight, RIGHT_VIEW_NAME); viewPortRight = setupViewBuffers(camRight, RIGHT_VIEW_NAME);
} else { } else {
viewPortLeft = app.getViewPort(); viewPortLeft = app.getViewPort();
viewPortLeft.attachScene(VRApplication.getMainVRApp().getRootNode()); viewPortLeft.attachScene(app.getRootNode());
camRight = camLeft.clone(); camRight = camLeft.clone();
if( VRApplication.getVRHardware() != null ) camRight.setProjectionMatrix(VRApplication.getVRHardware().getHMDMatrixProjectionRightEye(camRight)); if( app.getVRHardware() != null ) camRight.setProjectionMatrix(app.getVRHardware().getHMDMatrixProjectionRightEye(camRight));
org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_CLIP_DISTANCE0); org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_CLIP_DISTANCE0);
//FIXME: Fix with JMonkey next release //FIXME: [jme-vr] Fix with JMonkey next release
//RenderManager._VRInstancing_RightCamProjection = camRight.getViewProjectionMatrix(); //RenderManager._VRInstancing_RightCamProjection = camRight.getViewProjectionMatrix();
setupFinalFullTexture(app.getViewPort().getCamera()); setupFinalFullTexture(app.getViewPort().getCamera());
} }
// setup gui // setup gui
VRGuiManager.setupGui(camLeft, camRight, viewPortLeft, viewPortRight); app.getVRGUIManager().setupGui(camLeft, camRight, viewPortLeft, viewPortRight);
if( VRApplication.getVRHardware() != null ) { if( app.getVRHardware() != null ) {
// call these to cache the results internally // call these to cache the results internally
VRApplication.getVRHardware().getHMDMatrixPoseLeftEye(); app.getVRHardware().getHMDMatrixPoseLeftEye();
VRApplication.getVRHardware().getHMDMatrixPoseRightEye(); app.getVRHardware().getHMDMatrixPoseRightEye();
} }
} }
@ -588,9 +593,11 @@ public class VRViewManager {
} }
pic.setQueueBucket(Bucket.Opaque); pic.setQueueBucket(Bucket.Opaque);
pic.setTexture(app.getAssetManager(), (Texture2D)tex, false); pic.setTexture(app.getAssetManager(), (Texture2D)tex, false);
pic.updateGeometricState();
viewPort.attachScene(pic); viewPort.attachScene(pic);
viewPort.setOutputFrameBuffer(null); viewPort.setOutputFrameBuffer(null);
pic.updateGeometricState();
return viewPort; return viewPort;
} }

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Loading…
Cancel
Save