public void SetDeviceIndex(int index) { if (System.Enum.IsDefined(typeof(EIndex), index)) { this.index = (EIndex)index; } }
public void SetDeviceIndex(int index) { Debug.Log("index" + index); if (System.Enum.IsDefined(typeof(EIndex), index)) { this.index = (EIndex)index; } }
public void SetDeviceIndex(int index) { Console.WriteLine("Set index to " + index); if (System.Enum.IsDefined(typeof(EIndex), index)) { this.index = (EIndex)index; } }
private void GetTrackedObjectsIndexID() { var vr = SteamVR.instance; for (int i = 0; i < Valve.VR.OpenVR.k_unMaxTrackedDeviceCount; i++) { //Debug.Log(vr.hmd.GetTrackedDeviceClass((uint)i)); if (vr.hmd.GetTrackedDeviceClass((uint)i) != Valve.VR.ETrackedDeviceClass.Controller && vr.hmd.GetTrackedDeviceClass((uint)i) != Valve.VR.ETrackedDeviceClass.GenericTracker) { //Debug.Log( string.Format( "Hand - device {0} is not a controller", i ) ); continue; } if (vr.hmd.GetTrackedDeviceClass((uint)i) == Valve.VR.ETrackedDeviceClass.GenericTracker) { var system = OpenVR.System; var error = ETrackedPropertyError.TrackedProp_Success; var capacity = system.GetStringTrackedDeviceProperty((uint)i, ETrackedDeviceProperty.Prop_RenderModelName_String, null, 0, ref error); if (capacity <= 1) { continue; } var buffer = new System.Text.StringBuilder((int)capacity); system.GetStringTrackedDeviceProperty((uint)i, ETrackedDeviceProperty.Prop_RenderModelName_String, buffer, capacity, ref error); var s = buffer.ToString(); if (this.name.Contains("LH")) { if (s.Contains("LH")) { handtype = HANDTYPE.LEFT_HAND; Tracker = this.gameObject; index = (EIndex)i; Debug.Log(string.Format("Device {0} is a Left Hand Tracker", i)); break; } } if (this.name.Contains("RH")) { if (s.Contains("RH")) { handtype = HANDTYPE.RIGHT_HAND; Tracker = this.gameObject; index = (EIndex)i; Debug.Log(string.Format("Device {0} is a Right Hand Tracker", i)); break; } } } } }
// I want deterministic behaviour for the controllers - eg green maps to the knee. public void Awake() { dumpDeviceProperties(); if (physio_role == EPhysioRole.Knee) { index = getIndexForSerialNumber(GreenTrackerSerial); // assign the index for the Knee } else if (physio_role == EPhysioRole.Ankle) { index = getIndexForSerialNumber(BlueTrackerSerial); } }
/// <summary> /// 検索フォーム起動処理 /// </summary> /// <param name="kbn"></param> /// <param name="setCtl"></param> private void SearchData(EIndex kbn, Control setCtl) { //switch (kbn) //{ // case EIndex.StoreCD: // using (Search_Store frmStaff = new Search_Store()) // { // frmStaff.ShowDialog(); // setCtl.Text = frmStaff.parStoreCD; // } // break; //} }
// Callback function to handle registering new connected Vive Tracker private void onNewDeviceConnection(int index, bool connected) { if (connected && (device == EIndex.None)) { var system = OpenVR.System; if (system != null) { // Assign tracker to headset if it is not a controller var deviceClass = system.GetTrackedDeviceClass((uint)index); if (deviceClass == ETrackedDeviceClass.GenericTracker) { device = (EIndex)index; } } } }
private void OnNewPoses(params object[] args) { // If our Tracked Type changes, we are no longer valid if (_type != Type) { _type = Type; IsValid = false; } // If we aren't valid, try and find our index if (!IsValid) { Index = EIndex.None; if (Type != EType.None) { switch (Type) { case EType.None: return; case EType.HMD: if (HOTK_TrackedDeviceManager.Instance.HMDIndex != OpenVR.k_unTrackedDeviceIndexInvalid) { Index = (EIndex)HOTK_TrackedDeviceManager.Instance.HMDIndex; } break; case EType.LeftController: if (HOTK_TrackedDeviceManager.Instance.LeftIndex != OpenVR.k_unTrackedDeviceIndexInvalid) { Index = (EIndex)HOTK_TrackedDeviceManager.Instance.LeftIndex; } break; case EType.RightController: if (HOTK_TrackedDeviceManager.Instance.RightIndex != OpenVR.k_unTrackedDeviceIndexInvalid) { Index = (EIndex)HOTK_TrackedDeviceManager.Instance.RightIndex; } break; case EType.ThirdController: if (HOTK_TrackedDeviceManager.Instance.ThirdIndex != OpenVR.k_unTrackedDeviceIndexInvalid) { Index = (EIndex)HOTK_TrackedDeviceManager.Instance.ThirdIndex; } break; case EType.FourthController: if (HOTK_TrackedDeviceManager.Instance.FourthIndex != OpenVR.k_unTrackedDeviceIndexInvalid) { Index = (EIndex)HOTK_TrackedDeviceManager.Instance.FourthIndex; } break; default: throw new ArgumentOutOfRangeException(); } } //UpdateRenderModel(); } // Check if our device is valid IsValid = false; if (Index == EIndex.None) { return; // This TrackedDevice is not set to track anything } var i = (int)Index; var poses = (TrackedDevicePose_t[])args[0]; if (poses.Length <= i) { return; // SteamVR did not send poses this update } if (!poses[i].bDeviceIsConnected) { return; // SteamVR reports device has been disconnected or was never connected } if (!poses[i].bPoseIsValid) { return; // SteamVR reports device is not valid (not being tracked currently) } IsValid = true; // Get our poses and change our position/rotation to match the device var pose = new SteamVR_Utils.RigidTransform(poses[i].mDeviceToAbsoluteTracking); if (Origin != null) // Our device is 'anchored' to something else in the scene { pose = new SteamVR_Utils.RigidTransform(Origin) * pose; pose.pos.x *= Origin.localScale.x; pose.pos.y *= Origin.localScale.y; pose.pos.z *= Origin.localScale.z; transform.position = pose.pos; transform.rotation = pose.rot; } else // Our device is not attached to anything, use it's raw tracked position { transform.localPosition = pose.pos; transform.localRotation = pose.rot; } }
private void Reset() { Index = EIndex.None; IsValid = false; //UpdateRenderModel(); }
/// <summary> /// Update is called every frame. /// For SteamVR plugin this is where the device Index is set up. /// For Oculus plugin this is where the tracking is done. /// </summary> protected virtual void Update() { #if ZED_OCULUS //Used only if the Oculus Integration plugin is detected. //Check if the VR headset is connected. if (OVRManager.isHmdPresent && loadeddevice == "Oculus") { if (OVRInput.GetConnectedControllers().ToString().ToLower().Contains("touch")) { //Depending on which tracked device we are looking for, start tracking it. if (deviceToTrack == Devices.LeftController) //Track the Left Oculus Controller. { RegisterPosition(1, OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch), OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch)); } if (deviceToTrack == Devices.RightController) //Track the Right Oculus Controller. { RegisterPosition(1, OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch), OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch)); } if (deviceToTrack == Devices.Hmd) //Track the Oculus Hmd. { RegisterPosition(1, InputTracking.GetLocalPosition(XRNode.CenterEye), InputTracking.GetLocalRotation(XRNode.CenterEye)); } //Use our saved positions to apply a delay before assigning it to this object's Transform. if (poseData.Count > 0) { sl.Pose p; //Delay the saved values inside GetValuePosition() by a factor of latencyCompensation in milliseconds. p = GetValuePosition(1, (float)(latencyCompensation / 1000.0f)); transform.position = p.translation; //Assign new delayed Position transform.rotation = p.rotation; //Assign new delayed Rotation. } } } //Enable updating the internal state of OVRInput. OVRInput.Update(); #endif #if ZED_STEAM_VR UpdateControllerState(); //Get the button states so we can check if buttons are down or not. timerSteamVR += Time.deltaTime; //Increment timer for checking on devices if (timerSteamVR <= timerMaxSteamVR) { return; } timerSteamVR = 0f; //Checks if a device has been assigned if (index == EIndex.None && loadeddevice == "OpenVR") { //We look for any device that has "tracker" in its 3D model mesh name. //We're doing this since the device ID changes based on how many devices are connected to SteamVR. //This way, if there's no controllers or just one, it's going to get the right ID for the Tracker. if (deviceToTrack == Devices.ViveTracker) { var error = ETrackedPropertyError.TrackedProp_Success; for (uint i = 0; i < 16; i++) { var result = new System.Text.StringBuilder((int)64); OpenVR.System.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_RenderModelName_String, result, 64, ref error); if (result.ToString().Contains("tracker")) { index = (EIndex)i; break; //We break out of the loop, but we can use this to set up multiple Vive Trackers if we want to. } } } //Looks for a device with the role of a Right Hand. if (deviceToTrack == Devices.RightController) { index = (EIndex)OpenVR.System.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.RightHand); } //Looks for a device with the role of a Left Hand. if (deviceToTrack == Devices.LeftController) { index = (EIndex)OpenVR.System.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.LeftHand); } //Assigns the HMD. if (deviceToTrack == Devices.Hmd) { index = EIndex.Hmd; } //Display a warning if there was supposed to be a calibration file, and none was found. if (SNHolder.Equals("NONE")) { Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.PAD_CAMERA_CALIBRATION_NOT_FOUND)); } else if (SNHolder != null && index != EIndex.None) // { //If the Serial number of the Calibrated device isn't the same as the current tracked device by this script... var snerror = ETrackedPropertyError.TrackedProp_Success; var snresult = new System.Text.StringBuilder((int)64); OpenVR.System.GetStringTrackedDeviceProperty((uint)index, ETrackedDeviceProperty.Prop_SerialNumber_String, snresult, 64, ref snerror); if (!snresult.ToString().Contains(SNHolder)) { Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.PAD_CAMERA_CALIBRATION_MISMATCH) + " Serial Number: " + SNHolder); //... then look for that device through all the connected devices. for (int i = 0; i < 16; i++) { //If a device with the same Serial Number is found, then change the device to track of this script. var chsnresult = new System.Text.StringBuilder((int)64); OpenVR.System.GetStringTrackedDeviceProperty((uint)i, ETrackedDeviceProperty.Prop_SerialNumber_String, chsnresult, 64, ref snerror); if (snresult.ToString().Contains(SNHolder)) { index = (EIndex)i; string deviceRole = OpenVR.System.GetControllerRoleForTrackedDeviceIndex((uint)index).ToString(); if (deviceRole.Equals("RightHand")) { deviceToTrack = Devices.RightController; } else if (deviceRole.Equals("LeftHand")) { deviceToTrack = Devices.LeftController; } else if (deviceRole.Equals("Invalid")) { var error = ETrackedPropertyError.TrackedProp_Success; var result = new System.Text.StringBuilder((int)64); OpenVR.System.GetStringTrackedDeviceProperty((uint)index, ETrackedDeviceProperty.Prop_RenderModelName_String, result, 64, ref error); if (result.ToString().Contains("tracker")) { deviceToTrack = Devices.ViveTracker; } } Debug.Log("A connected device with the correct Serial Number was found, and assigned to " + this + " the correct device to track."); break; } } } } oldDevice = deviceToTrack; } if (deviceToTrack != oldDevice) { index = EIndex.None; } #endif }
private void OnNewPoses(params object[] args) { if (_type != Type) { _type = Type; IsValid = false; } if (!IsValid) { Index = EIndex.None; if (Type != EType.None) { switch (Type) { case EType.HMD: if (HOTK_TrackedDeviceManager.Instance.HMDIndex != OpenVR.k_unTrackedDeviceIndexInvalid) { Index = (EIndex)HOTK_TrackedDeviceManager.Instance.HMDIndex; } break; case EType.LeftController: if (HOTK_TrackedDeviceManager.Instance.LeftIndex != OpenVR.k_unTrackedDeviceIndexInvalid) { Index = (EIndex)HOTK_TrackedDeviceManager.Instance.LeftIndex; } break; case EType.RightController: if (HOTK_TrackedDeviceManager.Instance.RightIndex != OpenVR.k_unTrackedDeviceIndexInvalid) { Index = (EIndex)HOTK_TrackedDeviceManager.Instance.RightIndex; } break; default: throw new ArgumentOutOfRangeException(); } } } IsValid = false; if (Index == EIndex.None) { return; } var i = (int)Index; var poses = (TrackedDevicePose_t[])args[0]; if (poses.Length <= i) { return; } if (!poses[i].bDeviceIsConnected) { return; } if (!poses[i].bPoseIsValid) { return; } IsValid = true; var pose = new SteamVR_Utils.RigidTransform(poses[i].mDeviceToAbsoluteTracking); if (Origin != null) { pose = new SteamVR_Utils.RigidTransform(Origin) * pose; pose.pos.x *= Origin.localScale.x; pose.pos.y *= Origin.localScale.y; pose.pos.z *= Origin.localScale.z; transform.position = pose.pos; transform.rotation = pose.rot; } else { transform.localPosition = pose.pos; transform.localRotation = pose.rot; } }
private void Reset() { Index = EIndex.None; IsValid = false; }