Search in sources :

Example 36 with Environment

use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.

the class VREnvironment method initialize.

/**
     * Initialize this VR environment. This method enable the system bindings and configure all the VR system modules. 
     * A call to this method has to be made before any use of VR capabilities.
     * @return <code>true</code> if the VR environment is successfully initialized and <code>false</code> otherwise.
     */
public boolean initialize() {
    logger.config("Initializing VR environment.");
    initialized = false;
    // we are going to use OpenVR now, not the Oculus Rift
    // OpenVR does support the Rift
    String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
    //for the moment, linux/unix causes crashes, 64-bit only
    vrSupportedOS = !OS.contains("nux") && System.getProperty("sun.arch.data.model").equalsIgnoreCase("64");
    compositorOS = OS.contains("indows");
    if (vrSupportedOS) {
        if (vrBinding == VRConstants.SETTING_VRAPI_OSVR_VALUE) {
            hardware = new OSVR(this);
            initialized = true;
            logger.config("Creating OSVR wrapper [SUCCESS]");
        } else if (vrBinding == VRConstants.SETTING_VRAPI_OPENVR_VALUE) {
            hardware = new OpenVR(this);
            initialized = true;
            logger.config("Creating OpenVR wrapper [SUCCESS]");
        } else {
            logger.config("Cannot create VR binding: " + vrBinding + " [FAILED]");
            logger.log(Level.SEVERE, "Cannot initialize VR environment [FAILED]");
        }
        if (hardware.initialize()) {
            initialized &= true;
            logger.config("VR native wrapper initialized [SUCCESS]");
        } else {
            initialized &= false;
            logger.warning("VR native wrapper initialized [FAILED]");
            logger.log(Level.SEVERE, "Cannot initialize VR environment [FAILED]");
        }
    } else {
        logger.log(Level.SEVERE, "System does not support VR capabilities.");
        logger.log(Level.SEVERE, "Cannot initialize VR environment [FAILED]");
    }
    return initialized;
}
Also used : VRViewManagerOSVR(com.jme3.util.VRViewManagerOSVR) OSVR(com.jme3.input.vr.OSVR) VRViewManagerOpenVR(com.jme3.util.VRViewManagerOpenVR) OpenVR(com.jme3.input.vr.OpenVR)

Example 37 with Environment

use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.

the class OSVR method initialize.

@Override
public boolean initialize() {
    logger.config("Initialize OSVR system.");
    hmdPose.setAutoSynch(false);
    context = OsvrClientKitLibrary.osvrClientInit(defaultJString, 0);
    VRinput = new OSVRInput(environment);
    initSuccess = context != null && VRinput.init();
    if (initSuccess) {
        PointerByReference grabDisplay = new PointerByReference();
        byte retval = OsvrDisplayLibrary.osvrClientGetDisplay(context, grabDisplay);
        if (retval != 0) {
            System.out.println("OSVR Get Display Error: " + retval);
            initSuccess = false;
            return false;
        }
        displayConfig = new OSVR_DisplayConfig(grabDisplay.getValue());
        System.out.println("Waiting for the display to fully start up, including receiving initial pose update...");
        int i = 400;
        while (OsvrDisplayLibrary.osvrClientCheckDisplayStartup(displayConfig) != 0) {
            if (i-- < 0) {
                System.out.println("Couldn't get display startup update in time, continuing anyway...");
                break;
            }
            OsvrClientKitLibrary.osvrClientUpdate(context);
            try {
                Thread.sleep(5);
            } catch (Exception e) {
            }
        }
        System.out.println("OK, display startup status is good!");
    }
    return initSuccess;
}
Also used : PointerByReference(com.sun.jna.ptr.PointerByReference) OSVR_DisplayConfig(com.jme3.system.osvr.osvrdisplay.OsvrDisplayLibrary.OSVR_DisplayConfig)

Example 38 with Environment

use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.

the class VRGuiManager method positionTo.

/**
	 * Position the GUI to the given location.
	 * @param pos the position of the GUI.
	 * @param dir the rotation of the GUI.
	 * @param tpf the time per frame.
	 */
private void positionTo(Vector3f pos, Quaternion dir, float tpf) {
    if (environment != null) {
        Vector3f guiPos = guiQuadNode.getLocalTranslation();
        guiPos.set(0f, 0f, guiDistance);
        dir.mult(guiPos, guiPos);
        guiPos.x += pos.x;
        guiPos.y += pos.y + environment.getVRHeightAdjustment();
        guiPos.z += pos.z;
        if (guiPositioningElastic > 0f && posMode != VRGUIPositioningMode.MANUAL) {
            // mix pos & dir with current pos & dir            
            guiPos.interpolateLocal(EoldPos, guiPos, Float.min(1f, tpf * guiPositioningElastic));
            EoldPos.set(guiPos);
        }
    } else {
        throw new IllegalStateException("VR GUI manager is not attached to any environment.");
    }
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 39 with Environment

use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.

the class VRGuiManager method getCanvasSize.

/**
	 * 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.");
    }
}
Also used : AppSettings(com.jme3.system.AppSettings) Vector2f(com.jme3.math.Vector2f)

Example 40 with Environment

use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.

the class VRGuiManager method getCanvasToWindowRatio.

/**
	 * 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.");
    }
}
Also used : Vector2f(com.jme3.math.Vector2f)

Aggregations

Camera (com.jme3.renderer.Camera)9 Vector2f (com.jme3.math.Vector2f)8 Vector3f (com.jme3.math.Vector3f)8 Spatial (com.jme3.scene.Spatial)7 VRAPI (com.jme3.input.vr.VRAPI)6 ViewPort (com.jme3.renderer.ViewPort)6 Texture2D (com.jme3.texture.Texture2D)6 Material (com.jme3.material.Material)5 Geometry (com.jme3.scene.Geometry)5 Node (com.jme3.scene.Node)5 FrameBuffer (com.jme3.texture.FrameBuffer)5 AudioNode (com.jme3.audio.AudioNode)4 OSVR (com.jme3.input.vr.OSVR)4 Quaternion (com.jme3.math.Quaternion)4 OpenVR (com.jme3.input.vr.OpenVR)3 ColorRGBA (com.jme3.math.ColorRGBA)3 FilterPostProcessor (com.jme3.post.FilterPostProcessor)3 Environment (com.jme3.audio.Environment)2 AmbientLight (com.jme3.light.AmbientLight)2 CartoonSSAO (com.jme3.post.CartoonSSAO)2