/****************************************************************************
* Copyright 2019 Nreal Techonology Limited. All rights reserved.
*
* This file is part of NRSDK.
*
* https://www.nreal.ai/
*
*****************************************************************************/
namespace NRKernal.Experimental.StreammingCast
{
using NRKernal.Record;
using UnityEngine;
/// A nr observer view behaviour.
public class NRObserverViewBehaviour : MonoBehaviour
{
/// The camera root.
[SerializeField]
private Transform m_CameraRoot;
/// Information describing the debug.
[SerializeField]
private GameObject m_DebugInfo;
/// The capture camera.
[SerializeField]
public Camera CaptureCamera;
/// The defualt fcc.
NativeMat3f defualtFCC = new NativeMat3f(
new Vector3(1402.06530528f, 0, 0),
new Vector3(0, 1401.16300406f, 0),
new Vector3(939.51336953f, 545.53574753f, 1)
);
/// Awakes this object.
void Awake()
{
m_DebugInfo.SetActive(false);
//Use default fov.
UpdateCameraParam(ProjectMatrixUtility.CalculateFOVByFCC(defualtFCC));
}
/// Switch debug panel.
/// True to isopen.
public void SwitchDebugPanel(bool isopen)
{
m_DebugInfo.SetActive(isopen);
}
/// Updates the pose described by pose.
/// The pose.
public void UpdatePose(Pose pose)
{
m_CameraRoot.position = pose.position;
m_CameraRoot.rotation = pose.rotation;
}
/// Sets culling mask.
/// Zero-based index of the.
public void SetCullingMask(int i)
{
this.CaptureCamera.cullingMask = i;
}
/// Updates the camera parameter described by fov.
/// The fov.
public void UpdateCameraParam(Fov4f fov)
{
//Update fov.
CaptureCamera.projectionMatrix = ProjectMatrixUtility.PerspectiveOffCenter(fov.left, fov.right, fov.bottom, fov.top,
CaptureCamera.nearClipPlane, CaptureCamera.farClipPlane);
NRDebugger.Info("[NRObserverViewBehaviour] UpdateCameraParam:" + CaptureCamera.projectionMatrix.ToString());
}
}
}