Created
December 26, 2022 12:01
-
-
Save hatsunea/6d3fafb5927eaca88b1dc6a972c127bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class NRCameraRigParent : MonoBehaviour | |
{ | |
[SerializeField] | |
private Transform ARCameraTransform = null; | |
private Transform NrCameraRigTransform; | |
private void Awake() | |
{ | |
this.NrCameraRigTransform = transform.GetChild(0); | |
} | |
private void Update() | |
{ | |
transform.position = ARCameraTransform.position; | |
} | |
public void RecenterCamera() | |
{ | |
// Android 端末の水平方向の回転と Nreal の回転を一致させる | |
var arCameraYaw = GetYawRotation(this.ARCameraTransform.forward); | |
var nrCameraYaw = GetYawRotation(this.NrCameraRigTransform.forward); | |
var parentYaw = GetYawRotation(transform.forward); | |
parentYaw = parentYaw + arCameraYaw - nrCameraYaw; | |
var rotation = Quaternion.AngleAxis(parentYaw, Vector3.up); | |
transform.rotation = rotation; | |
} | |
private float GetYawRotation(Vector3 forward) | |
{ | |
var x = forward.x; | |
var z = forward.z; | |
return Mathf.Atan2(x, z) * Mathf.Rad2Deg; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment