public override TrackingNode CreateTrackingNode(string name)
        {
            TrackingNode node = new TrackingNode();

            trackingNodes[name] = node;
            return(node);
        }
        void updateHeadTracking()
        {
            TrackingNode head = trackingNodes[TrackingNode.HEAD];

            Vector3 screenRotation = new Vector3(-90, 0, 90);
            Vector3 rotationRate   = Vector3.zero;
            Vector3 accel          = default(Vector3);

            var raw = gyro.GetCurrentReading();

            rotationRate  = new Vector3((float)-raw.AngularVelocityX, (float)-raw.AngularVelocityY, (float)raw.AngularVelocityZ) * Time.deltaTime;
            head.Rotation = head.Rotation * Quaternion.Euler(-rotationRate.x, -rotationRate.y, rotationRate.z);

            if (accel == default(Vector3))
            {
                accel = Input.acceleration;
            }

            //perform orientation transform for landscape left
            accel = new Vector3(-accel.x, accel.y, accel.z);

            Vector3 pitchVector = Vector3.ProjectOnPlane(accel, Vector3.right).normalized;
            Vector3 rollVector  = Vector3.ProjectOnPlane(accel, Vector3.forward).normalized;

            float pitch = Mathf.Atan2(-pitchVector.y, pitchVector.z) * Mathf.Rad2Deg;
            float roll  = Mathf.Atan2(rollVector.y, rollVector.x) * Mathf.Rad2Deg;

            Quaternion rotation = Quaternion.Euler(new Vector3(pitch, head.Rotation.eulerAngles.y, roll) + screenRotation);

            //This represents a basic complimentary filter, it's not good long term we should use a Kalman filter here [ld]
            head.Rotation = Quaternion.Slerp(head.Rotation, rotation, 1.0F * Time.deltaTime);
        }
        public override TrackingNode GetTrackingNode(string name)
        {
            TrackingNode node = null;

            if (trackingNodes.TryGetValue(name, out node))
            {
                return(node);
            }

            return(null);
        }
            void updateHeadTracking()
            {
                TrackingNode head = trackingNodes[TrackingNode.HEAD];

                if (Application.isEditor)
                {
                    if (Input.GetMouseButtonDown(1))
                    {
                        lastMouse = Input.mousePosition;
                    }

                    if (!Input.GetMouseButton(1))
                    {
                        return;
                    }

                    Vector3 deltaMouse = Input.mousePosition - lastMouse;
                    lastMouse = Input.mousePosition;

                    head.Rotation = head.Rotation
                                    * Quaternion.AngleAxis(-deltaMouse.y, Vector3.right)
                                    * Quaternion.AngleAxis(deltaMouse.x, Vector3.up);

                    head.Rotation.eulerAngles = new Vector3(head.Rotation.eulerAngles.x, head.Rotation.eulerAngles.y, 0);
                    return;
                }

                Vector3 screenRotation = new Vector3(-90, 0, 90);
                Vector3 rotationRate   = Vector3.zero;
                Vector3 accel          = default(Vector3);

                rotationRate  = Input.gyro.rotationRate * Time.deltaTime;
                head.Rotation = head.Rotation * Quaternion.Euler(-rotationRate.x, -rotationRate.y, rotationRate.z);

                if (accel == default(Vector3))
                {
                    accel = Input.acceleration;
                }

                //perform orientation transform for landscape left
                accel = new Vector3(-accel.x, accel.y, accel.z);

                Vector3 pitchVector = Vector3.ProjectOnPlane(accel, Vector3.right).normalized;
                Vector3 rollVector  = Vector3.ProjectOnPlane(accel, Vector3.forward).normalized;

                float pitch = Mathf.Atan2(-pitchVector.y, pitchVector.z) * Mathf.Rad2Deg;
                float roll  = Mathf.Atan2(rollVector.y, rollVector.x) * Mathf.Rad2Deg;

                Quaternion rotation = Quaternion.Euler(new Vector3(pitch, head.Rotation.eulerAngles.y, roll) + screenRotation);

                //This represents a basic complimentary filter, it's not good long term we should use a Kalman filter here [ld]
                head.Rotation = Quaternion.Slerp(head.Rotation, rotation, 1.0F * Time.deltaTime);
            }
Пример #5
0
        void LateUpdate()
        {
            SdkTrackingDriver.Instance.UpdateTracking();

            foreach (Transform child in transform)
            {
                TrackingNode node = SdkTrackingDriver.Instance.GetTrackingNode(child.name.ToLower());

                if (node != null)
                {
                    child.localPosition = node.LocalPosition;
                    child.rotation      = node.Rotation;
                }
            }
        }
Пример #6
0
        void LateUpdate()
        {
            if (Application.isEditor)
            {
                return; // in editor no gyroscope is available, rely on other controls (e.g. MouseLook script)
            }
            SdkTrackingDriver.Instance.UpdateTracking();

            foreach (Transform child in transform)
            {
                TrackingNode node = SdkTrackingDriver.Instance.GetTrackingNode(child.name.ToLower());

                if (node != null)
                {
                    child.localPosition = node.LocalPosition;
                    child.rotation      = node.Rotation;
                }
            }
        }