SetDeviceIndex() public method

public SetDeviceIndex ( int index ) : void
index int
return void
示例#1
0
 // Use this for initialization
 void Awake()
 {
     flipperBase = Instantiate(flipperBase);
     myFlipper = flipperBase.GetComponent<SteamVR_TrackedObject>();
     myFlipper.origin = gameObject.transform;
     myFlipper.SetDeviceIndex(++numControllers);
 }
示例#2
0
    public void Update()
    {
        List <string> currentIDs = new List <string>();
        var           error      = ETrackedPropertyError.TrackedProp_Success;

        for (uint i = 0; i < 16; i++)
        {
            var result = new StringBuilder(64);
            OpenVR.System.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_RenderModelName_String, result, 64, ref error);

            if (result.ToString().Contains("tracker"))
            {
                StringBuilder id = new StringBuilder(64);

                OpenVR.System.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_SerialNumber_String, id, 64, ref error);

                currentIDs.Add(id.ToString());

                if (CircleVRTrackingSystem.HasTracker(id.ToString()))
                {
                    continue;
                }

                SteamVR_TrackedObject trackedObj = CircleVRTrackingSystem.CreateTracker(id.ToString()).gameObject.AddComponent <SteamVR_TrackedObject>();
                trackedObj.SetDeviceIndex((int)i);
            }
        }
    }
示例#3
0
 // Use this for initialization
 void Awake()
 {
     flipperBase      = Instantiate(flipperBase);
     myFlipper        = flipperBase.GetComponent <SteamVR_TrackedObject>();
     myFlipper.origin = gameObject.transform;
     myFlipper.SetDeviceIndex(++numControllers);
 }
    void LateUpdate()
    {
        if (ReportDistanceOnly)
        {
            DesiredDistanceBetweenBasestations = (BasestationB.transform.position - BasestationC.transform.position).magnitude;
        }
        else
        {
            // Check to make sure the basestations are at approximately the correct distance from each other. This
            // check ensures that the basestations are being tracked before repositioning the room. We want the error between actual distance
            // and desired distance to be less than 5%
            float basestationDistance = (BasestationB.transform.position - BasestationC.transform.position).magnitude;
            float distanceCheck       = Mathf.Abs(basestationDistance - DesiredDistanceBetweenBasestations) / DesiredDistanceBetweenBasestations;
            if (distanceCheck < 0.05)
            {
                GameObject basestation = null;
                GameObject target      = null;
                switch (CalibrationOn)
                {
                case CalibrationType.NoCalibration:
                    return;

                case CalibrationType.BasestationB:
                    basestation = BasestationB.gameObject;
                    target      = BasestationBTarget;
                    break;

                case CalibrationType.BasestationC:
                    basestation = BasestationC.gameObject;
                    target      = BasestationCTarget;

                    break;
                }

                // Find the distance between the basestation and it's target
                Vector3 offset = target.transform.position - basestation.transform.position;

                // The devices are assigned incorrectly, swap them
                if (offset.sqrMagnitude > 1.0f)
                {
                    SteamVR_TrackedObject.EIndex tmpIndex = BasestationC.index;
                    BasestationC.SetDeviceIndex((int)BasestationB.index);
                    BasestationB.SetDeviceIndex((int)tmpIndex);
                }
                else
                {
                    // Correct the rotation
                    Quaternion rotationOffset = target.transform.rotation * Quaternion.Inverse(basestation.transform.rotation);
                    CameraRig.transform.rotation = rotationOffset * CameraRig.transform.rotation;

                    // Correct the position
                    offset = target.transform.position - basestation.transform.position;
                    CameraRig.transform.position += offset;
                }
            }
        }
    }
        public static GameObject SpawnMotionTracker(bool newTracker)
        {
            // Load prefab and check validity
            GameObject motionTrackerPrefab = Resources.Load <GameObject>("Trackers/VIVETracker");

            if (motionTrackerPrefab == null)
            {
                throw new System.Exception("The requested motion tracker prefab was not found.");
            }

            // Load Player object
            GameObject playerGO = GameObject.FindGameObjectWithTag("Player");

            if (playerGO == null)
            {
                throw new System.Exception("The player GameObject was not found.");
            }

            // Load Avatar object to set as parent.
            GameObject avatarGO = GameObject.FindGameObjectWithTag("Avatar");

            // Instantiate
            GameObject motionTrackerGO = Object.Instantiate(motionTrackerPrefab, avatarGO.transform);

            // Configure
            SteamVR_TrackedObject motionTrackerConfig = motionTrackerGO.GetComponent <SteamVR_TrackedObject>();

            if (AvatarSystem.AvatarType == AvatarType.AbleBodied)
            {
                motionTrackerConfig.SetDeviceIndex(motionTrackerNumber + 4); // Set hardware device index to follow
            }
            else
            {
                motionTrackerConfig.SetDeviceIndex(motionTrackerNumber + 5); // Set hardware device index to follow
            }
            motionTrackerConfig.origin = playerGO.transform;
            if (newTracker)
            {
                motionTrackerNumber++;
            }

            return(motionTrackerGO);
        }
