NRObserverViewBehaviour.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal.Experimental.StreammingCast
  10. {
  11. using NRKernal.Record;
  12. using UnityEngine;
  13. /// <summary> A nr observer view behaviour. </summary>
  14. public class NRObserverViewBehaviour : MonoBehaviour
  15. {
  16. /// <summary> The camera root. </summary>
  17. [SerializeField]
  18. private Transform m_CameraRoot;
  19. /// <summary> Information describing the debug. </summary>
  20. [SerializeField]
  21. private GameObject m_DebugInfo;
  22. /// <summary> The capture camera. </summary>
  23. [SerializeField]
  24. public Camera CaptureCamera;
  25. /// <summary> The defualt fcc. </summary>
  26. NativeMat3f defualtFCC = new NativeMat3f(
  27. new Vector3(1402.06530528f, 0, 0),
  28. new Vector3(0, 1401.16300406f, 0),
  29. new Vector3(939.51336953f, 545.53574753f, 1)
  30. );
  31. /// <summary> Awakes this object. </summary>
  32. void Awake()
  33. {
  34. m_DebugInfo.SetActive(false);
  35. //Use default fov.
  36. UpdateCameraParam(ProjectMatrixUtility.CalculateFOVByFCC(defualtFCC));
  37. }
  38. /// <summary> Switch debug panel. </summary>
  39. /// <param name="isopen"> True to isopen.</param>
  40. public void SwitchDebugPanel(bool isopen)
  41. {
  42. m_DebugInfo.SetActive(isopen);
  43. }
  44. /// <summary> Updates the pose described by pose. </summary>
  45. /// <param name="pose"> The pose.</param>
  46. public void UpdatePose(Pose pose)
  47. {
  48. m_CameraRoot.position = pose.position;
  49. m_CameraRoot.rotation = pose.rotation;
  50. }
  51. /// <summary> Sets culling mask. </summary>
  52. /// <param name="i"> Zero-based index of the.</param>
  53. public void SetCullingMask(int i)
  54. {
  55. this.CaptureCamera.cullingMask = i;
  56. }
  57. /// <summary> Updates the camera parameter described by fov. </summary>
  58. /// <param name="fov"> The fov.</param>
  59. public void UpdateCameraParam(Fov4f fov)
  60. {
  61. //Update fov.
  62. CaptureCamera.projectionMatrix = ProjectMatrixUtility.PerspectiveOffCenter(fov.left, fov.right, fov.bottom, fov.top,
  63. CaptureCamera.nearClipPlane, CaptureCamera.farClipPlane);
  64. NRDebugger.Info("[NRObserverViewBehaviour] UpdateCameraParam:" + CaptureCamera.projectionMatrix.ToString());
  65. }
  66. }
  67. }