Search in sources :

Example 1 with TrackedDevicePose_t

use of com.jme3.system.jopenvr.TrackedDevicePose_t 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;
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) Matrix4f(com.jme3.math.Matrix4f) FloatByReference(com.sun.jna.ptr.FloatByReference) LongByReference(com.sun.jna.ptr.LongByReference) TrackedDevicePose_t(com.jme3.system.jopenvr.TrackedDevicePose_t) VR_IVRSystem_FnTable(com.jme3.system.jopenvr.VR_IVRSystem_FnTable)

Aggregations

Matrix4f (com.jme3.math.Matrix4f)1 TrackedDevicePose_t (com.jme3.system.jopenvr.TrackedDevicePose_t)1 VR_IVRSystem_FnTable (com.jme3.system.jopenvr.VR_IVRSystem_FnTable)1 FloatByReference (com.sun.jna.ptr.FloatByReference)1 IntByReference (com.sun.jna.ptr.IntByReference)1 LongByReference (com.sun.jna.ptr.LongByReference)1