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;
}
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;
}
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.");
}
}
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.");
}
}
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.");
}
}
Aggregations