public override void UpdateComponent()
        {
            if (SteamDevice.status == Status.Unavailable)
            {
                status = Status.Unavailable;
            }

            if (SteamDevice.GetConfidence(trackerId) == 0)
            {
                status             = SteamDevice.IsPresent(trackerId) ? Status.Present : Status.Unavailable;
                positionConfidence = 0;
                rotationConfidence = 0;
                gameObject.SetActive(false);
                return;
            }

            status = Status.Tracking;
            Vector3    localSensorPosition = Target.ToVector3(SteamDevice.GetPosition(trackerId));
            Quaternion localSensorRotation = Target.ToQuaternion(SteamDevice.GetRotation(trackerId));

            transform.position = trackerTransform.TransformPoint(localSensorPosition);
            transform.rotation = trackerTransform.rotation * localSensorRotation;

            positionConfidence = SteamDevice.GetConfidence(trackerId);
            rotationConfidence = SteamDevice.GetConfidence(trackerId);
            gameObject.SetActive(true);

            FuseWithUnityCamera();
        }
        private void FindOutermostController(bool isLeft)
        {
            Vector outermostLocalPos = new Vector(isLeft ? -0.1F : 0.1F, 0, 0);

            for (int i = 0; i < Passer.OpenVR.k_unMaxTrackedDeviceCount; i++)
            {
                if (SteamDevice.GetDeviceClass(i) != Passer.ETrackedDeviceClass.Controller)
                {
                    continue;
                }

                Passer.ETrackedControllerRole role = Passer.OpenVR.System.GetControllerRoleForTrackedDeviceIndex((uint)i);
                if ((isLeft && role == Passer.ETrackedControllerRole.LeftHand) ||
                    (!isLeft && role == Passer.ETrackedControllerRole.RightHand))
                {
                    trackerId = i;
                    return;
                }

                Vector sensorLocalPos = Rotation.Inverse(SteamDevice.GetRotation(0)) * (SteamDevice.GetPosition(i) - SteamDevice.GetPosition(0)); // 0 = HMD

                if ((isLeft && sensorLocalPos.x < outermostLocalPos.x && role != Passer.ETrackedControllerRole.RightHand) ||
                    (!isLeft && sensorLocalPos.x > outermostLocalPos.x) && role != Passer.ETrackedControllerRole.LeftHand)
                {
                    trackerId         = i;
                    outermostLocalPos = sensorLocalPos;
                }
            }
        }
Example #3
0
        public override void UpdateTracker(bool showRealObjects)
        {
            if (subTrackerId == -1)
            {
                return;
            }

            bool isPresent = IsPresent();

            if (!isPresent)
            {
                return;
            }

            gameObject.SetActive(showRealObjects);

            transform.localPosition = Target.ToVector3(SteamDevice.GetPosition(subTrackerId));
            transform.localRotation = Target.ToQuaternion(SteamDevice.GetRotation(subTrackerId));
        }
        public override void UpdateComponent()
        {
            if (SteamDevice.status == Status.Unavailable)
            {
                status = Status.Unavailable;
            }

            //if (trackerId < 0)
            //    FindOutermostController(isLeft);

            if (SteamDevice.GetConfidence(trackerId) == 0)
            {
                status             = SteamDevice.IsPresent(trackerId) ? Status.Present : Status.Unavailable;
                positionConfidence = 0;
                rotationConfidence = 0;
                gameObject.SetActive(false);
                return;
            }

            status = Status.Tracking;
            Vector3    localSensorPosition = Target.ToVector3(SteamDevice.GetPosition(trackerId));
            Quaternion localSensorRotation = Target.ToQuaternion(SteamDevice.GetRotation(trackerId));

            transform.position = trackerTransform.TransformPoint(localSensorPosition);
            transform.rotation = trackerTransform.rotation * localSensorRotation;

            positionConfidence = SteamDevice.GetConfidence(trackerId);
            rotationConfidence = SteamDevice.GetConfidence(trackerId);
            gameObject.SetActive(true);

            Passer.VRControllerState_t controllerState = new Passer.VRControllerState_t();
            var  system = Passer.OpenVR.System;
            uint controllerStateSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(Passer.VRControllerState_t));
            bool newControllerState  = system.GetControllerState((uint)trackerId, ref controllerState, controllerStateSize);

            if (system != null && newControllerState)
            {
                UpdateInput(controllerState);
            }
        }