@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]"); }
@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."); } }
/** * 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."); } }
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( 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( 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 (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();
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);
/** * 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."); } }
if (environment.getApplication().getContext().getSettings().isSwapBuffers()) { setupMirrorBuffers(environment.getCamera(), dualEyeTex, true); if (environment.getApplication().getContext().getSettings().isSwapBuffers()) { setupMirrorBuffers(environment.getCamera(), leftEyeTexture, false);
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 ) {
if( environment.getApplication().getContext().getSettings().isSwapBuffers() ) { setupMirrorBuffers(environment.getCamera(), dualEyeTex, true); if( environment.getApplication().getContext().getSettings().isSwapBuffers() ) { setupMirrorBuffers(environment.getCamera(), leftEyeTexture, false);
if( environment.getApplication().getContext().getSettings().isSwapBuffers() ) { setupMirrorBuffers(environment.getCamera(), dualEyeTex, true); if( environment.getApplication().getContext().getSettings().isSwapBuffers() ) { setupMirrorBuffers(environment.getCamera(), leftEyeTexture, false);
app.createCanvas(); context = (JmeCanvasContext) app.getContext(); canvas = context.getCanvas(); canvas.setSize(getWidth(), getHeight());
if (app.getContext().getTouchInput() == null) { this.mouseState = new MouseAppState(app); } else { gammaEnabled = app.getContext().getSettings().isGammaCorrection();