Search in sources :

Example 1 with GlfwMouseInputVR

use of com.jme3.input.lwjgl.GlfwMouseInputVR in project jmonkeyengine by jMonkeyEngine.

the class VRMouseManager method initialize.

/**
     * Initialize the VR mouse manager.
     */
protected 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]");
}
Also used : GlfwMouseInputVR(com.jme3.input.lwjgl.GlfwMouseInputVR) Picture(com.jme3.ui.Picture) MouseInput(com.jme3.input.MouseInput)

Example 2 with GlfwMouseInputVR

use of com.jme3.input.lwjgl.GlfwMouseInputVR in project jmonkeyengine by jMonkeyEngine.

the class VRMouseManager method centerMouse.

/**
     * Center the mouse on the display.
     */
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.");
    }
}
Also used : GlfwMouseInputVR(com.jme3.input.lwjgl.GlfwMouseInputVR) AppSettings(com.jme3.system.AppSettings) Vector2f(com.jme3.math.Vector2f) MouseInput(com.jme3.input.MouseInput)

Example 3 with GlfwMouseInputVR

use of com.jme3.input.lwjgl.GlfwMouseInputVR 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

MouseInput (com.jme3.input.MouseInput)3 GlfwMouseInputVR (com.jme3.input.lwjgl.GlfwMouseInputVR)3 Vector2f (com.jme3.math.Vector2f)2 Node (com.jme3.scene.Node)1 AppSettings (com.jme3.system.AppSettings)1 LwjglWindow (com.jme3.system.lwjgl.LwjglWindow)1 Picture (com.jme3.ui.Picture)1