/// <summary> /// Callback for NewPoses event. Check whether devices have (dis)connected, /// update their state, and manage the Manipulator objects. /// </summary> /// <param name="devicePoses">The data structure containing the current state of all devices.</param> protected void OnDevicePosesReady(TrackedDevicePose_t[] devicePoses) { // detect devices that have (dis)connected for (uint i = 0; i < OpenVR.k_unMaxTrackedDeviceCount; i++) { bool isConnected = devicePoses[i].bDeviceIsConnected; if (isDeviceConnected[i] != isConnected) { SteamVR_Events.DeviceConnected.Send((int)i, isConnected); } isDeviceConnected[i] = isConnected; } OnTrackedDeviceRoleChanged(); //the events are NOT trustworthy! // update poses for tracked devices SteamVR_Controller.Update(); // update Manipulator objects' state if (DeviceIndexIsValid(ControllerIndexLeft)) { SteamVR_Utils.RigidTransform controllerPose = new SteamVR_Utils.RigidTransform( devicePoses[ControllerIndexLeft].mDeviceToAbsoluteTracking); SteamVR_Controller.Device controllerState = SteamVR_Controller.Input((int)ControllerIndexLeft); if (controllerState != null) { // state is stored in Manipulator object ManipulatorLeft.UpdateState(controllerPose, controllerState); // notify listeners Events.ManipulatorLeftUpdated.Send(controllerState); } } if (DeviceIndexIsValid(ControllerIndexRight)) { SteamVR_Utils.RigidTransform controllerPose = new SteamVR_Utils.RigidTransform( devicePoses[ControllerIndexRight].mDeviceToAbsoluteTracking); SteamVR_Controller.Device controllerState = SteamVR_Controller.Input((int)ControllerIndexRight); if (controllerState != null) { // state is stored in Manipulator object ManipulatorRight.UpdateState(controllerPose, controllerState); // notify listeners Events.ManipulatorRightUpdated.Send(controllerState); } } }
private void OnDevicePosesReady(TrackedDevicePose_t[] devicePoses) { // detect devices that have (dis)connected for (uint i = 0; i < OpenVR.k_unMaxTrackedDeviceCount; i++) { bool isConnected = devicePoses[i].bDeviceIsConnected; if (isDeviceConnected[i] != isConnected) { SteamVR_Events.DeviceConnected.Send((int)i, isConnected); } isDeviceConnected[i] = isConnected; } // update poses for tracked devices SteamVR_Controller.Update(); // update Manipulator objects' state if (DeviceIndexIsValid(ControllerIndexLeft)) { SteamVR_Utils.RigidTransform controllerPose = new SteamVR_Utils.RigidTransform( devicePoses[ControllerIndexLeft].mDeviceToAbsoluteTracking); SteamVR_Controller.Device controllerState = SteamVR_Controller.Input((int)ControllerIndexLeft); ManipulatorLeft.GetComponent <Manipulator>().UpdateState(controllerPose, controllerState); } if (DeviceIndexIsValid(ControllerIndexRight)) { SteamVR_Utils.RigidTransform controllerPose = new SteamVR_Utils.RigidTransform( devicePoses[ControllerIndexRight].mDeviceToAbsoluteTracking); SteamVR_Controller.Device controllerState = SteamVR_Controller.Input((int)ControllerIndexRight); ManipulatorRight.GetComponent <Manipulator>().UpdateState(controllerPose, controllerState); } }