Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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