use of com.jme3.input.vr.OpenVR in project jmonkeyengine by jMonkeyEngine.
the class OpenVR method initVRCompositor.
@Override
public boolean initVRCompositor(boolean allowed) {
// clear the error store
hmdErrorStore.setValue(0);
if (allowed && vrsystemFunctions != null) {
IntByReference intptr = JOpenVRLibrary.VR_GetGenericInterface(JOpenVRLibrary.IVRCompositor_Version, hmdErrorStore);
if (intptr != null) {
if (intptr.getPointer() != null) {
compositorFunctions = new VR_IVRCompositor_FnTable(intptr.getPointer());
if (compositorFunctions != null && hmdErrorStore.getValue() == 0) {
compositorFunctions.setAutoSynch(false);
compositorFunctions.read();
if (environment.isSeatedExperience()) {
compositorFunctions.SetTrackingSpace.apply(JOpenVRLibrary.ETrackingUniverseOrigin.ETrackingUniverseOrigin_TrackingUniverseSeated);
} else {
compositorFunctions.SetTrackingSpace.apply(JOpenVRLibrary.ETrackingUniverseOrigin.ETrackingUniverseOrigin_TrackingUniverseStanding);
}
logger.config("OpenVR Compositor initialized");
} else {
logger.severe("OpenVR Compositor error: " + hmdErrorStore.getValue());
compositorFunctions = null;
}
} else {
logger.log(Level.SEVERE, "Cannot get valid pointer for generic interface \"" + JOpenVRLibrary.IVRCompositor_Version + "\", " + OpenVRUtil.getEVRInitErrorString(hmdErrorStore.getValue()) + " (" + hmdErrorStore.getValue() + ")");
compositorFunctions = null;
}
} else {
logger.log(Level.SEVERE, "Cannot get generic interface for \"" + JOpenVRLibrary.IVRCompositor_Version + "\", " + OpenVRUtil.getEVRInitErrorString(hmdErrorStore.getValue()) + " (" + hmdErrorStore.getValue() + ")");
compositorFunctions = null;
}
}
if (compositorFunctions == null) {
logger.severe("Skipping VR Compositor...");
if (vrsystemFunctions != null) {
vsyncToPhotons = vrsystemFunctions.GetFloatTrackedDeviceProperty.apply(JOpenVRLibrary.k_unTrackedDeviceIndex_Hmd, JOpenVRLibrary.ETrackedDeviceProperty.ETrackedDeviceProperty_Prop_SecondsFromVsyncToPhotons_Float, hmdErrorStore);
} else {
vsyncToPhotons = 0f;
}
}
return compositorFunctions != null;
}
use of com.jme3.input.vr.OpenVR in project jmonkeyengine by jMonkeyEngine.
the class OpenVR method initialize.
@Override
public boolean initialize() {
logger.config("Initializing OpenVR system...");
hmdErrorStore = new IntByReference();
vrsystemFunctions = null;
JOpenVRLibrary.VR_InitInternal(hmdErrorStore, JOpenVRLibrary.EVRApplicationType.EVRApplicationType_VRApplication_Scene);
if (hmdErrorStore.getValue() == 0) {
vrsystemFunctions = new VR_IVRSystem_FnTable(JOpenVRLibrary.VR_GetGenericInterface(JOpenVRLibrary.IVRSystem_Version, hmdErrorStore).getPointer());
}
if (vrsystemFunctions == null || hmdErrorStore.getValue() != 0) {
logger.severe("OpenVR Initialize Result: " + JOpenVRLibrary.VR_GetVRInitErrorAsEnglishDescription(hmdErrorStore.getValue()).getString(0));
logger.severe("Initializing OpenVR system [FAILED]");
return false;
} else {
logger.config("OpenVR initialized & VR connected.");
vrsystemFunctions.setAutoSynch(false);
vrsystemFunctions.read();
tlastVsync = new FloatByReference();
_tframeCount = new LongByReference();
hmdDisplayFrequency = IntBuffer.allocate(1);
hmdDisplayFrequency.put((int) JOpenVRLibrary.ETrackedDeviceProperty.ETrackedDeviceProperty_Prop_DisplayFrequency_Float);
hmdTrackedDevicePoseReference = new TrackedDevicePose_t.ByReference();
hmdTrackedDevicePoses = (TrackedDevicePose_t[]) hmdTrackedDevicePoseReference.toArray(JOpenVRLibrary.k_unMaxTrackedDeviceCount);
poseMatrices = new Matrix4f[JOpenVRLibrary.k_unMaxTrackedDeviceCount];
for (int i = 0; i < poseMatrices.length; i++) poseMatrices[i] = new Matrix4f();
timePerFrame = 1.0 / hmdDisplayFrequency.get(0);
// disable all this stuff which kills performance
hmdTrackedDevicePoseReference.setAutoRead(false);
hmdTrackedDevicePoseReference.setAutoWrite(false);
hmdTrackedDevicePoseReference.setAutoSynch(false);
for (int i = 0; i < JOpenVRLibrary.k_unMaxTrackedDeviceCount; i++) {
hmdTrackedDevicePoses[i].setAutoRead(false);
hmdTrackedDevicePoses[i].setAutoWrite(false);
hmdTrackedDevicePoses[i].setAutoSynch(false);
}
// init controllers for the first time
VRinput = new OpenVRInput(environment);
VRinput.init();
VRinput.updateConnectedControllers();
// init bounds & chaperone info
VRBounds.init();
logger.config("Initializing OpenVR system [SUCCESS]");
initSuccess = true;
return true;
}
}
use of com.jme3.input.vr.OpenVR in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOpenVR method initTextureSubmitStructs.
/**
* Initialize the system binds of the textures.
*/
private void initTextureSubmitStructs() {
leftTextureType = new Texture_t();
rightTextureType = new Texture_t();
if (environment != null) {
if (environment.getVRHardware() instanceof OpenVR) {
leftTextureBounds = new VRTextureBounds_t();
rightTextureBounds = new VRTextureBounds_t();
// left eye
leftTextureBounds.uMax = 0.5f;
leftTextureBounds.uMin = 0f;
leftTextureBounds.vMax = 1f;
leftTextureBounds.vMin = 0f;
leftTextureBounds.setAutoSynch(false);
leftTextureBounds.setAutoRead(false);
leftTextureBounds.setAutoWrite(false);
leftTextureBounds.write();
// right eye
rightTextureBounds.uMax = 1f;
rightTextureBounds.uMin = 0.5f;
rightTextureBounds.vMax = 1f;
rightTextureBounds.vMin = 0f;
rightTextureBounds.setAutoSynch(false);
rightTextureBounds.setAutoRead(false);
rightTextureBounds.setAutoWrite(false);
rightTextureBounds.write();
// texture type
leftTextureType.eColorSpace = JOpenVRLibrary.EColorSpace.EColorSpace_ColorSpace_Gamma;
leftTextureType.eType = JOpenVRLibrary.ETextureType.ETextureType_TextureType_OpenGL;
leftTextureType.setAutoSynch(false);
leftTextureType.setAutoRead(false);
leftTextureType.setAutoWrite(false);
leftTextureType.handle = -1;
rightTextureType.eColorSpace = JOpenVRLibrary.EColorSpace.EColorSpace_ColorSpace_Gamma;
rightTextureType.eType = JOpenVRLibrary.ETextureType.ETextureType_TextureType_OpenGL;
rightTextureType.setAutoSynch(false);
rightTextureType.setAutoRead(false);
rightTextureType.setAutoWrite(false);
rightTextureType.handle = -1;
logger.config("Init eyes native texture binds");
logger.config(" Left eye texture");
logger.config(" address: " + leftTextureType.getPointer());
logger.config(" size: " + leftTextureType.size() + " bytes");
logger.config(" color space: " + OpenVRUtil.getEColorSpaceString(leftTextureType.eColorSpace));
logger.config(" type: " + OpenVRUtil.getETextureTypeString(leftTextureType.eType));
logger.config(" auto read: " + leftTextureType.getAutoRead());
logger.config(" auto write: " + leftTextureType.getAutoWrite());
logger.config(" handle address: " + leftTextureType.handle);
logger.config(" handle value: " + leftTextureType.handle);
logger.config("");
logger.config(" Right eye texture");
logger.config(" address: " + rightTextureType.getPointer());
logger.config(" size: " + rightTextureType.size() + " bytes");
logger.config(" color space: " + OpenVRUtil.getEColorSpaceString(rightTextureType.eColorSpace));
logger.config(" type: " + OpenVRUtil.getETextureTypeString(rightTextureType.eType));
logger.config(" auto read: " + rightTextureType.getAutoRead());
logger.config(" auto write: " + rightTextureType.getAutoWrite());
logger.config(" handle address: " + rightTextureType.handle);
logger.config(" handle value: " + rightTextureType.handle);
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.input.vr.OpenVR 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.OpenVR in project jmonkeyengine by jMonkeyEngine.
the class OpenVRInput method init.
@Override
public boolean init() {
logger.config("Initialize OpenVR input.");
for (int i = 0; i < JOpenVRLibrary.k_unMaxTrackedDeviceCount; i++) {
rotStore[i] = new Quaternion();
posStore[i] = new Vector3f();
cStates[i] = new VRControllerState_t();
cStates[i].setAutoSynch(false);
cStates[i].setAutoRead(false);
cStates[i].setAutoWrite(false);
lastCallAxis[i] = new Vector2f();
needsNewVelocity[i] = true;
needsNewAngVelocity[i] = true;
logger.config(" Input " + (i + 1) + "/" + JOpenVRLibrary.k_unMaxTrackedDeviceCount + " binded.");
}
return true;
}
Aggregations