Exemplo n.º 1
0
        private void UpdateCardboard()
        {
            if (cardboard != null)
            {
                Vector3 baseDelta = ivr.transform.position - baseStartPoint;
                cardboard.transform.position = cardboardStartPoint + baseDelta;

                float baseAngleDelta = ivr.transform.eulerAngles.y - baseStartAngle;
                cardboard.transform.rotation = cardboardStartRotation * Quaternion.AngleAxis(baseAngleDelta, Vector3.up);

                if (cardboard.HeadPose != null)
                {
                    controllerPosition = startPosition;

                    controllerRotation = cardboard.HeadPose.Orientation * Quaternion.AngleAxis(-baseAngleDelta, Vector3.up);;

                    tracking = true;

                    base.UpdateController();
                }
#if INSTANTVR_ADVANCED
                if (tracking && vicoVRHead != null && vicoVRHead.isTracking())
                {
                    position           = vicoVRHead.position;
                    transform.position = position;
                    Vector3 neckOffset = transform.rotation * controllerRotation * localNeckOffset;
                    cardboard.transform.position = position + neckOffset;
                }
#endif
            }
        }
Exemplo n.º 2
0
        private void SetHeadTargets()
        {
            if (tracking)
            {
                transform.rotation = cameraTransform.rotation;
                if (positionalTracking)
                {
                    transform.position = cameraTransform.position + cameraTransform.rotation * -neck2eyes;
                }
#if INSTANTVR_ADVANCED
                else
                {
                    if (kinect2Head != null && kinect2Head.isTracking())
                    {
                        transform.position = kinect2Head.position;
                    }
                    else if (vicoVRHead != null && vicoVRHead.isTracking())
                    {
                        transform.position = vicoVRHead.position;
                    }
                }
#endif
            }
        }
        private void SetHeadTargets()
        {
#if UNITY_ANDROID
            if (cardboard.HeadPose != null)
            {
                tracking           = true;
                transform.rotation = cameraTransform.rotation;
                Vector3 target2camera = transform.position + neck2eyes - cameraTransform.position;
                cameraRoot.transform.position += target2camera;
#if INSTANTVR_ADVANCED
                if (vicoVRHead != null && vicoVRHead.isTracking())
                {
                    transform.position = vicoVRHead.position;
                }
#endif
            }
#endif
        }
Exemplo n.º 4
0
        private void UpdateRift()
        {
            tracking = true;
            Quaternion calibrationRotation = extension.trackerRotation * Quaternion.AngleAxis(180, Vector3.up) * Quaternion.Inverse(OVRManager.tracker.GetPose(0).orientation);

            Quaternion trackerOrientation = OVRManager.tracker.GetPose(0).orientation;

            if (OVRManager.tracker.isPositionTracked)
            {
                if (!positionTracking && lastTrackerOrientation != trackerOrientation)
                {
                    headcamRoot.transform.position = ivr.transform.position + startPosition;
                    headcamRoot.transform.rotation = ivr.transform.rotation * startRotation;

                    Vector3 eye2trackerPosition =
                        (calibrationRotation * -OVRManager.tracker.GetPose(0).position)
                        + (calibrationRotation * InputTracking.GetLocalPosition(VRNode.CenterEye));

                    if (extension.trackerPosition.magnitude == 0 && extension.trackerEulerAngles.magnitude == 0)
                    {
                        extension.trackerPosition    = Quaternion.Inverse(ivr.transform.rotation) * (headcam.position - ivr.transform.position) - eye2trackerPosition;
                        extension.trackerRotation    = Quaternion.identity;
                        extension.trackerEulerAngles = extension.trackerRotation.eulerAngles;
                    }

                    Vector3 worldEyePosition = ivr.transform.position + ivr.transform.rotation * (extension.trackerPosition + eye2trackerPosition);
                    calibrationRotation = extension.trackerRotation * Quaternion.AngleAxis(180, Vector3.up) * Quaternion.Inverse(OVRManager.tracker.GetPose(0).orientation);

                    headcamRoot.transform.Translate(worldEyePosition - headcam.position, Space.World);
                    headcamRoot.transform.rotation = ivr.transform.rotation * calibrationRotation;

                    positionTracking = true;
                }
                lastTrackerOrientation = OVRManager.tracker.GetPose(0).orientation;
            }
            else
            {
                positionTracking = false;

#if INSTANTVR_ADVANCED
                if (kinect2Head != null && kinect2Head.isTracking())
                {
                    transform.position = kinect2Head.position;
                }
                else if (vicoVRHead != null && vicoVRHead.isTracking())
                {
                    transform.position = vicoVRHead.position;
                }
#endif
            }

            Quaternion inverseIvrRotation     = Quaternion.Inverse(ivr.transform.rotation);
            Quaternion inverseTrackerRotation = Quaternion.Inverse(extension.trackerRotation);

            controllerRotation = inverseIvrRotation * headcam.rotation;

#if IVR_DEBUG
            Debug.DrawRay(ivr.transform.position + ivr.transform.rotation * (extension.trackerPosition),
                          ivr.transform.rotation * (calibrationRotation * -OVRManager.tracker.GetPose(0).position), Color.green);
            Debug.DrawRay(ivr.transform.position + ivr.transform.rotation * (extension.trackerPosition - (calibrationRotation * OVRManager.tracker.GetPose(0).position)),
                          ivr.transform.rotation * (-(calibrationRotation * -InputTracking.GetLocalPosition(VRNode.Head))), Color.red);
            Debug.DrawRay(ivr.transform.position + ivr.transform.rotation * (extension.trackerPosition - (calibrationRotation * OVRManager.tracker.GetPose(0).position)
                                                                             - (calibrationRotation * -InputTracking.GetLocalPosition(VRNode.Head))), ivr.transform.rotation * (-(this.rotation * localNeckOffset)), Color.blue);
#endif

            if (positionTracking)
            {
                Vector3 localPosition1    = inverseIvrRotation * (headcam.position - ivr.transform.position);
                Vector3 localNeckPosition = localPosition1 - extension.trackerRotation * controllerRotation * localNeckOffset;

                controllerPosition = inverseTrackerRotation * (localNeckPosition - extension.trackerPosition);

                Vector3 localPosition = extension.trackerPosition + extension.trackerRotation * controllerPosition;

                position = ivr.transform.position + ivr.transform.rotation * localPosition;
                if (selected)
                {
                    transform.position = position;
                }
            }

            if (selected)
            {
                Quaternion localRotation = extension.trackerRotation * controllerRotation;
                transform.rotation = ivr.transform.rotation * localRotation;
            }
        }