Search in sources :

Example 1 with LwjglWindow

use of com.jme3.system.lwjgl.LwjglWindow in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOSVR method initialize.

/**
     * Initialize the VR view manager.
     */
public void initialize() {
    logger.config("Initializing VR view manager.");
    if (environment != null) {
        initTextureSubmitStructs();
        setupCamerasAndViews();
        setupVRScene();
        moveScreenProcessingToEyes();
        if (environment.hasTraditionalGUIOverlay()) {
            environment.getVRMouseManager().initialize();
            // update the pose to position the gui correctly on start
            update(0f);
            environment.getVRGUIManager().positionGui();
        }
        if (environment.getApplication() != null) {
            // if we are OSVR, our primary mirror window needs to be the same size as the render manager's output...
            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);
                }
                org.lwjgl.glfw.GLFW.glfwSetWindowPos(window, origWidth - (int) windowSize.x, 32);
                org.lwjgl.glfw.GLFW.glfwFocusWindow(window);
                org.lwjgl.glfw.GLFW.glfwSetCursorPos(window, origWidth / 2.0, origHeight / 2.0);
                logger.config("Initialized VR view manager [SUCCESS]");
            } else {
                throw new IllegalStateException("Underlying VR hardware should be " + OSVR.class.getSimpleName());
            }
        } 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.");
    }
}
Also used : OSVR(com.jme3.input.vr.OSVR) Vector2f(com.jme3.math.Vector2f) LwjglWindow(com.jme3.system.lwjgl.LwjglWindow)

Example 2 with LwjglWindow

use of com.jme3.system.lwjgl.LwjglWindow in project jmonkeyengine by jMonkeyEngine.

the class VRMouseManager method update.

/**
     * Update the mouse manager. This method should not be called manually. 
     * The standard behavior for this method is to be called from the {@link VRViewManager#update(float) update method} of the attached {@link VRViewManager VR view manager}.
     * @param tpf the time per frame.
     */
protected void update(float tpf) {
    if (environment.getApplication().getInputManager().isCursorVisible()) {
        if (mouseImage.getParent() == null) {
            environment.getApplication().getGuiViewPort().attachScene(mouseImage);
            centerMouse();
            // the "real" mouse pointer should stay hidden
            if (environment.getApplication().getContext() instanceof LwjglWindow) {
                GLFW.glfwSetInputMode(((LwjglWindow) environment.getApplication().getContext()).getWindowHandle(), GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_DISABLED);
            }
        }
        // handle mouse movements, which may be in addition to (or exclusive from) tracked movement
        MouseInput mi = environment.getApplication().getContext().getMouseInput();
        if (mi instanceof GlfwMouseInputVR) {
            if (recentCenterCount <= 0) {
                //Vector2f winratio = VRGuiManager.getCanvasToWindowRatio();
                // * winratio.x;
                cursorPos.x += ((GlfwMouseInputVR) mi).getLastDeltaX();
                // * winratio.y;
                cursorPos.y += ((GlfwMouseInputVR) mi).getLastDeltaY();
                if (cursorPos.x < 0f)
                    cursorPos.x = 0f;
                if (cursorPos.y < 0f)
                    cursorPos.y = 0f;
                if (cursorPos.x > environment.getVRGUIManager().getCanvasSize().x)
                    cursorPos.x = environment.getVRGUIManager().getCanvasSize().x;
                if (cursorPos.y > environment.getVRGUIManager().getCanvasSize().y)
                    cursorPos.y = environment.getVRGUIManager().getCanvasSize().y;
            } else
                recentCenterCount--;
            ((GlfwMouseInputVR) mi).clearDeltas();
        }
        // ok, update the cursor graphic position
        Vector2f currentPos = getCursorPosition();
        mouseImage.setLocalTranslation(currentPos.x, currentPos.y - ySize, environment.getVRGUIManager().getGuiDistance() + 1f);
        mouseImage.updateGeometricState();
    } else if (mouseImage.getParent() != null) {
        Node n = mouseImage.getParent();
        mouseImage.removeFromParent();
        if (n != null) {
            n.updateGeometricState();
        }
    }
}
Also used : GlfwMouseInputVR(com.jme3.input.lwjgl.GlfwMouseInputVR) Vector2f(com.jme3.math.Vector2f) Node(com.jme3.scene.Node) LwjglWindow(com.jme3.system.lwjgl.LwjglWindow) MouseInput(com.jme3.input.MouseInput)

Aggregations

Vector2f (com.jme3.math.Vector2f)2 LwjglWindow (com.jme3.system.lwjgl.LwjglWindow)2 MouseInput (com.jme3.input.MouseInput)1 GlfwMouseInputVR (com.jme3.input.lwjgl.GlfwMouseInputVR)1 OSVR (com.jme3.input.vr.OSVR)1 Node (com.jme3.scene.Node)1