示例#6
0
    // Use this for initialization
    void Start()
    {
        ourCollider = GetComponentInChildren <Collider>();
        if (!ourCollider)
        {
            Debug.Log("collider is null");
        }

        // set our controller device indices
        controller_left.SetDeviceIndex(LEFT_IND);
        controller_right.SetDeviceIndex(RIGHT_IND);
        Debug.Log("Left device index: " + (int)controller_left.index);
        Debug.Log("Right device index: " + (int)controller_right.index);
    }
示例#7
0
        private void CreateTrackedObjects()
        {
            // Get list of Tracked device IDs
            List <SteamVR_TrackedObject.EIndex> AvailableEIndecies = new List <SteamVR_TrackedObject.EIndex>();
            List <SteamVR_TrackedObject.EIndex> AllocatedEIndecies = new List <SteamVR_TrackedObject.EIndex>();

            foreach (Dictionary <SteamVR_TrackedObject.EIndex, List <float> > trackedObjectDistances in distances)
            {
                AvailableEIndecies = AvailableEIndecies.Union(trackedObjectDistances.Keys).ToList();
            }

            for (int to_i = 0; to_i < _trackedObjects.Count; to_i++)
            {
                Dictionary <SteamVR_TrackedObject.EIndex, List <float> > trackedObjectDistances = distances[to_i];
                float min = -1;
                SteamVR_TrackedObject.EIndex allocatedEIndex = SteamVR_TrackedObject.EIndex.None;


                foreach (var eIndex in AvailableEIndecies)
                {
                    float mean = trackedObjectDistances[eIndex].Sum() / trackedObjectDistances[eIndex].Count;

                    if (min == -1)
                    {
                        min             = mean;
                        allocatedEIndex = eIndex;
                    }
                    else if (mean < min)
                    {
                        min             = mean;
                        allocatedEIndex = eIndex;
                    }
                }


                if (AllocatedEIndecies.Contains(allocatedEIndex))
                {
                    Debug.LogWarning("Tracker " + allocatedEIndex + " allocated twice");
                }
                else
                {
                    AllocatedEIndecies.Add(allocatedEIndex);
                }

                steamVR_TrackedObject = _trackedObjects[to_i].gameObject.AddComponent <SteamVR_TrackedObject>();
                steamVR_TrackedObject.SetDeviceIndex((int)allocatedEIndex);
            }
        }
    // Start is called before the first frame update
    void Start()
    {
        if (behaviourPose == null)
        {
            behaviourPose = GetComponent <SteamVR_Behaviour_Pose>();
        }
        if (trackedObject == null)
        {
            trackedObject = GetComponent <SteamVR_TrackedObject>();
        }

        int deviceIndex = behaviourPose.GetDeviceIndex();

        Debug.Log(deviceIndex);
        trackedObject.SetDeviceIndex(deviceIndex);
    }
