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 (SteamDevice.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(SteamDevice.GetRotation(0)) * (SteamDevice.GetPosition(i) - SteamDevice.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 UpdateComponent() { if (SteamDevice.status == Status.Unavailable) { status = Status.Unavailable; } if (SteamDevice.GetConfidence(trackerId) == 0) { status = SteamDevice.IsPresent(trackerId) ? Status.Present : Status.Unavailable; positionConfidence = 0; rotationConfidence = 0; gameObject.SetActive(false); return; } status = Status.Tracking; Vector3 localSensorPosition = Target.ToVector3(SteamDevice.GetPosition(trackerId)); Quaternion localSensorRotation = Target.ToQuaternion(SteamDevice.GetRotation(trackerId)); transform.position = trackerTransform.TransformPoint(localSensorPosition); transform.rotation = trackerTransform.rotation * localSensorRotation; positionConfidence = SteamDevice.GetConfidence(trackerId); rotationConfidence = SteamDevice.GetConfidence(trackerId); gameObject.SetActive(true); FuseWithUnityCamera(); }
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 SteamVR Controller Input ... :-( SteamDevice.Start(); AddTracker(humanoid, "SteamVR"); SteamDevice.onNewSensor += OnNewSensor; // trackerId => ViveTracker.NewViveTracker(humanoid, trackerId); #if hVIVETRACKER Debug.Log("Detecting Vive Tracker positions.\nMake sure the Vive HMD is looking in the same direction as the user!"); #endif }
public void StartTracker() { if (!enabled || UnityVRDevice.xrDevice != UnityVRDevice.XRDeviceType.OpenVR) { return; } TraditionalDevice.gameControllerEnabled = false; // Game controllers interfere with SteamVR Controller Input ... :-( SteamDevice.Start(); }
public override void UpdateTracker(bool showRealObjects) { if (subTrackerId == -1) { return; } bool isPresent = IsPresent(); if (!isPresent) { return; } gameObject.SetActive(showRealObjects); transform.localPosition = Target.ToVector3(SteamDevice.GetPosition(subTrackerId)); transform.localRotation = Target.ToQuaternion(SteamDevice.GetRotation(subTrackerId)); }
public override void UpdateComponent() { if (SteamDevice.status == Status.Unavailable) { status = Status.Unavailable; } //if (trackerId < 0) // FindOutermostController(isLeft); if (SteamDevice.GetConfidence(trackerId) == 0) { status = SteamDevice.IsPresent(trackerId) ? Status.Present : Status.Unavailable; positionConfidence = 0; rotationConfidence = 0; gameObject.SetActive(false); return; } status = Status.Tracking; Vector3 localSensorPosition = Target.ToVector3(SteamDevice.GetPosition(trackerId)); Quaternion localSensorRotation = Target.ToQuaternion(SteamDevice.GetRotation(trackerId)); transform.position = trackerTransform.TransformPoint(localSensorPosition); transform.rotation = trackerTransform.rotation * localSensorRotation; positionConfidence = SteamDevice.GetConfidence(trackerId); rotationConfidence = SteamDevice.GetConfidence(trackerId); gameObject.SetActive(true); Passer.VRControllerState_t controllerState = new Passer.VRControllerState_t(); var system = Passer.OpenVR.System; uint controllerStateSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(Passer.VRControllerState_t)); bool newControllerState = system.GetControllerState((uint)trackerId, ref controllerState, controllerStateSize); if (system != null && newControllerState) { UpdateInput(controllerState); } }
public override void UpdateTracker() { if (!enabled || UnityVRDevice.xrDevice != UnityVRDevice.XRDeviceType.OpenVR) { status = Status.Unavailable; return; } status = SteamDevice.status; SteamDevice.Update(); 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 (SteamVrControllerComponent controller in controllers) { controller.UpdateComponent(); } #if hVIVETRACKER foreach (ViveTrackerComponent viveTracker in viveTrackers) { viveTracker.UpdateComponent(); } #endif }
public override void Calibrate() { SteamDevice.ResetSensors(); }
public override bool IsPresent() { bool isPresent = SteamDevice.IsPresent(subTrackerId); return(isPresent); }