Esempio n. 1
0
        private void VisualizeTrackers()
        {
            for (int i = 0; i < trackers.RequiredTrackers.Length; i++)
            {
                // Spawn new visual if there are not enough
                if (trackerVisuals.Count < i + 1)
                {
                    trackerVisuals.Add(Instantiate(trackerModel, transform));
                }

                VRTrackerType trackerType = trackers.RequiredTrackers[i];

                // Hide tracker when there is no tracker data
                TransformValues?trackerTransform = trackers.GetTracker(trackerType);
                if (trackerTransform == null)
                {
                    if (trackerVisuals[i].activeSelf)
                    {
                        trackerVisuals[i].SetActive(false);
                    }
                    continue;
                }

                // Position tracker model to the right position
                if (!trackerVisuals[i].activeSelf)
                {
                    trackerVisuals[i].SetActive(true);
                }

                trackerVisuals[i]?.transform.SetPositionAndRotation(
                    trackerTransform.Value.position,
                    trackerTransform.Value.rotation);
            }
        }
Esempio n. 2
0
            public static Vector3 GetDirection(Direction settings, TrackerReference trackers, CalibrationProfile profile)
            {
                switch (settings.type)
                {
                case DirectionType.WorldDirection:
                    return(settings.worldDirection);

                case DirectionType.TrackerDirection:
                    TransformValues?trackerFrom = trackers.GetTracker(settings.trackerFrom);
                    if (settings.trackerFromLocal)
                    {
                        if (profile.trackerOffsets.ContainsKey(settings.trackerFromLocalOffset) &&
                            profile.trackerOffsets[settings.trackerFromLocalOffset].position != null)
                        {
                            trackerFrom = trackers.GetTrackerWithOffset(settings.trackerFrom, profile.trackerOffsets[settings.trackerFromLocalOffset].Position, Quaternion.identity);
                        }
                    }

                    TransformValues?trackerTo = trackers.GetTracker(settings.trackerTo);
                    if (settings.trackerToLocal)
                    {
                        if (profile.trackerOffsets.ContainsKey(settings.trackerToLocalOffset) &&
                            profile.trackerOffsets[settings.trackerToLocalOffset].position != null)
                        {
                            trackerTo = trackers.GetTrackerWithOffset(settings.trackerTo, profile.trackerOffsets[settings.trackerToLocalOffset].Position, Quaternion.identity);
                        }
                    }

                    if (trackerFrom == null || trackerTo == null)
                    {
                        Debug.LogError("Not all trackers are connected");
                        break;
                    }

                    return(trackerTo.Value.position - trackerFrom.Value.position);
                }

                return(Vector3.zero);
            }
            public static Vector3 GetPoint(Point settings, TrackerReference trackers, CalibrationProfile profile)
            {
                switch (settings.type)
                {
                case PointType.Tracker:

                    TransformValues?trackerTransform = trackers.GetTracker(settings.tracker);

                    if (settings.useTrackerLocal)
                    {
                        if (!profile.trackerOffsets.ContainsKey(settings.trackerOffset) ||
                            profile.trackerOffsets[settings.trackerOffset].position == null)
                        {
                            break;
                        }

                        trackerTransform = trackers.GetTrackerWithOffset(settings.tracker, profile.trackerOffsets[settings.trackerOffset].Position, Quaternion.identity);
                    }

                    if (trackerTransform == null)
                    {
                        break;
                    }

                    return(trackerTransform.Value.position);

                    break;

                default:
                    Debug.LogError("Not Implemented");
                    break;
                }

                Debug.LogError("Something went wrong here");

                return(Vector3.zero);
            }
Esempio n. 4
0
        private void UpdateTrackerTargets()
        {
            foreach (VRTrackerType tracker in trackers.RequiredTrackers)
            {
                TransformValues?trackerTransform = trackers.GetTracker(tracker);

                Transform obj = null;

                switch (tracker)
                {
                case VRTrackerType.Head:
                    obj = head;

                    if (profile.trackerOffsets.ContainsKey(OffsetsToTrackers.HeadTrackerToHead))
                    {
                        TrackerOffset offset = profile.trackerOffsets[OffsetsToTrackers.HeadTrackerToHead];
                        trackerTransform = trackers.GetTrackerWithOffset(
                            VRTrackerType.Head,
                            offset.Position,
                            offset.Rotation);
                    }

                    break;

                case VRTrackerType.Waist:
                    obj = hip;

                    if (profile.trackerOffsets.ContainsKey(OffsetsToTrackers.HipTrackerToHip))
                    {
                        TrackerOffset offset = profile.trackerOffsets[OffsetsToTrackers.HipTrackerToHip];
                        trackerTransform = trackers.GetTrackerWithOffset(
                            VRTrackerType.Waist,
                            offset.Position,
                            offset.Rotation);
                    }

                    break;

                case VRTrackerType.LeftHand:
                    obj = leftHand;

                    if (profile.trackerOffsets.ContainsKey(OffsetsToTrackers.LeftHandTrackerToWrist))
                    {
                        TrackerOffset offset = profile.trackerOffsets[OffsetsToTrackers.LeftHandTrackerToWrist];
                        trackerTransform = trackers.GetTrackerWithOffset(
                            VRTrackerType.LeftHand,
                            offset.Position,
                            offset.Rotation);
                    }

                    break;

                case VRTrackerType.RightHand:
                    obj = rightHand;

                    if (profile.trackerOffsets.ContainsKey(OffsetsToTrackers.RightHandTrackerToWrist))
                    {
                        TrackerOffset offset = profile.trackerOffsets[OffsetsToTrackers.RightHandTrackerToWrist];
                        trackerTransform = trackers.GetTrackerWithOffset(
                            VRTrackerType.RightHand,
                            offset.Position,
                            offset.Rotation);
                    }

                    break;

                case VRTrackerType.LeftFoot:
                    obj = leftFoot;

                    if (profile.trackerOffsets.ContainsKey(OffsetsToTrackers.LeftFootTrackerToAnkle))
                    {
                        TrackerOffset offset = profile.trackerOffsets[OffsetsToTrackers.LeftFootTrackerToAnkle];
                        trackerTransform = trackers.GetTrackerWithOffset(
                            VRTrackerType.LeftFoot,
                            offset.Position,
                            offset.Rotation);
                    }

                    break;

                case VRTrackerType.RightFoot:
                    obj = rightFoot;

                    if (profile.trackerOffsets.ContainsKey(OffsetsToTrackers.RightFootTrackerToAnkle))
                    {
                        TrackerOffset offset = profile.trackerOffsets[OffsetsToTrackers.RightFootTrackerToAnkle];
                        trackerTransform = trackers.GetTrackerWithOffset(
                            VRTrackerType.RightFoot,
                            offset.Position,
                            offset.Rotation);
                    }

                    break;
                }

                if (trackerTransform == null || obj == null)
                {
                    continue;
                }

                filters[tracker].UpdateFilter(trackerTransform.Value.position, trackerTransform.Value.rotation);

                obj.position = useKalmanOnTrackerData ? filters[tracker].Position : trackerTransform.Value.position;
                obj.rotation = useKalmanOnTrackerData ? filters[tracker].Rotation : trackerTransform.Value.rotation;

                switch (tracker)
                {
                case VRTrackerType.LeftFoot:
                case VRTrackerType.RightFoot:
                    float _footHeight = 0.1346572f;

                    if (obj.position.y < _footHeight)
                    {
                        obj.position = new Vector3(obj.position.x, _footHeight, obj.position.z);
                    }

                    break;
                }
            }
        }