示例#9
0
    private void SwitchControllers()
    {
        leftHanded = !leftHanded;
        Transform toggleParent = GameObject.Find("Tablet(Clone)").
                                 transform.Find("Tablet").
                                 Find("FrontSide").
                                 Find("Canvas").
                                 Find("UI_changeHand");
        GameObject rightToggle = toggleParent.Find("Toggle_right").gameObject;
        GameObject leftToggle  = toggleParent.Find("Toggle_left").gameObject;

        if (leftHanded)
        {
            rightToggle.GetComponent <Toggle>().isOn = false;
            leftToggle.GetComponent <Toggle>().isOn  = true;
        }

        SteamVR_TrackedObject     lo = GameObject.Find("Controller (left)").GetComponent <SteamVR_TrackedObject>();
        SteamVR_TrackedController lc = GameObject.Find("Controller (left)").GetComponent <SteamVR_TrackedController>();

        SteamVR_TrackedObject     ro = GameObject.Find("Controller (right)").GetComponent <SteamVR_TrackedObject>();
        SteamVR_TrackedController rc = GameObject.Find("Controller (right)").GetComponent <SteamVR_TrackedController>();


        int tmp = (int)ro.index;

        ro.SetDeviceIndex((int)lo.index);
        rc.SetDeviceIndex((int)lo.index);

        lo.SetDeviceIndex(tmp);
        lc.SetDeviceIndex(tmp);


        // Decalle tablet
        GameObject tablet = GameObject.Find("Tablet(Clone)").transform.Find("Tablet").gameObject;

        if (leftHanded)
        {
            GameObject leftPoint = GameObject.Find("Tablet(Clone)").transform.Find("LeftPoint").gameObject;
            tablet.transform.position = leftPoint.transform.position;
        }
        else
        {
            GameObject rightPoint = GameObject.Find("Tablet(Clone)").transform.Find("RightPoint").gameObject;
            tablet.transform.position = rightPoint.transform.position;
        }
    }
示例#10
0
    // Use this for initialization
    void Start()
    {
        device      = null;
        ourCollider = GetComponentInChildren <Collider>();
        if (!ourCollider)
        {
            Debug.Log("collider is null");
        }

        // set our controller device indices
        controller_left.SetDeviceIndex(LEFT_IND);
        controller_right.SetDeviceIndex(RIGHT_IND);
        Debug.Log("Left device index: " + (int)controller_left.index);
        Debug.Log("Right device index: " + (int)controller_right.index);
        GetComponent <cakeslice.Outline>().enabled = !GetComponent <cakeslice.Outline>().enabled;

        readGas = false;
        StartCoroutine(DelayGas(2));
    }
示例#11
0
    // Start is called before the first frame update
    void Start()
    {
        trackedObject = transform.GetComponent <SteamVR_TrackedObject>();

        for (uint i = 0; i < 16; i++)
        {
            uint index = i;
            ETrackedPropertyError error = new ETrackedPropertyError();
            StringBuilder         sb    = new StringBuilder();
            OpenVR.System.GetStringTrackedDeviceProperty(index, ETrackedDeviceProperty.Prop_SerialNumber_String, sb, OpenVR.k_unMaxPropertyStringSize, ref error);
            string probablyUniqueDeviceSerial = sb.ToString();


            //if (probablyUniqueDeviceSerial == "LHR-4C5B295D" || probablyUniqueDeviceSerial == "LHR-9C9D4ADE")
            if (probablyUniqueDeviceSerial == DeviceSerial)
            {
                trackedObject.enabled = true;
                Debug.Log("tracker found");
                trackedObject.SetDeviceIndex((int)i);
                return;
            }
        }
    }
