Search in sources :

Example 6 with Application

use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.

the class VRMouseManager method setImage.

/**
     * Set the image to use as mouse cursor. The given string describe an asset that the underlying application asset manager has to load.
     * @param texture the image to use as mouse cursor.
     */
public void setImage(String texture) {
    if (environment != null) {
        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.setWidth(tex.getImage().getWidth());
                mouseImage.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
                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);
                mouseImage.setWidth(tex.getImage().getWidth());
                mouseImage.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
                mouseImage.getMaterial().getAdditionalRenderState().setDepthWrite(false);
            }
        } 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 : Texture(com.jme3.texture.Texture)

Example 7 with Application

use of com.jme3.app.Application 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 8 with Application

use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.

the class VRMouseManager method updateAnalogAsMouse.

/**
     * Update analog controller as it was a mouse controller.
     * @param inputIndex the index of the controller attached to the VR system.
     * @param mouseListener the JMonkey mouse listener to trigger.
     * @param mouseXName the mouseX identifier.
     * @param mouseYName the mouseY identifier
     * @param tpf the time per frame.
     */
public void updateAnalogAsMouse(int inputIndex, AnalogListener mouseListener, String mouseXName, String mouseYName, float tpf) {
    if (environment != null) {
        if (environment.getApplication() != null) {
            // got a tracked controller to use as the "mouse"
            if (environment.isInVR() == false || environment.getVRinput() == null || environment.getVRinput().isInputDeviceTracking(inputIndex) == false) {
                return;
            }
            Vector2f tpDelta;
            if (thumbstickMode) {
                tpDelta = environment.getVRinput().getAxis(inputIndex, VRInputType.ViveTrackpadAxis);
            } else {
                tpDelta = environment.getVRinput().getAxisDeltaSinceLastCall(inputIndex, VRInputType.ViveTrackpadAxis);
            }
            float Xamount = (float) Math.pow(Math.abs(tpDelta.x) * sensitivity, acceleration);
            float Yamount = (float) Math.pow(Math.abs(tpDelta.y) * sensitivity, acceleration);
            if (tpDelta.x < 0f) {
                Xamount = -Xamount;
            }
            if (tpDelta.y < 0f) {
                Yamount = -Yamount;
            }
            Xamount *= moveScale;
            Yamount *= moveScale;
            if (mouseListener != null) {
                if (tpDelta.x != 0f && mouseXName != null)
                    mouseListener.onAnalog(mouseXName, Xamount * 0.2f, tpf);
                if (tpDelta.y != 0f && mouseYName != null)
                    mouseListener.onAnalog(mouseYName, Yamount * 0.2f, tpf);
            }
            if (environment.getApplication().getInputManager().isCursorVisible()) {
                int index = (avgCounter + 1) % AVERAGE_AMNT;
                lastXmv[index] = Xamount * 133f;
                lastYmv[index] = Yamount * 133f;
                cursorPos.x -= avg(lastXmv);
                cursorPos.y -= avg(lastYmv);
                Vector2f maxsize = environment.getVRGUIManager().getCanvasSize();
                if (cursorPos.x > maxsize.x) {
                    cursorPos.x = maxsize.x;
                }
                if (cursorPos.x < 0f) {
                    cursorPos.x = 0f;
                }
                if (cursorPos.y > maxsize.y) {
                    cursorPos.y = maxsize.y;
                }
                if (cursorPos.y < 0f) {
                    cursorPos.y = 0f;
                }
            }
        } 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 : Vector2f(com.jme3.math.Vector2f)

Example 9 with Application

use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOSVR method setupFinalFullTexture.

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(Texture.MinFilter.BilinearNoMipMaps);
            dualEyeTex.setMagFilter(Texture.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.");
    }
}
Also used : Texture2D(com.jme3.texture.Texture2D) ViewPort(com.jme3.renderer.ViewPort) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 10 with Application

use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOSVR method prepareCameraSize.

/**
     * Prepare the size of the given {@link Camera camera} to adapt it to the underlying rendering context.
     * @param cam the {@link Camera camera} to prepare.
     * @param xMult the camera width multiplier.
     */
private void prepareCameraSize(Camera cam, float xMult) {
    if (environment != null) {
        if (environment.getApplication() != null) {
        } else {
            throw new IllegalStateException("This VR environment is not attached to any application.");
        }
        Vector2f size = new Vector2f();
        VRAPI vrhmd = environment.getVRHardware();
        if (vrhmd == null) {
            size.x = 1280f;
            size.y = 720f;
        } else {
            vrhmd.getRenderSize(size);
        }
        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;
        }
        // other adjustments
        size.x *= xMult;
        size.x *= resMult;
        size.y *= resMult;
        if (cam.getWidth() != size.x || cam.getHeight() != size.y) {
            cam.resize((int) size.x, (int) size.y, false);
        }
    } else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
    }
}
Also used : Vector2f(com.jme3.math.Vector2f) VRAPI(com.jme3.input.vr.VRAPI)

Aggregations

AppSettings (com.jme3.system.AppSettings)11 Material (com.jme3.material.Material)10 Vector2f (com.jme3.math.Vector2f)8 ViewPort (com.jme3.renderer.ViewPort)8 Geometry (com.jme3.scene.Geometry)8 Camera (com.jme3.renderer.Camera)6 Spatial (com.jme3.scene.Spatial)6 Texture2D (com.jme3.texture.Texture2D)6 Node (com.jme3.scene.Node)5 FrameBuffer (com.jme3.texture.FrameBuffer)5 KeyTrigger (com.jme3.input.controls.KeyTrigger)4 InputManager (com.jme3.input.InputManager)3 OSVR (com.jme3.input.vr.OSVR)3 VRAPI (com.jme3.input.vr.VRAPI)3 Application (ca.uhn.hl7v2.app.Application)2 BitmapText (com.jme3.font.BitmapText)2 MouseInput (com.jme3.input.MouseInput)2 ActionListener (com.jme3.input.controls.ActionListener)2 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)2 Vector3f (com.jme3.math.Vector3f)2