/// <summary>
        /// Load trackers calibrations from file.
        /// </summary>
        public void LoadTrackersCalibrations()
        {
            int successCount = 0;

            // Read calib file
            if (File.Exists(calibFilePath))
            {
                using (StreamReader reader = File.OpenText(calibFilePath))
                {
                    // Read Data
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        string[] items       = line.Split(';');
                        string   trackerName = items[0];
                        // Set Calibration to the existing tracker.
                        ViveTracker tracker = _trackers.Find(trckr => trckr.name == trackerName);
                        if (tracker != null)
                        {
                            float qx = float.Parse(items[1]);
                            float qy = float.Parse(items[2]);
                            float qz = float.Parse(items[3]);
                            float qw = float.Parse(items[4]);
                            tracker.Calibration = new Quaternion(qx, qy, qz, qw);
                            ++successCount;
                        }
                    }
                }
            }
            Debug.Log("[ViveTrackersManagerBase] " + successCount + " trackers calibrations loaded from file : " + calibFilePath);
        }
Esempio n. 2
0
 private void _OnTrackerConnectedStatusChanged(ViveTracker pTracker)
 {
     if (pTracker.Connected)
     {
         Debug.Log("[ViveTrackersTest] ViveTracker " + pTracker.name + " connected.");
     }
     else
     {
         Debug.LogWarning("[ViveTrackersTest] ViveTracker " + pTracker.name + " disconnected !");
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Generate fake ViveTrackers.
        /// </summary>
        public override void RefreshTrackers()
        {
            // Delete existing ViveTrackers
            foreach (ViveTracker tracker in _trackers)
            {
                Destroy(tracker.gameObject);
            }
            _trackers.Clear();
            _trackerDurations.Clear();
            _trackerElapsedTimes.Clear();
            _trackerSpeeds.Clear();

            Debug.Log("[ViveTrackersManagerFake] Generating fake Tracker devices...");
            for (char trackerName = 'A'; trackerName < 'I'; ++trackerName)
            {
                Vector2     pos      = Random.insideUnitCircle * 0.5f;
                Vector3     startPos = new Vector3(pos.x, targetsHeight, pos.y);
                ViveTracker vt       = Instantiate <ViveTracker>(prefab, origin.transform.TransformPoint(startPos), Quaternion.identity, origin.transform);
                vt.Init(new ViveTrackerID((uint)_trackers.Count, trackerName.ToString()), trackerName.ToString());
                _trackers.Add(vt);
                _trackerDurations.Add(0f);
                _trackerElapsedTimes.Add(0f);
                _trackerSpeeds.Add(Random.Range(minSpeed, maxSpeed));
            }

            Debug.Log(string.Format("[ViveTrackersManagerFake] {0} trackers created:", _trackers.Count));
            foreach (ViveTracker tracker in _trackers)
            {
                Debug.Log(string.Format("[ViveTrackersManagerFake] -> Tracker : Name = {0} ; SN = {1} ; Index = {2}", tracker.name, tracker.ID.TrackedDevice_SerialNumber, tracker.ID.TrackedDevice_Index));
            }

            // Fire Action.
            if (TrackersFound != null)
            {
                TrackersFound(_trackers);
            }
        }
        /// <summary>
        /// Scan for available Vive Tracker devices and creates ViveTracker objects accordingly.
        /// Init OpenVR if not already done.
        /// </summary>
        public override void RefreshTrackers()
        {
            // Delete existing ViveTrackers
            foreach (ViveTracker tracker in _trackers)
            {
                Destroy(tracker.gameObject);
            }
            _trackers.Clear();

            // OVR check
            if (!_ovrInit)
            {
                _ovrInit = _InitOpenVR();
                if (!_ovrInit)
                {
                    return;
                }
            }

            Debug.Log("[ViveTrackersManager] Scanning for Tracker devices...");
            for (uint i = 0; i < OpenVR.k_unMaxTrackedDeviceCount; ++i)
            {
                ETrackedDeviceClass deviceClass = _cvrSystem.GetTrackedDeviceClass(i);
                if (deviceClass == ETrackedDeviceClass.GenericTracker)
                {
                    string sn = _GetTrackerSerialNumber(i);
                    if (logTrackersDetection)
                    {
                        Debug.Log("[ViveTrackersManager] Tracker detected : " + sn);
                    }

                    if (sn != "")
                    {
                        string trackerName = "";
                        bool   declared    = _declaredTrackers.TryGetValue(sn, out trackerName);
                        // Creates only trackers declared in config file or all (if !createDeclaredTrackersOnly).
                        if (declared || !createDeclaredTrackersOnly)
                        {
                            ViveTracker vt = GameObject.Instantiate <ViveTracker>(prefab, origin.transform.position, origin.transform.rotation, origin.transform);
                            vt.Init(new ViveTrackerID(i, sn), declared ? trackerName : sn);
                            _trackers.Add(vt);
                        }
                    }
                }
            }

            // Check
            if (_trackers.Count == 0)
            {
                Debug.LogWarning("[ViveTrackersManager] No trackers available !");
                return;
            }

            // Sort Trackers by name.
            _trackers.Sort((ViveTracker x, ViveTracker y) => { return(string.Compare(x.name, y.name)); });

            Debug.Log(string.Format("[ViveTrackersManager] {0} trackers declared and {1} trackers available:", _declaredTrackers.Count, _trackers.Count));
            foreach (ViveTracker tracker in _trackers)
            {
                Debug.Log(string.Format("[ViveTrackersManager] -> Tracker : Name = {0} ; SN = {1} ; Index = {2}", tracker.name, tracker.ID.trackedDevice_SerialNumber, tracker.ID.trackedDevice_Index));
            }

            // Fire Action.
            if (TrackersFound != null)
            {
                TrackersFound(_trackers);
            }
        }
Esempio n. 5
0
 private void _OnTrackerCalibrated(ViveTracker pTracker)
 {
     Debug.Log("[ViveTrackersTest] ViveTracker " + pTracker.name + " calibrated (calibration = rotation offset from World.forward).");
 }
Esempio n. 6
0
 private void _OnTrackerCalibrated(ViveTracker pTracker)
 {
     Debug.Log("[ViveTrackersTest] ViveTracker " + pTracker.name + " calibrated.");
 }