CameraComponent.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Scene/Components/SceneComponent.h>
  7. #include <AnKi/Scene/Frustum.h>
  8. namespace anki {
  9. /// @addtogroup scene
  10. /// @{
  11. /// Perspective camera component.
  12. class CameraComponent : public SceneComponent
  13. {
  14. ANKI_SCENE_COMPONENT(CameraComponent)
  15. public:
  16. CameraComponent(SceneNode* node);
  17. ~CameraComponent();
  18. void setNear(F32 near)
  19. {
  20. if(ANKI_EXPECT(near > 0.0f))
  21. {
  22. m_frustum.setNear(near);
  23. }
  24. }
  25. F32 getNear() const
  26. {
  27. return m_frustum.getNear();
  28. }
  29. void setFar(F32 far)
  30. {
  31. if(ANKI_EXPECT(far > 0.0f))
  32. {
  33. m_frustum.setFar(far);
  34. }
  35. }
  36. F32 getFar() const
  37. {
  38. return m_frustum.getFar();
  39. }
  40. void setFovX(F32 fovx)
  41. {
  42. if(ANKI_EXPECT(fovx > 0.0f && fovx < kPi))
  43. {
  44. m_frustum.setFovX(fovx);
  45. }
  46. }
  47. F32 getFovX() const
  48. {
  49. return m_frustum.getFovX();
  50. }
  51. void setFovY(F32 fovy)
  52. {
  53. if(ANKI_EXPECT(fovy > 0.0f && fovy < kPi))
  54. {
  55. m_frustum.setFovY(fovy);
  56. }
  57. }
  58. F32 getFovY() const
  59. {
  60. return m_frustum.getFovY();
  61. }
  62. void setPerspective(F32 near, F32 far, F32 fovx, F32 fovy)
  63. {
  64. m_frustum.setPerspective(near, far, fovx, fovy);
  65. }
  66. ANKI_INTERNAL const Frustum& getFrustum() const
  67. {
  68. return m_frustum;
  69. }
  70. ANKI_INTERNAL Frustum& getFrustum()
  71. {
  72. return m_frustum;
  73. }
  74. private:
  75. Frustum m_frustum;
  76. void update(SceneComponentUpdateInfo& info, Bool& updated) override;
  77. };
  78. /// @}
  79. } // end namespace anki