1인칭 시점으로 마구잡이 돌릴때...

* 오큘러스 카메라 앵글에 사용

using UnityEngine; 
using System.Collections; 
public class Behavior_Cam_Tilt : MonoBehaviour { 
     private Quaternion cameraBase = Quaternion.Euler(new Vector3(3f, 180f, 0f)); 
     private Quaternion referanceRotation = Quaternion.identity; 
     private const float lowPassFilterFactor = 0.2f; 
     void Start() { Input.gyro.enabled = true; } 
     void Update() {
           //transform.rotation = ConvertRotation(Input.gyro.attitude);
           transform.rotation = Quaternion.Slerp(transform.rotation, cameraBase * (ConvertRotation(referanceRotation * Input.gyro.attitude) * GetRotFix()), lowPassFilterFactor); 
      } 

     private static Quaternion ConvertRotation(Quaternion q) { 
           return new Quaternion(q.x, q.y, -q.z, -q.w); 
     } 
     private Quaternion GetRotFix() { 
            if (Screen.orientation == ScreenOrientation.Portrait) return Quaternion.identity; 
            if (Screen.orientation == ScreenOrientation.LandscapeLeft || Screen.orientation == ScreenOrientation.Landscape) return Quaternion.Euler(0, 0, -90); 
            if (Screen.orientation == ScreenOrientation.LandscapeRight) return Quaternion.Euler(0, 0, 90); 
            if (Screen.orientation == ScreenOrientation.PortraitUpsideDown) return Quaternion.Euler(0, 0, 180); 
            return Quaternion.identity; 
      } 
}
2014/04/07 17:27 2014/04/07 17:27

트랙백 주소 :: 이 글에는 트랙백을 보낼 수 없습니다