Ejemplo n.º 1
0
        public override void Update()
        {
            if (tracker == null || !tracker.enabled || !enabled)
            {
                return;
            }

            if (hmd == null)
            {
                hmd = sensorTransform.GetComponent <OpenVRHmd>();
                UpdateTarget(headTarget.head.target, sensorTransform);
            }

            hmd.UpdateComponent();
            if (hmd.status != Status.Tracking)
            {
                return;
            }

            if (!calibrated && tracker.humanoid.calibrateAtStart)
            {
                tracker.humanoid.Calibrate();
                calibrated = true;
            }

            UpdateTarget(headTarget.head.target, hmd);
            UpdateNeckTargetFromHead();
        }
Ejemplo n.º 2
0
        protected OpenVRHmd FindHmd(uint sensorId)
        {
            if (hmd != null && hmd.trackerId == sensorId)
            {
                return(hmd);
            }

            OpenVRHead openVRHead = humanoid.headTarget.openVR;

            if (openVRHead.hmd != null)
            {
                openVRHead.hmd.trackerId = (int)sensorId;
                hmd = openVRHead.hmd;
                return(hmd);
            }

            // See if a HMD already exists in the Real World
            OpenVRHmd openVRHmd = trackerTransform.GetComponentInChildren <OpenVRHmd>();

            if (openVRHmd != null)
            {
                openVRHmd.trackerId = (int)sensorId;
                hmd            = openVRHmd;
                openVRHead.hmd = openVRHmd;
                return(hmd);
            }

            return(null);
        }
Ejemplo n.º 3
0
        protected override void CreateSensorTransform()
        {
            CreateSensorTransform("OpenVR HMD", headTarget.head2eyes, Quaternion.identity);
            OpenVRHmd openVRHmd = sensorTransform.GetComponent <OpenVRHmd>();

            if (openVRHmd == null)
            {
                sensorTransform.gameObject.AddComponent <OpenVRHmd>();
            }
        }
Ejemplo n.º 4
0
            protected static void CheckHmdComponent(HeadTarget headTarget)
            {
                if (headTarget.openVR.sensorTransform == null)
                {
                    return;
                }

                OpenVRHmd sensorComponent = headTarget.openVR.sensorTransform.GetComponent <OpenVRHmd>();

                if (sensorComponent == null)
                {
                    headTarget.openVR.sensorTransform.gameObject.AddComponent <OpenVRHmd>();
                }
            }
Ejemplo n.º 5
0
        protected virtual void OnNewSensor(uint sensorId)
        {
            Passer.ETrackedDeviceClass deviceClass = Passer.OpenVR.System.GetTrackedDeviceClass(sensorId);
            switch (deviceClass)
            {
            case Passer.ETrackedDeviceClass.HMD:
                hmd = FindHmd(sensorId);
                if (hmd == null)
                {
                    hmd = OpenVRHmd.NewHmd(humanoid, (int)sensorId);
                }
                break;

            case Passer.ETrackedDeviceClass.TrackingReference:
                SubTracker subTracker = FindLighthouse(sensorId);
                if (subTracker == null)
                {
                    subTrackers.Add(NewLighthouse(humanoid, sensorId));
                }
                break;

            case Passer.ETrackedDeviceClass.Controller:
                OpenVRController controller = FindController(sensorId);
                if (controller == null)
                {
                    controllers.Add(OpenVRController.NewController(humanoid, (int)sensorId));
                }
                break;

#if hVIVETRACKER
            case Passer.ETrackedDeviceClass.GenericTracker:
                ViveTrackerComponent viveTracker = FindViveTracker(sensorId);
                if (viveTracker == null)
                {
                    viveTrackers.Add(ViveTracker.NewViveTracker(humanoid, sensorId));
                }
                break;
#endif
            default:
                break;
            }
        }
Ejemplo n.º 6
0
        public override void Start(HumanoidControl _humanoid, Transform targetTransform)
        {
            base.Start(_humanoid, targetTransform);
            tracker = headTarget.humanoid.openVR;

            if (tracker == null || !tracker.enabled || !enabled)
            {
                return;
            }

            SetSensor2Target();
            CheckSensorTransform();
            sensor2TargetPosition = -headTarget.head2eyes;

            if (sensorTransform != null)
            {
                hmd = sensorTransform.GetComponent <OpenVRHmd>();
                if (hmd != null)
                {
                    hmd.StartComponent(tracker.trackerTransform);
                }
            }
        }
Ejemplo n.º 7
0
        public static OpenVRHmd NewHmd(HumanoidControl humanoid, int trackerId = -1)
        {
            GameObject trackerPrefab = Resources.Load(resourceName) as GameObject;
            GameObject trackerObject = (trackerPrefab == null) ? new GameObject(resourceName) : Instantiate(trackerPrefab);

            trackerObject.name = resourceName;

            OpenVRHmd trackerComponent = trackerObject.GetComponent <OpenVRHmd>();

            if (trackerComponent == null)
            {
                trackerComponent = trackerObject.AddComponent <OpenVRHmd>();
            }

            if (trackerId != -1)
            {
                trackerComponent.trackerId = trackerId;
            }
            trackerObject.transform.parent = humanoid.openVR.trackerTransform;

            trackerComponent.StartComponent(humanoid.openVR.trackerTransform);

            return(trackerComponent);
        }
Ejemplo n.º 8
0
 private void OnEnable()
 {
     sensorComponent = (OpenVRHmd)target;
 }