赞
踩
- using UnityEngine;
-
-
-
- /// <summary>
-
- /// Gyroscope controller that works with any device orientation.
-
- /// </summary>
-
- public class GyroController : MonoBehaviour
- {
-
- #region [Private fields]
-
-
-
- private bool gyroEnabled = true;
-
- private const float lowPassFilterFactor = 0.2f;
-
-
-
- private readonly Quaternion baseIdentity = Quaternion.Euler(90, 0, 0);
-
-
-
-
- private Quaternion cameraBase = Quaternion.identity;
-
- private Quaternion calibration = Quaternion.identity;
-
- private Quaternion baseOrientation = Quaternion.Euler(90, 0, 0);
-
- private Quaternion baseOrientationRotationFix = Quaternion.identity;
-
-
-
- private Quaternion referanceRotation = Quaternion.identity;
-
- private bool debug = false;
-
-
-
- #endregion
-
-
-
- #region [Unity events]
-
-
-
- protected void Start()
- {
-
- AttachGyro();
-
- }
-
-
-
- protected void Update()
- {
-
-
- if (!gyroEnabled)
-
- return;
-
- transform.rotation = Quaternion.Slerp(transform.rotation,
-
- cameraBase * (ConvertRotation(referanceRotation * Input.gyro.attitude) * GetRotFix()), lowPassFilterFactor);
-
- }
-
-
-
- protec
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。