@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."); } }
/** * 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."); } }
/** * Handles moving filters from the main view to each eye */ public void moveScreenProcessingToEyes() { if (environment != null){ if( getRightViewPort() == null ){ return; } if (environment.getApplication() != null){ syncScreenProcessing(environment.getApplication().getViewPort()); environment.getApplication().getViewPort().clearProcessors(); } else { throw new IllegalStateException("The VR environment is not attached to any application."); } } else { throw new IllegalStateException("This VR view manager is not attached to any VR environment."); } }
private ViewPort setupViewBuffers(Camera cam, String viewName) { // TODO this function is identical to that in VRViewManagerOpenVR; merge the two. if (environment != null) { if (environment.getApplication() != null) { ViewPort viewPort = environment.getApplication().getRenderManager().createPreView(viewName, cam); viewPort.setClearFlags(true, true, true); viewPort.setBackgroundColor(ColorRGBA.Black); Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator(); while (spatialIter.hasNext()) { viewPort.attachScene(spatialIter.next()); } // The viewbuffer to render into will be set during prerender. return viewPort; } 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."); } }
@Override public void initialize() { logger.config("Initializing VR mouse manager."); // load default mouseimage mouseImage = new Picture("mouse"); setImage("Common/Util/mouse.png"); // hide default cursor by making it invisible MouseInput mi = environment.getApplication().getContext().getMouseInput(); if( mi instanceof GlfwMouseInputVR ){ ((GlfwMouseInputVR)mi).hideActiveCursor(); } centerMouse(); logger.config("Initialized VR mouse manager [SUCCESS]"); }
/** * Get the ratio between the {@link #getCanvasSize() GUI canvas size} and the application main windows (if available) or the screen size. * @return the ratio between the {@link #getCanvasSize() GUI canvas size} and the application main windows (if available). * @see #getCanvasSize() */ public Vector2f getCanvasToWindowRatio() { if (environment != null){ if (environment.getApplication() != null){ if( ratio == null ) { ratio = new Vector2f(); Vector2f canvas = getCanvasSize(); int width = Integer.min(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getWidth(), environment.getApplication().getContext().getSettings().getWidth()); int height = Integer.min(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getHeight(), environment.getApplication().getContext().getSettings().getHeight()); ratio.x = Float.max(1f, canvas.x / width); ratio.y = Float.max(1f, canvas.y / height); } return ratio; } 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."); } }
private ViewPort setupViewBuffers(Camera cam, String viewName){ if (environment.getApplication() != null){ offBufferLeft.setColorTexture(offTex); ViewPort viewPort = environment.getApplication().getRenderManager().createPreView(viewName, cam); viewPort.setClearFlags(true, true, true); viewPort.setBackgroundColor(ColorRGBA.Black); Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator(); while(spatialIter.hasNext()){ viewPort.attachScene(spatialIter.next());
private ViewPort setupMirrorBuffers(Camera cam, Texture tex, boolean expand) { if (environment.getApplication() != null){ Camera clonecam = cam.clone(); ViewPort viewPort = environment.getApplication().getRenderManager().createPostView("MirrorView", clonecam); clonecam.setParallelProjection(true); viewPort.setClearFlags(true, true, true); pic.setTexture(environment.getApplication().getAssetManager(), (Texture2D)tex, false); viewPort.attachScene(pic); viewPort.setOutputFrameBuffer(null);
private ViewPort setupMirrorBuffers(Camera cam, Texture tex, boolean expand) { if (environment.getApplication() != null){ Camera clonecam = cam.clone(); ViewPort viewPort = environment.getApplication().getRenderManager().createPostView("MirrorView", clonecam); clonecam.setParallelProjection(true); viewPort.setClearFlags(true, true, true); pic.setTexture(environment.getApplication().getAssetManager(), (Texture2D)tex, false); viewPort.attachScene(pic); viewPort.setOutputFrameBuffer(null);
private ViewPort setupMirrorBuffers(Camera cam, Texture2D tex, boolean expand) { if (environment != null) { if (environment.getApplication() != null) { Camera clonecam = cam.clone(); ViewPort viewPort = environment.getApplication().getRenderManager().createPostView("MirrorView", clonecam); clonecam.setParallelProjection(true); viewPort.setClearFlags(true, true, true); viewPort.setBackgroundColor(ColorRGBA.Black); Picture pic = new Picture("fullscene"); pic.setLocalTranslation(-0.75f, -0.5f, 0f); if (expand) { pic.setLocalScale(3f, 1f, 1f); } else { pic.setLocalScale(1.5f, 1f, 1f); } pic.setQueueBucket(Bucket.Opaque); pic.setTexture(environment.getApplication().getAssetManager(), (Texture2D) tex, false); viewPort.attachScene(pic); viewPort.setOutputFrameBuffer(null); pic.updateGeometricState(); return viewPort; } 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.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);
private ViewPort setupViewBuffers(Camera cam, String viewName) { if (environment != null) { if (environment.getApplication() != null) { // create offscreen framebuffer FrameBuffer offBufferLeft = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1); //offBufferLeft.setSrgb(true); //setup framebuffer's texture Texture2D offTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8); offTex.setMinFilter(Texture2D.MinFilter.BilinearNoMipMaps); offTex.setMagFilter(Texture2D.MagFilter.Bilinear); //setup framebuffer to use texture offBufferLeft.setDepthBuffer(Image.Format.Depth); offBufferLeft.setColorTexture(offTex); ViewPort viewPort = environment.getApplication().getRenderManager().createPreView(viewName, cam); viewPort.setClearFlags(true, true, true); viewPort.setBackgroundColor(ColorRGBA.Black); Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator(); while (spatialIter.hasNext()) { viewPort.attachScene(spatialIter.next()); } //set viewport to render to offscreen framebuffer viewPort.setOutputFrameBuffer(offBufferLeft); return viewPort; } 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."); } }
private ViewPort setupViewBuffers(Camera cam, String viewName){ if (environment.getApplication() != null){ offBufferLeft.setColorTexture(offTex); ViewPort viewPort = environment.getApplication().getRenderManager().createPreView(viewName, cam); viewPort.setClearFlags(true, true, true); viewPort.setBackgroundColor(ColorRGBA.Black); Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator(); while(spatialIter.hasNext()){ viewPort.attachScene(spatialIter.next());
/** * 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."); } }
private void setupFinalFullTexture(Camera cam) { if (environment != null) { if (environment.getApplication() != null) { // create offscreen framebuffer FrameBuffer out = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1); //offBuffer.setSrgb(true); //setup framebuffer's texture dualEyeTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8); dualEyeTex.setMinFilter(Texture2D.MinFilter.BilinearNoMipMaps); dualEyeTex.setMagFilter(Texture2D.MagFilter.Bilinear); logger.config("Dual eye texture " + dualEyeTex.getName() + " (" + dualEyeTex.getImage().getId() + ")"); logger.config(" Type: " + dualEyeTex.getType()); logger.config(" Size: " + dualEyeTex.getImage().getWidth() + "x" + dualEyeTex.getImage().getHeight()); logger.config(" Image depth: " + dualEyeTex.getImage().getDepth()); logger.config(" Image format: " + dualEyeTex.getImage().getFormat()); logger.config(" Image color space: " + dualEyeTex.getImage().getColorSpace()); //setup framebuffer to use texture out.setDepthBuffer(Image.Format.Depth); out.setColorTexture(dualEyeTex); ViewPort viewPort = environment.getApplication().getViewPort(); viewPort.setClearFlags(true, true, true); viewPort.setBackgroundColor(ColorRGBA.Black); viewPort.setOutputFrameBuffer(out); } 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."); } }
private void setupFinalFullTexture(Camera cam) { if (environment.getApplication() != null){ out.setColorTexture(dualEyeTex); ViewPort viewPort = environment.getApplication().getViewPort(); viewPort.setClearFlags(true, true, true); viewPort.setBackgroundColor(ColorRGBA.Black);
if (environment.getApplication() != null){ if( environment.isInVR() == false ){ Texture tex = environment.getApplication().getAssetManager().loadTexture(texture); mouseImage.setTexture(environment.getApplication().getAssetManager(), (Texture2D)tex, true); ySize = tex.getImage().getHeight(); mouseImage.setHeight(ySize); mouseImage.getMaterial().getAdditionalRenderState().setDepthWrite(false); } else { Texture tex = environment.getApplication().getAssetManager().loadTexture(texture); mouseImage.setTexture(environment.getApplication().getAssetManager(), (Texture2D)tex, true); ySize = tex.getImage().getHeight(); mouseImage.setHeight(ySize);
private void setupFinalFullTexture(Camera cam) { if (environment.getApplication() != null){ out.setColorTexture(dualEyeTex); ViewPort viewPort = environment.getApplication().getViewPort(); viewPort.setClearFlags(true, true, true); viewPort.setBackgroundColor(ColorRGBA.Black);
if( environment.getApplication().getInputManager().isCursorVisible() ) { if( mouseImage.getParent() == null ) { environment.getApplication().getGuiViewPort().attachScene(mouseImage); centerMouse(); if (environment.getApplication().getContext() instanceof LwjglWindow){ GLFW.glfwSetInputMode(((LwjglWindow)environment.getApplication().getContext()).getWindowHandle(), GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_DISABLED); MouseInput mi = environment.getApplication().getContext().getMouseInput(); if( mi instanceof GlfwMouseInputVR ) { if( recentCenterCount <= 0 ) {