public override void UpdateComponent() { if (OpenVRDevice.status == Status.Unavailable) { status = Status.Unavailable; } if (OpenVRDevice.GetConfidence(trackerId) == 0) { status = OpenVRDevice.IsPresent(trackerId) ? Status.Present : Status.Unavailable; positionConfidence = 0; rotationConfidence = 0; gameObject.SetActive(false); return; } status = Status.Tracking; Vector3 localSensorPosition = Target.ToVector3(OpenVRDevice.GetPosition(trackerId)); Quaternion localSensorRotation = Target.ToQuaternion(OpenVRDevice.GetRotation(trackerId)); transform.position = trackerTransform.TransformPoint(localSensorPosition); transform.rotation = trackerTransform.rotation * localSensorRotation; positionConfidence = OpenVRDevice.GetConfidence(trackerId); rotationConfidence = OpenVRDevice.GetConfidence(trackerId); gameObject.SetActive(true); FuseWithUnityCamera(); }
private void FindOutermostController(bool isLeft) { Vector outermostLocalPos = new Vector(isLeft ? -0.1F : 0.1F, 0, 0); for (int i = 0; i < Passer.OpenVR.k_unMaxTrackedDeviceCount; i++) { if (OpenVRDevice.GetDeviceClass(i) != Passer.ETrackedDeviceClass.Controller) { continue; } Passer.ETrackedControllerRole role = Passer.OpenVR.System.GetControllerRoleForTrackedDeviceIndex((uint)i); if ((isLeft && role == Passer.ETrackedControllerRole.LeftHand) || (!isLeft && role == Passer.ETrackedControllerRole.RightHand)) { trackerId = i; return; } Vector sensorLocalPos = Rotation.Inverse(OpenVRDevice.GetRotation(0)) * (OpenVRDevice.GetPosition(i) - OpenVRDevice.GetPosition(0)); // 0 = HMD if ((isLeft && sensorLocalPos.x < outermostLocalPos.x && role != Passer.ETrackedControllerRole.RightHand) || (!isLeft && sensorLocalPos.x > outermostLocalPos.x) && role != Passer.ETrackedControllerRole.LeftHand) { trackerId = i; outermostLocalPos = sensorLocalPos; } } }
public override void Calibrate() { OpenVRDevice.ResetSensors(); #if hVIVETRACKER humanoid.hipsTarget.viveTracker.ResetSensor(); humanoid.leftFootTarget.viveTracker.ResetSensor(); humanoid.rightFootTarget.viveTracker.ResetSensor(); #endif }
public void StartTracker() { if (!enabled || UnityVRDevice.xrDevice != UnityVRDevice.XRDeviceType.OpenVR) { return; } TraditionalDevice.gameControllerEnabled = false; // Game controllers interfere with OpenVR Controller Input ... :-( OpenVRDevice.Start(); }
public override void StartTracker(HumanoidControl _humanoid) { humanoid = _humanoid; if (humanoid.headTarget.unityVRHead.enabled && UnityVRDevice.xrDevice == UnityVRDevice.XRDeviceType.OpenVR) { enabled = true; } if (!enabled || UnityVRDevice.xrDevice != UnityVRDevice.XRDeviceType.OpenVR) { return; } TraditionalDevice.gameControllerEnabled = false; // Game controllers interfere with OpenVR Controller Input ... :-( OpenVRDevice.Start(); AddTracker(humanoid, "OpenVR"); #if UNITY_EDITOR string path = Application.dataPath + humanoid.path + "/Extensions/OpenVR/actions.json"; #else string path = Application.dataPath + "/../actions.json"; #endif Passer.EVRInputError err = Passer.OpenVR.Input.SetActionManifestPath(path); if (err != Passer.EVRInputError.None) { Debug.LogError("OpenVR.Input.SetActionManifestPath error (" + path + "): " + err.ToString()); } else { err = Passer.OpenVR.Input.GetActionSetHandle("/actions/default", ref pHandle); if (err != Passer.EVRInputError.None) { Debug.LogError("OpenVR.Input.GetActionSetHandle error (): " + err.ToString()); } else { actionSet.ulActionSet = pHandle; } } activeActionSets = new Passer.VRActiveActionSet_t[] { actionSet }; activeActionSetSize = (uint)(Marshal.SizeOf(typeof(Passer.VRActiveActionSet_t))); OpenVRDevice.onNewSensor = OnNewSensor; #if hVIVETRACKER Debug.Log("Detecting Vive Tracker positions.\nMake sure the Vive HMD is looking in the same direction as the user!"); #endif }
public override void UpdateComponent() { if (OpenVRDevice.status == Status.Unavailable) { status = Status.Unavailable; } if (trackerId < 0) { FindOutermostController(isLeft); } if (OpenVRDevice.GetConfidence(trackerId) == 0) { status = OpenVRDevice.IsPresent(trackerId) ? Status.Present : Status.Unavailable; positionConfidence = 0; rotationConfidence = 0; gameObject.SetActive(false); return; } status = Status.Tracking; Vector3 localSensorPosition = Target.ToVector3(OpenVRDevice.GetPosition(trackerId)); Quaternion localSensorRotation = Target.ToQuaternion(OpenVRDevice.GetRotation(trackerId)); transform.position = trackerTransform.TransformPoint(localSensorPosition); transform.rotation = trackerTransform.rotation * localSensorRotation; positionConfidence = OpenVRDevice.GetConfidence(trackerId); rotationConfidence = OpenVRDevice.GetConfidence(trackerId); gameObject.SetActive(true); Passer.VRControllerState_t controllerState = new Passer.VRControllerState_t(); var system = Passer.OpenVR.System; uint controllerStateSize = (uint)Marshal.SizeOf(typeof(Passer.VRControllerState_t)); bool newControllerState = system.GetControllerState((uint)trackerId, ref controllerState, controllerStateSize); if (system != null && newControllerState) { UpdateInput(controllerState); } Skeletal(); }
public override void UpdateTracker(bool showRealObjects) { if (subTrackerId == -1) { return; } bool isPresent = IsPresent(); if (!isPresent) { return; } if (gameObject != null) { gameObject.SetActive(showRealObjects); } transform.localPosition = Target.ToVector3(OpenVRDevice.GetPosition(subTrackerId)); transform.localRotation = Target.ToQuaternion(OpenVRDevice.GetRotation(subTrackerId)); }
public override void UpdateTracker() { if (!enabled || UnityVRDevice.xrDevice != UnityVRDevice.XRDeviceType.OpenVR) { status = Status.Unavailable; return; } status = OpenVRDevice.status; OpenVRDevice.Update(); Passer.OpenVR.Input.UpdateActionState(activeActionSets, activeActionSetSize); deviceView.position = Target.ToVector(trackerTransform.position); deviceView.orientation = Target.ToRotation(trackerTransform.rotation); bool showRealObjects = humanoid == null ? true : humanoid.showRealObjects; if (hmd != null) { hmd.UpdateComponent(); } foreach (SubTracker subTracker in subTrackers) { subTracker.UpdateTracker(showRealObjects); } foreach (OpenVRController controller in controllers) { controller.UpdateComponent(); } #if hVIVETRACKER foreach (ViveTrackerComponent viveTracker in viveTrackers) { viveTracker.UpdateComponent(); } #endif }
public override bool IsPresent() { bool isPresent = OpenVRDevice.IsPresent(subTrackerId); return(isPresent); }