protected static void CheckControllerComponent(HandTarget handTarget)
            {
                if (handTarget.openVR.sensorTransform == null)
                {
                    return;
                }

                OpenVRController sensorComponent = handTarget.openVR.sensorTransform.GetComponent <OpenVRController>();

                if (sensorComponent == null)
                {
                    sensorComponent = handTarget.openVR.sensorTransform.gameObject.AddComponent <OpenVRController>();
                }
                sensorComponent.isLeft = handTarget.isLeft;
            }
Exemple #2
0
        protected OpenVRController FindController(uint sensorId)
        {
            foreach (OpenVRController controller in controllers)
            {
                if (controller != null && controller.trackerId == sensorId)
                {
                    return(controller);
                }
            }
            if (OpenVRController.IsLeftController(sensorId))
            {
                OpenVRHand leftHand = humanoid.leftHandTarget.openVR;
                if (leftHand != null && leftHand.openVRController != null)
                {
                    leftHand.openVRController.trackerId = (int)sensorId;
                    // leftHand Controller was not in controller list yet
                    controllers.Add(leftHand.openVRController);
                    return(leftHand.openVRController);
                }
            }
            else
            if (OpenVRController.IsRightController(sensorId))
            {
                OpenVRHand rightHand = humanoid.rightHandTarget.openVR;
                if (rightHand != null && rightHand.openVRController != null)
                {
                    rightHand.openVRController.trackerId = (int)sensorId;
                    // rightHand Controller was not in controller list yet
                    controllers.Add(rightHand.openVRController);
                    return(rightHand.openVRController);
                }
            }

            // See if the controller already exists in the Real World
            OpenVRController[] openVRControllers = trackerTransform.GetComponentsInChildren <OpenVRController>();
            foreach (OpenVRController controller in openVRControllers)
            {
                if (controller.trackerId == sensorId)
                {
                    // controller was not in controller list yet
                    controllers.Add(controller);
                    return(controller);
                }
            }

            return(null);
        }
Exemple #3
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;
            }
        }
Exemple #4
0
        //        public override void RefreshSensor() {
        //            if (openVRController != null) {
        //#if UNITY_EDITOR
        //                Object.DestroyImmediate(openVRController, true);
        //#else
        //                Object.Destroy(openVRController);
        //#endif
        //            }

        //            CreateSensorTransform();
        //        }

        protected override void CreateSensorTransform()
        {
            string prefabLeftName  = "Vive Controller";
            string prefabRightName = "Vive Controller";

            switch (controllerType)
            {
            case OpenVRController.ControllerType.ValveIndex:
                break;

            case OpenVRController.ControllerType.MixedReality:
                prefabLeftName  = "Windows MR Controller Left";
                prefabRightName = "Windows MR Controller Right";
                break;

            case OpenVRController.ControllerType.OculusTouch:
                prefabLeftName  = "Left Touch Controller";
                prefabRightName = "Right Touch Controller";
                break;

            case OpenVRController.ControllerType.SteamVRController:
            default:
                break;
            }

            if (handTarget.isLeft)
            {
                CreateSensorTransform(prefabLeftName, new Vector3(-0.14F, -0.04F, 0.08F), Quaternion.Euler(0, -30, -90));
            }
            else
            {
                CreateSensorTransform(prefabRightName, new Vector3(0.14F, -0.04F, 0.08F), Quaternion.Euler(0, 30, 90));
            }

            openVRController = sensorTransform.GetComponent <OpenVRController>();
            if (openVRController == null)
            {
                openVRController = sensorTransform.gameObject.AddComponent <OpenVRController>();
            }
            openVRController.isLeft = handTarget.isLeft;
        }
Exemple #5
0
        protected Quaternion GetFingerRotation(OpenVRController openVRController, int fingerIx, int boneIx)
        {
            int ix = fingerIx * 5 + boneIx + 2;

            Passer.VRBoneTransform_t boneTransform = openVRController.tempBoneTransforms[ix];

            Quaternion q = new Quaternion(
                boneTransform.orientation.x,
                boneTransform.orientation.y,
                boneTransform.orientation.z,
                boneTransform.orientation.w
                );

            if (!handTarget.isLeft)
            {
                q = new Quaternion(q.x, -q.y, -q.z, q.w);
            }
            if (fingerIx == 0)
            {
                if (boneIx == 0)
                {
                    q = Rotations.Rotate(q, Quaternion.Euler(90, 0, 0));
                    if (handTarget.isLeft)
                    {
                        q = Quaternion.Euler(0, -180, -90) * q;
                    }
                    else
                    {
                        q = Quaternion.Euler(180, -180, -90) * q;
                    }
                }
                else
                {
                    q = Rotations.Rotate(q, Quaternion.Euler(90, 0, 0));
                }
            }
            return(q);
        }
Exemple #6
0
        public override void Start(HumanoidControl _humanoid, Transform targetTransform)
        {
            base.Start(_humanoid, targetTransform);
            tracker = handTarget.humanoid.openVR;

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

            SetSensor2Target();
            CheckSensorTransform();
            ShowSensor(handTarget.humanoid.showRealObjects && target.showRealObjects);

            if (sensorTransform != null)
            {
                openVRController = sensorTransform.GetComponent <OpenVRController>();
                if (openVRController != null)
                {
                    openVRController.StartComponent(tracker.trackerTransform);
                }
            }
        }
        public static OpenVRController NewController(HumanoidControl humanoid, int trackerId = -1)
        {
            GameObject trackerPrefab = Resources.Load(resourceName) as GameObject;
            GameObject trackerObject = (trackerPrefab == null) ? new GameObject(resourceName) : Instantiate(trackerPrefab);

            trackerObject.name = resourceName;

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

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

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

            trackerComponent.StartComponent(humanoid.openVR.trackerTransform);

            return(trackerComponent);
        }
            //SerializedProperty controllerTypeProp;

            private void OnEnable()
            {
                controllerComponent = (OpenVRController)target;

                //controllerTypeProp = serializedObject.FindProperty("controllerType");
            }