@Override public Matrix4f getPose(){ if (environment != null){ if (hardware != null){ return ((OpenVR)environment.getVRHardware()).poseMatrices[controllerIndex]; } else { throw new IllegalStateException("No underlying VR API."); } } else { throw new IllegalStateException("VR tracked device is not attached to any environment."); } }
@Override public void cleanup() { if( environment.getVRHardware() != null ) { environment.getVRHardware().destroy(); } this.application = null; this.stateManager = null; }
@Override public boolean isInputDeviceTracking(int index) { if( index < 0 || index >= controllerCount ){ return false; } if (environment != null){ if (environment.getVRHardware() instanceof OpenVR){ return ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[controllerIndex[index]].bPoseIsValid != 0; } else { throw new IllegalStateException("VR hardware "+environment.getVRHardware().getClass().getSimpleName()+" is not a subclass of "+OpenVR.class.getSimpleName()); } } else { throw new IllegalStateException("VR input is not attached to a VR environment."); } }
@Override public boolean isInputDeviceTracking(int index) { if (index < 0 || index >= controllerCount) { return false; } if (environment != null) { if (environment.getVRHardware() instanceof LWJGLOpenVR) { return ((LWJGLOpenVR) environment.getVRHardware()).hmdTrackedDevicePoses[controllerIndex[index]].bPoseIsValid(); } else { throw new IllegalStateException("VR hardware " + environment.getVRHardware().getClass().getSimpleName() + " is not a subclass of " + LWJGLOpenVR.class.getSimpleName()); } } else { throw new IllegalStateException("VR input is not attached to a VR environment."); } }
/** * Get the VR underlying hardware. * @return the VR underlying hardware. */ public VRAPI getVRHardware() { return getVREnvironment().getVRHardware(); }
@Override public Matrix4f getPose(){ if (environment != null){ if (hardware != null){ return ((LWJGLOpenVR)environment.getVRHardware()).getPoseMatrices()[controllerIndex]; } else { throw new IllegalStateException("No underlying VR API."); } } else { throw new IllegalStateException("VR tracked device is not attached to any environment."); } }
public OculusViewManager(VREnvironment environment) { this.environment = environment; VRAPI hardware = environment.getVRHardware(); Objects.requireNonNull(hardware, "Attached VR Hardware cannot be null"); if (!(hardware instanceof OculusVR)) { throw new IllegalStateException("Cannot use Oculus VR view manager on non-Oculus hardware state!"); } this.hardware = (OculusVR) hardware; if (!environment.compositorAllowed()) { throw new UnsupportedOperationException("Cannot render without compositor on LibOVR"); } }
@Override public Quaternion getOrientation(int index) { if( isInputDeviceTracking(index) == false ){ return null; } if (environment != null){ if (environment.getVRHardware() instanceof OpenVR){ index = controllerIndex[index]; VRUtil.convertMatrix4toQuat(((OpenVR)environment.getVRHardware()).poseMatrices[index], rotStore[index]); return rotStore[index]; } else { throw new IllegalStateException("VR hardware "+environment.getVRHardware().getClass().getSimpleName()+" is not a subclass of "+OpenVR.class.getSimpleName()); } } else { throw new IllegalStateException("VR input is not attached to a VR environment."); } }
@Override public Quaternion getOrientation(int index) { if (isInputDeviceTracking(index) == false) { return null; } if (environment != null) { if (environment.getVRHardware() instanceof LWJGLOpenVR) { index = controllerIndex[index]; VRUtil.convertMatrix4toQuat(((LWJGLOpenVR) environment.getVRHardware()).poseMatrices[index], rotStore[index]); return rotStore[index]; } else { throw new IllegalStateException("VR hardware " + environment.getVRHardware().getClass().getSimpleName() + " is not a subclass of " + LWJGLOpenVR.class.getSimpleName()); } } else { throw new IllegalStateException("VR input is not attached to a VR environment."); } }
@Override public Vector3f getPosition(int index) { if (isInputDeviceTracking(index) == false) { return null; } if (environment != null) { if (environment.getVRHardware() instanceof LWJGLOpenVR) { // the hmdPose comes in rotated funny, fix that here index = controllerIndex[index]; ((LWJGLOpenVR) environment.getVRHardware()).poseMatrices[index].toTranslationVector(posStore[index]); posStore[index].x = -posStore[index].x; posStore[index].z = -posStore[index].z; return posStore[index]; } else { throw new IllegalStateException("VR hardware " + environment.getVRHardware().getClass().getSimpleName() + " is not a subclass of " + LWJGLOpenVR.class.getSimpleName()); } } else { throw new IllegalStateException("VR input is not attached to a VR environment."); } }
/** * Get the VR dedicated input. * @return the VR dedicated input. */ public VRInputAPI getVRinput() { if( getVREnvironment().getVRHardware() == null ){ return null; } return getVREnvironment().getVRHardware().getVRinput(); }
@Override public Vector3f getAngularVelocity(int controllerIndex) { if (environment != null) { if (environment.getVRHardware() instanceof LWJGLOpenVR) { int index = LWJGLOpenVRInput.controllerIndex[controllerIndex]; HmdVector3 tempVec = ((LWJGLOpenVR) environment.getVRHardware()).hmdTrackedDevicePoses[index].vAngularVelocity(); // needsNewVelocity[index] = false; // } tempVel.x = tempVec.v(0); tempVel.y = tempVec.v(1); tempVel.z = tempVec.v(2); return tempVel; } else { throw new IllegalStateException("VR hardware " + environment.getVRHardware().getClass().getSimpleName() + " is not a subclass of " + LWJGLOpenVR.class.getSimpleName()); } } else { throw new IllegalStateException("VR input is not attached to a VR environment."); } }
@Override public boolean isInputFocused() { if (environment != null){ return ((VR_IVRSystem_FnTable)environment.getVRHardware().getVRSystem()).IsInputAvailable.apply() == 0; } else { throw new IllegalStateException("VR input is not attached to a VR environment."); } }
/** * Reset headset pose if seating experience. */ public void resetSeatedPose(){ if( vrSupportedOS == false || isSeatedExperience() == false ){ return; } getVRHardware().reset(); }
@Override public void triggerHapticPulse(int controllerIndex, float seconds) { if( environment.isInVR() == false || isInputDeviceTracking(controllerIndex) == false ){ return; } // apparently only axis ID of 0 works ((VR_IVRSystem_FnTable)environment.getVRHardware().getVRSystem()).TriggerHapticPulse.apply(OpenVRInput.controllerIndex[controllerIndex], 0, (short)Math.round(3f * seconds / 1e-3f)); }
@Override public void updateControllerStates() { if (environment != null){ for(int i=0;i<controllerCount;i++) { int index = controllerIndex[i]; ((OpenVR)environment.getVRHardware()).getVRSystem().GetControllerState.apply(index, cStates[index], 64); cStates[index].readField("ulButtonPressed"); cStates[index].readField("rAxis"); needsNewVelocity[index] = true; needsNewAngVelocity[index] = true; } } else { throw new IllegalStateException("VR input is not attached to a VR environment."); } }
/** * Register the OSVR OpenGL buffer. * @param buf the OSVR OpenGL buffer. */ private void registerOSVRBuffer(OSVR_RenderBufferOpenGL.ByValue buf) { if (environment != null){ OsvrRenderManagerOpenGLLibrary.osvrRenderManagerStartRegisterRenderBuffers(grabRBS); OsvrRenderManagerOpenGLLibrary.osvrRenderManagerRegisterRenderBufferOpenGL(grabRBS.getValue(), buf); OsvrRenderManagerOpenGLLibrary.osvrRenderManagerFinishRegisterRenderBuffers(((OSVR)environment.getVRHardware()).getCompositor(), grabRBS.getValue(), (byte)0); } else { throw new IllegalStateException("This VR view manager is not attached to any VR environment."); } }
public static void testInitHmd(){ VREnvironment environment = new VREnvironment(new AppSettings(true)); environment.initialize(); OpenVR openVr = (OpenVR) environment.getVRHardware(); System.out.println(openVr.getName()); openVr.updatePose(); openVr.destroy(); } }
private OSVR_ClientInterface getInterface(byte[] str) { PointerByReference pbr = new PointerByReference(); OsvrClientKitLibrary.osvrClientGetInterface((OsvrClientKitLibrary.OSVR_ClientContext)environment.getVRHardware().getVRSystem(), str, pbr); return new OSVR_ClientInterface(pbr.getValue()); }
/** * Get the observer final rotation within the scene. * @return the observer final rotation within the scene. * @see #getFinalObserverPosition() */ public Quaternion getFinalObserverRotation() { if( environment.getVRViewManager() == null ) { if( environment.getObserver() == null ) { return environment.getCamera().getRotation(); } else { return ((Spatial)environment.getObserver()).getWorldRotation(); } } if( environment.getObserver() == null ) { tempq.set(environment.getDummyCamera().getRotation()); } else { tempq.set(((Spatial)environment.getObserver()).getWorldRotation()); } return tempq.multLocal(environment.getVRHardware().getOrientation()); }