示例#12
0
 private void searchForValidDevice()
 {
     for (int count = 1; count < 12; count++)
     {
         Debug.Log("Other controller index - " + otherHand.getSteamDeviceIndex());
         if (count != otherHand.getSteamDeviceIndex())
         {
             steamVRController = SteamVR_Controller.Input(count);
             if (steamVRController.valid && steamVRController.connected)
             {
                 trackedObject = GetComponent <SteamVR_TrackedObject>();
                 trackedObject.SetDeviceIndex(count);
                 Debug.LogWarning(name + "New device index set to - " + trackedObject.index);
                 Initialize();
                 break;
             }
             else
             {
                 Debug.LogWarning(name + " Failed input on index - " + count);
                 Debug.Log(steamVRController.connected + "-" + steamVRController.valid);
             }
         }
     }
 }
示例#13
0
        /// <summary>
        /// Lists all OpenVR devices connected, looking for a given keyboard model.
        /// Repeats the search every 2 seconds if no keyboard could be found.
        /// </summary>
        /// <param name="model"></param>
        private IEnumerator LookForKeyboard(KeyboardModel model)
        {
            int keyboardIndex;
            int retryInterval = 1;

            while (!GetFirstKeyboard(keyboardModel, out keyboardIndex))
            {
                if (retryInterval < 60)
                {
                    retryInterval *= 2;
                    MrKeyboardWatchdog.Instance.DebugText("'" + keyboardModel + "' not found, will try again in " + retryInterval + "s.");
                }
                else
                {
                    MrKeyboardWatchdog.Instance.DebugText("Keyboard takes a while to appear, you may need to restart SteamVR.");
                }

                yield return(new WaitForSeconds(retryInterval));
            }
            svrTrackedObject.SetDeviceIndex(keyboardIndex);
            PositionModel(model);
            KeyboardFound = true;
            Debug.Log("Found the keyboard object.");
        }
        bool GetTrackedTransform_Steam(out Vector3 pos, out Quaternion rot)
        {
            pos = Vector3.zero;
            rot = Quaternion.identity;

            if (string.IsNullOrEmpty(context.Data.trackedByDeviceId))
            {
                lastTrackingDeviceId = null;
                if (!string.IsNullOrEmpty(context.Data.trackedByDevice))
                {
                    SteamVR_TrackedObject.EIndex deviceIndex = (SteamVR_TrackedObject.EIndex)System.Enum.Parse(typeof(SteamVR_TrackedObject.EIndex), context.Data.trackedByDevice);
                    context.Data.trackedByDeviceId = VRInfo.GetDeviceSerial((uint)deviceIndex);
                }
                else
                {
                    return(false);
                }
            }

            try
            {
                if (lastTrackingDeviceId != context.Data.trackedByDeviceId)
                {
                    if (trackedObject == null)
                    {
                        var proxy = new GameObject("Tracking Proxy");
                        proxy.transform.parent = transform;
                        trackedObject          = proxy.AddComponent <SteamVR_TrackedObject>();
                    }

                    lastTrackingDeviceId = null;

                    for (int i = 0; i < Valve.VR.OpenVR.k_unMaxTrackedDeviceCount; i++)
                    {
                        string deviceId = VRInfo.GetDeviceSerial((uint)i);
                        if (deviceId == context.Data.trackedByDeviceId)
                        {
                            trackedObject.SetDeviceIndex(i);
                            trackedObject.enabled = false;  //Reset component so trackedObject.isValid will be helpful again
                            trackedObject.enabled = true;
                            lastTrackingDeviceId  = context.Data.trackedByDeviceId;
                            break;
                        }
                    }
                    newPosesAppliedAction.enabled = true;
                    isTrackedDeviceReady          = false;

                    return(false);
                }

                if (!isTrackedDeviceReady ||
                    string.IsNullOrEmpty(lastTrackingDeviceId) ||
                    trackedObject == null ||
                    !trackedObject.isValid)
                {
                    return(false);
                }

                pos = trackedObject.transform.localPosition;
                rot = trackedObject.transform.localRotation;

                return(true);
            }
            catch (System.Exception)
            {
                return(false);
            }
        }