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(); } }
if (environment.getApplication() != null){ Camera origCam = environment.getCamera(); float fFar = origCam.getFrustumFar(); float fNear = origCam.getFrustumNear(); if( environment.getVRHardware() instanceof OSVR ) { ((OSVR)environment.getVRHardware()).getEyeInfo(); if( environment.isInstanceRendering() ) { leftCamera = origCam; } else if( environment.compositorAllowed() == false ) { origCam.setFrustumFar(100f); origCam.setFrustumNear(1f); leftCamera.setFrustumPerspective(environment.getDefaultFOV(), environment.getDefaultAspect(), fNear, fFar); if( environment.getVRHardware() != null ) leftCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionLeftEye(leftCamera)); if( !environment.isInstanceRendering()) { leftViewPort = setupViewBuffers(leftCamera, LEFT_VIEW_NAME); rightCamera = leftCamera.clone(); if( environment.getVRHardware() != null ){ rightCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(rightCamera)); leftViewPort = environment.getApplication().getViewPort(); if( environment.getVRHardware() != null ){ rightCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(rightCamera));
/** * 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()); }
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"); } }
/** * Get the {@link Camera camera} used for rendering. * If the VR mode is {@link #isInVR() active}, this method return a dummy camera, otherwise, * this method return the camera of the attached application. * @return the camera attached used for rendering. */ public Camera getCamera() { if( isInVR() && getVRViewManager() != null && getVRViewManager().getLeftCamera() != null ) { return getDummyCamera(); } return application.getCamera(); }
@Override public Vector2f getCursorPosition() { if (environment != null){ if (environment.getApplication() != null){ if( environment.isInVR() ) { return cursorPos; } return environment.getApplication().getInputManager().getCursorPosition(); } else { throw new IllegalStateException("This VR environment is not attached to any application."); } } else { throw new IllegalStateException("This VR view manager is not attached to any VR environment."); } }
Camera origCam = environment.getCamera(); float fFar = origCam.getFrustumFar(); float fNear = origCam.getFrustumNear(); if (environment.isInstanceRendering()) { leftCamera = origCam; } else { if (environment.getVRHardware() != null) { getLeftCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionLeftEye(getLeftCamera())); if (!environment.isInstanceRendering()) { leftViewPort = setupViewBuffers(getLeftCamera(), LEFT_VIEW_NAME); rightCamera = getLeftCamera().clone(); if (environment.getVRHardware() != null) { getRightCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(getRightCamera())); } else if (environment.getApplication() != null) { throw new UnsupportedOperationException("Not yet implemented!"); } else { environment.getVRGUIManager().setupGui(getLeftCamera(), getRightCamera(), getLeftViewPort(), getRightViewPort()); } else { throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
if (getVREnvironment().getApplication() != null){ if( getVREnvironment().isInVR() == false || getVREnvironment().getVRinput() == null || getVREnvironment().getVRinput().isInputDeviceTracking(inputIndex) == false ){ return; tpDelta = getVREnvironment().getVRinput().getAxis(inputIndex, VRInputType.ViveTrackpadAxis); } else { tpDelta = getVREnvironment().getVRinput().getAxisDeltaSinceLastCall(inputIndex, VRInputType.ViveTrackpadAxis); if( getVREnvironment().getApplication().getInputManager().isCursorVisible() ) { int index = (avgCounter+1) % AVERAGE_AMNT; lastXmv[index] = Xamount * 133f; cursorPos.x -= avg(lastXmv); cursorPos.y -= avg(lastYmv); Vector2f maxsize = getVREnvironment().getVRGUIManager().getCanvasSize();
if (!environment.isInitialized()){ environment.initialize(); if (environment.isInitialized()){ environment.atttach(this, stateManager.getApplication()); } else { logger.severe("Cannot attach VR environment to the VR app state as its not initialized."); if( environment.isInVR() && !environment.compositorAllowed() ) { if (!environment.isInVR()){ logger.config("Cannot switch to VR mode (VR disabled by user)."); } else if (!environment.compositorAllowed()){ logger.warning("Cannot switch to VR mode (VR not supported)."); if( !environment.isInVR() ) { settings.setBitsPerPixel(32); settings.setFrameRate(0); settings.setFrequency(environment.getVRHardware().getDisplayFrequency()); settings.setFullscreen(false); settings.setVSync(false); // stop vsyncing on primary monitor! settings.setSwapBuffers(environment.isSwapBuffers());
@Override public void update(float tpf) { // update VR pose & cameras if( environment.getVRViewManager() != null ) { environment.getVRViewManager().update(tpf); } else if( environment.getObserver() != null ) { environment.getCamera().setFrame(((Spatial)environment.getObserver()).getWorldTranslation(), ((Spatial)environment.getObserver()).getWorldRotation()); } if( environment.isInVR() == false || environment.getVRGUIManager().getPositioningMode() == VRGUIPositioningMode.MANUAL ) { // 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 // TODO isn't this done by SimpleApplication? for (Spatial spatial : application.getGuiViewPort().getScenes()) { //spatial.updateLogicalState(tpf); spatial.updateGeometricState(); } } // use the analog control on the first tracked controller to push around the mouse environment.getVRMouseManager().updateAnalogAsMouse(0, null, null, null, tpf); }
Object obs = environment.getObserver(); Quaternion objRot; Vector3f objPos; VRAPI dev = environment.getVRHardware(); if( dev != null ) { if( environment.hasTraditionalGUIOverlay() ) { environment.getVRMouseManager().update(tpf); if( environment.getVRGUIManager().isWantsReposition() || environment.getVRGUIManager().getPositioningMode() != VRGUIPositioningMode.MANUAL ) { environment.getVRGUIManager().positionGuiNow(tpf); environment.getVRGUIManager().updateGuiQuadGeometricState();
Object obs = environment.getObserver(); Quaternion objRot; Vector3f objPos; if(!environment.isInstanceRendering()) { // We use the app camera as the left camera here finalizeCamera(Vector3f.ZERO, objPos, environment.getApplication().getCamera()); if (environment.hasTraditionalGUIOverlay()) { environment.getVRMouseManager().update(tpf); if (environment.getVRGUIManager().isWantsReposition() || environment.getVRGUIManager().getPositioningMode() != VRGUIPositioningMode.MANUAL) { environment.getVRGUIManager().positionGuiNow(tpf); environment.getVRGUIManager().updateGuiQuadGeometricState();
private void prepareCameraSize(Camera cam, float xMult) { if (environment.getApplication() != null) { Vector2f size = new Vector2f(); VRAPI vrhmd = environment.getVRHardware(); if (size.x < environment.getApplication().getContext().getSettings().getWidth()) { size.x = environment.getApplication().getContext().getSettings().getWidth(); if (size.y < environment.getApplication().getContext().getSettings().getHeight()) { size.y = environment.getApplication().getContext().getSettings().getHeight(); if (environment.isInstanceRendering()) { size.x *= 2f;
@Override public Quaternion getFinalObserverRotation(int index) { OSVRViewManager vrvm = (OSVRViewManager)environment.getVRViewManager(); if( vrvm == null || isInputDeviceTracking(index) == false ) return null; Object obs = environment.getObserver(); if( obs instanceof Camera ) { tempq.set(((Camera)obs).getRotation()); } else { tempq.set(((Spatial)obs).getWorldRotation()); } return tempq.multLocal(getOrientation(index)); }
setupVRScene(); moveScreenProcessingToEyes(); if( environment.hasTraditionalGUIOverlay() ) { environment.getVRMouseManager().initialize(); environment.getVRGUIManager().positionGui(); if (environment.getApplication() != null){ if( environment.getVRHardware() instanceof OSVR ) { int origWidth = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getWidth(); int origHeight = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getHeight(); long window = ((LwjglWindow)environment.getApplication().getContext()).getWindowHandle(); Vector2f windowSize = new Vector2f(); ((OSVR)environment.getVRHardware()).getRenderSize(windowSize); windowSize.x = Math.max(windowSize.x * 2f, leftCamera.getWidth()); org.lwjgl.glfw.GLFW.glfwSetWindowSize(window, (int)windowSize.x, (int)windowSize.y); environment.getApplication().getContext().getSettings().setResolution((int)windowSize.x, (int)windowSize.y); if (environment.getApplication().getRenderManager() != null) { environment.getApplication().getRenderManager().notifyReshape((int)windowSize.x, (int)windowSize.y);
app.getCamera().setFrustumNear(fNear); if( environment.isInVR() ) { if( environment.getVRHardware() != null ) { environment.getVRHardware().initVRCompositor(environment.compositorAllowed()); } else { logger.warning("No VR system found."); environment.getVRViewManager().setResolutionMultiplier(resMult); if( environment.getVRViewManager() != null ) { environment.getVRViewManager().initialize();
/** * Get the GUI canvas size. This method return the size in pixels of the GUI available area within the VR view. * @return the GUI canvas size. This method return the size in pixels of the GUI available area within the VR view. */ public Vector2f getCanvasSize() { if (environment != null){ if (environment.getApplication() != null){ if( screenSize == null ) { if( environment.isInVR() && environment.getVRHardware() != null ) { screenSize = new Vector2f(); environment.getVRHardware().getRenderSize(screenSize); screenSize.multLocal(environment.getVRViewManager().getResolutionMuliplier()); } else { AppSettings as = environment.getApplication().getContext().getSettings(); screenSize = new Vector2f(as.getWidth(), as.getHeight()); } } return screenSize; } else { throw new IllegalStateException("VR GUI manager underlying environment is not attached to any application."); } } else { throw new IllegalStateException("VR GUI manager is not attached to any environment."); } }
/** * Handles moving filters from the main view to each eye */ public void moveScreenProcessingToEyes() { if( getRightViewPort() == null ){ return; } if (environment != null){ if (environment.getApplication() != null){ syncScreenProcessing(environment.getApplication().getViewPort()); environment.getApplication().getViewPort().clearProcessors(); } else { throw new IllegalStateException("This VR environment is not attached to any application."); } } else { throw new IllegalStateException("This VR view manager is not attached to any VR environment."); } }
@Override public void centerMouse() { if (environment != null){ if (environment.getApplication() != null){ // set mouse in center of the screen if newly added Vector2f size = environment.getVRGUIManager().getCanvasSize(); MouseInput mi = environment.getApplication().getContext().getMouseInput(); AppSettings as = environment.getApplication().getContext().getSettings(); if( mi instanceof GlfwMouseInputVR ) ((GlfwMouseInputVR)mi).setCursorPosition((int)(as.getWidth() / 2f), (int)(as.getHeight() / 2f)); if( environment.isInVR() ) { cursorPos.x = size.x / 2f; cursorPos.y = size.y / 2f; recentCenterCount = 2; } } else { throw new IllegalStateException("This VR environment is not attached to any application."); } } else { throw new IllegalStateException("This VR view manager is not attached to any VR environment."); } }
if (environment.getApplication() != null) { if (environment.isInstanceRendering()) { if (environment.getApplication().getContext().getSettings().isSwapBuffers()) { setupMirrorBuffers(environment.getCamera(), dualEyeTex, true); Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator(); while (spatialIter.hasNext()) { environment.getApplication().getViewPort().detachScene(spatialIter.next()); spatialIter = environment.getApplication().getGuiViewPort().getScenes().iterator(); while (spatialIter.hasNext()) { environment.getApplication().getGuiViewPort().detachScene(spatialIter.next()); if (environment.getApplication().getContext().getSettings().isSwapBuffers()) { setupMirrorBuffers(environment.getCamera(), leftEyeTexture, false);