Esempio n. 1
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);
            }
Esempio n. 2
0
        private void VisualizeTrackerOffsets()
        {
            for (int i = 0; i < profile.trackerOffsets.Keys.Count; i++)
            {
                if (trackerOffsetVisuals.Count < i + 1)
                {
                    trackerOffsetVisuals.Add(GameObject.CreatePrimitive(PrimitiveType.Sphere));
                    trackerOffsetVisuals[i].GetComponent <MeshRenderer>().material.color = Color.black;
                    trackerOffsetVisuals[i].transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
                    trackerOffsetVisuals[i].transform.SetParent(transform);
                }

                OffsetsToTrackers offsetType = profile.trackerOffsets.Keys.ToArray()[i];
                VRTrackerType     type       = CalibrationProfile.GetMatchingTrackerFromOffset(offsetType) ?? VRTrackerType.Other;

                TrackerOffset offset = profile.trackerOffsets[offsetType];

                TransformValues?trackerWithOffset = trackers.GetTrackerWithOffset(type, offset.Position, Quaternion.identity);

                if (trackerWithOffset == null)
                {
                    if (trackerOffsetVisuals[i].activeSelf)
                    {
                        trackerOffsetVisuals[i].SetActive(false);
                    }
                    continue;
                }

                if (!trackerOffsetVisuals[i].activeSelf)
                {
                    trackerOffsetVisuals[i].SetActive(true);
                }

                trackerOffsetVisuals[i]?.transform.SetPositionAndRotation(
                    trackerWithOffset.Value.position,
                    trackerWithOffset.Value.rotation);
            }
        }
            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;
                }
            }
        }