2017-10-25 5 views
0

내 화합 장면에서 구형 내부에 360 비디오가 있고 사용자가 회전하여 영화를 볼 수 있도록 자이로 스크립트를 사용하고 있습니다. 문제는 영화에 사람이 있다는 것입니다. 나는 카메라가 사람의 입장이 아닌 모바일의 위치에서 시작하고 싶어하지만, 내가 할 노력하고있어 방법이 작동하지 않습니다 :시작 위치 자이로 스코프 카메라 유니티

public class Gyro : MonoBehaviour 
{ 


    void Start() 
    { 
     if (SystemInfo.supportsGyroscope) 
     { 
      Input.gyro.enabled = true; 
     } 


      GameObject cameraParent = new GameObject("camParent"); 
      cameraParent.transform.position = this.transform.position; 
      this.transform.parent = cameraParent.transform; 
      cameraParent.transform.Rotate(Vector3.right, 90); 

    } 


    void Update() 
    { 


      Quaternion cameraRotation = new Quaternion(Input.gyro.attitude.x, Input.gyro.attitude.y, -Input.gyro.attitude.z, -Input.gyro.attitude.w); 
      this.transform.localRotation = cameraRotation; 


    } 
} 

솔루션

void Start() 
{ 
     Application.targetFrameRate = 60; 
     initialYAngle = transform.eulerAngles.y; 
     Input.gyro.enabled = true; 
    } 

    void Update() 
    { 
     if(calibra){ 
      CalibrateYAngle(); 
      calibra = false; 
     } 
     ApplyGyroRotation(); 
     ApplyCalibration(); 
    } 



    public void CalibrateYAngle() 
    { 
     calibrationYAngle = appliedGyroYAngle - initialYAngle; // Offsets the y angle in case it wasn't 0 at edit time. 
    } 

    void ApplyGyroRotation() 
    { 
     transform.rotation = Input.gyro.attitude; 
     transform.Rotate(0f, 0f, 180f, Space.Self); // Swap "handedness" of quaternion from gyro. 
     transform.Rotate(90f, 180f, 0f, Space.World); // Rotate to make sense as a camera pointing out the back of your device. 
     appliedGyroYAngle = transform.eulerAngles.y; // Save the angle around y axis for use in calibration. 
    } 

    void ApplyCalibration() 
    { 
     transform.Rotate(0f, -calibrationYAngle, 0f, Space.World); // Rotates y angle back however much it deviated when calibrationYAngle was saved. 
    } 
+0

[this] (https://stackoverflow.com/q/46935419/3785314) 사람과 같은 것입니까? – Programmer

답변

1
 Quaternion cameraRotation = new Quaternion(Input.gyro.attitude.x, Input.gyro.attitude.y, -Input.gyro.attitude.z, -Input.gyro.attitude.w); 
     this.transform.localRotation = cameraRotation; 

카메라로 정확한 위치에서 카메라를 시작하려면 자이로 스코프 위치 만 지정하십시오. 마지막 프레임과 현재 프레임의 차이를 현재 위치에 더하거나 빼야합니다.

관련 문제