use of com.jme3.input.vr.OSVR in project jmonkeyengine by jMonkeyEngine.
the class VRApplication method start.
@Override
public void start() {
logger.config("Starting application...");
// set some default settings in-case
// settings dialog is not shown
boolean loadSettings = false;
if (settings == null) {
setSettings(new AppSettings(true));
loadSettings = true;
}
GraphicsDevice defDev = null;
try {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
defDev = ge.getDefaultScreenDevice();
} catch (Throwable e1) {
logger.log(Level.SEVERE, "Cannot access default screen device: " + e1.getMessage(), e1);
}
if (isInVR() && !compositorAllowed()) {
logger.warning("VR Composition is not allowed.");
// "easy extended" mode
// TO-DO: JFrame was removed in LWJGL 3, need to use new GLFW library to pick "monitor" display of VR device
// first, find the VR device
GraphicsDevice VRdev = null;
GraphicsDevice[] devs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
// pick the display that isn't the default one
for (GraphicsDevice gd : devs) {
if (gd != defDev) {
VRdev = gd;
break;
}
}
// did we get the VR device?
if (VRdev != null) {
// set properties for VR acceleration
try {
java.awt.DisplayMode useDM = null;
int max = 0;
for (java.awt.DisplayMode dm : VRdev.getDisplayModes()) {
int check = dm.getHeight() + dm.getWidth() + dm.getRefreshRate() + dm.getBitDepth();
if (check > max) {
max = check;
useDM = dm;
}
}
// create a window for the VR device
settings.setWidth(useDM.getWidth());
settings.setHeight(useDM.getHeight());
settings.setBitsPerPixel(useDM.getBitDepth());
settings.setFrequency(useDM.getRefreshRate());
settings.setSwapBuffers(true);
// allow vsync on this display
settings.setVSync(true);
setSettings(settings);
// make sure we are in the right display mode
if (VRdev.getDisplayMode().equals(useDM) == false) {
VRdev.setDisplayMode(useDM);
}
// make a blank cursor to hide it
//BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
//Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor");
//VRwindow.setCursor(blankCursor);
//jmeCanvas.getCanvas().setCursor(blankCursor);
//VRwindow.pack();
//VRwindow.setVisible(true);
//startCanvas();
logger.config("Starting application [SUCCESS]");
return;
} catch (Exception e) {
logger.log(Level.SEVERE, "Error during application start: " + e.getMessage(), e);
}
}
}
if (!isInVR()) {
logger.config("VR mode disabled.");
// not in VR, show settings dialog
if (Platform.get() != Platform.MACOSX) {
if (!JmeSystem.showSettingsDialog(settings, loadSettings)) {
logger.config("Starting application [SUCCESS]");
return;
}
} else {
// GLFW workaround on macs
settings.setFrequency(defDev.getDisplayMode().getRefreshRate());
settings.setDepthBits(24);
settings.setVSync(true);
// try and read resolution from file in local dir
File resfile = new File("resolution.txt");
if (resfile.exists()) {
try {
BufferedReader br = new BufferedReader(new FileReader(resfile));
settings.setWidth(Integer.parseInt(br.readLine()));
settings.setHeight(Integer.parseInt(br.readLine()));
try {
settings.setFullscreen(br.readLine().toLowerCase(Locale.ENGLISH).contains("full"));
} catch (Exception e) {
settings.setFullscreen(false);
}
br.close();
} catch (Exception e) {
settings.setWidth(1280);
settings.setHeight(720);
}
} else {
settings.setWidth(1280);
settings.setHeight(720);
settings.setFullscreen(false);
}
settings.setResizable(false);
}
settings.setSwapBuffers(true);
} else {
logger.config("VR mode enabled.");
// use basic mirroring window, skip settings window
settings.setWidth(xWin);
settings.setHeight(yWin);
settings.setBitsPerPixel(24);
// never sleep in main loop
settings.setFrameRate(0);
settings.setFrequency(VRhardware.getDisplayFrequency());
settings.setFullscreen(false);
// stop vsyncing on primary monitor!
settings.setVSync(false);
settings.setSwapBuffers(!disableSwapBuffers || VRhardware instanceof OSVR);
settings.setTitle("Put Headset On Now: " + settings.getTitle());
settings.setResizable(true);
}
if (forceDisableMSAA) {
logger.config("Disabling multisampling.");
// disable multisampling, which is more likely to break things than be useful
settings.setSamples(1);
}
// set opengl mode
if (tryOpenGL3) {
logger.config("Using LWJGL OpenGL 3 renderer.");
settings.setRenderer(AppSettings.LWJGL_OPENGL3);
} else {
logger.config("Using LWJGL OpenGL 2 renderer.");
settings.setRenderer(AppSettings.LWJGL_OPENGL2);
}
setSettings(settings);
start(JmeContext.Type.Display, false);
// disable annoying warnings about GUI stuff being updated, which is normal behavior
// for late GUI placement for VR purposes
Logger.getLogger("com.jme3").setLevel(Level.SEVERE);
}
use of com.jme3.input.vr.OSVR 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.input.vr.OSVR 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.input.vr.OSVR in project jmonkeyengine by jMonkeyEngine.
the class OSVRInput method init.
@Override
public boolean init() {
logger.config("Initialize OSVR input.");
buttonHandler = new Callback() {
@SuppressWarnings("unused")
public void invoke(Pointer userdata, Pointer timeval, OSVR_ButtonReport report) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < BUTTON_COUNT; j++) {
if (buttons[i][j] == null)
continue;
if (userdata.toString().equals(buttons[i][j].getPointer().toString())) {
buttonState[i][j] = report.state;
return;
}
}
}
}
};
analogHandler = new Callback() {
@SuppressWarnings("unused")
public void invoke(Pointer userdata, Pointer timeval, OSVR_AnalogReport report) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < ANALOG_COUNT; j++) {
for (int k = 0; k < CHANNEL_COUNT; k++) {
if (analogs[i][j][k] == null)
continue;
if (userdata.toString().equals(analogs[i][j][k].getPointer().toString())) {
analogState[i][j][k] = (float) report.state;
return;
}
}
}
}
}
};
buttons = new OSVR_ClientInterface[2][BUTTON_COUNT];
analogs = new OSVR_ClientInterface[2][ANALOG_COUNT][CHANNEL_COUNT];
buttonState = new float[2][BUTTON_COUNT];
analogState = new float[2][ANALOG_COUNT][CHANNEL_COUNT];
hands = new OSVR_ClientInterface[2];
hands[0] = getInterface(leftHand);
hands[1] = getInterface(rightHand);
handState = new OSVR_Pose3[2];
handState[0] = new OSVR_Pose3();
handState[1] = new OSVR_Pose3();
for (int h = 0; h < 2; h++) {
for (int i = 0; i < BUTTON_COUNT - 2; i++) {
buttons[h][i] = getInterface(getButtonString(h == 0, (byte) Integer.toString(i).toCharArray()[0]));
OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[h][i], buttonHandler, buttons[h][i].getPointer());
}
}
buttons[0][BUTTON_COUNT - 2] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 'b', 'u', 'm', 'p', 'e', 'r', (byte) 0 });
OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[0][BUTTON_COUNT - 2], buttonHandler, buttons[0][BUTTON_COUNT - 2].getPointer());
buttons[1][BUTTON_COUNT - 2] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 'b', 'u', 'm', 'p', 'e', 'r', (byte) 0 });
OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[1][BUTTON_COUNT - 2], buttonHandler, buttons[1][BUTTON_COUNT - 2].getPointer());
buttons[0][BUTTON_COUNT - 1] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'b', 'u', 't', 't', 'o', 'n', (byte) 0 });
OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[0][BUTTON_COUNT - 1], buttonHandler, buttons[0][BUTTON_COUNT - 1].getPointer());
buttons[1][BUTTON_COUNT - 1] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'b', 'u', 't', 't', 'o', 'n', (byte) 0 });
OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[1][BUTTON_COUNT - 1], buttonHandler, buttons[1][BUTTON_COUNT - 1].getPointer());
analogs[0][0][0] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 't', 'r', 'i', 'g', 'g', 'e', 'r', (byte) 0 });
analogs[1][0][0] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 't', 'r', 'i', 'g', 'g', 'e', 'r', (byte) 0 });
OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[0][0][0], analogHandler, analogs[0][0][0].getPointer());
OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[1][0][0], analogHandler, analogs[1][0][0].getPointer());
analogs[0][1][0] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'x', (byte) 0 });
analogs[0][1][1] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'y', (byte) 0 });
OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[0][1][0], analogHandler, analogs[0][1][0].getPointer());
OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[0][1][1], analogHandler, analogs[0][1][1].getPointer());
analogs[1][1][0] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'x', (byte) 0 });
analogs[1][1][1] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'y', (byte) 0 });
OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[1][1][0], analogHandler, analogs[1][1][0].getPointer());
OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[1][1][1], analogHandler, analogs[1][1][1].getPointer());
return true;
}
Aggregations