Camera.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  3. Permission is hereby granted, free of charge, to any person
  4. obtaining a copy of this software and associated documentation
  5. files (the "Software"), to deal in the Software without
  6. restriction, including without limitation the rights to use,
  7. copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the
  9. Software is furnished to do so, subject to the following
  10. conditions:
  11. The above copyright notice and this permission notice shall be
  12. included in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  15. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  17. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  18. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #pragma once
  23. #include "Types.h"
  24. #include "Frustum.h"
  25. #include "Mat4.h"
  26. #include "Vec3.h"
  27. namespace crown
  28. {
  29. class Camera
  30. {
  31. public:
  32. //! Constructor
  33. Camera(const Vec3& position, const Angles& axis, bool visible, float fov, float aspect, bool active);
  34. //! Destructor
  35. virtual ~Camera();
  36. //! Sets the camera's position
  37. void SetPosition(const Vec3& position);
  38. //! Returns the camera's lookat-point
  39. const Vec3& GetLookAt() const;
  40. //! Sets the camera's lookat-point
  41. void SetLookAt(const Vec3& lookat);
  42. //! Returns the camera's up vector
  43. const Vec3& GetUpVector() const;
  44. //! Returns whether the camera is active
  45. bool IsActive() const;
  46. //! Sets whether the camera is active
  47. void SetActive(bool active);
  48. //! Returns the camera's Field Of View
  49. float GetFOV() const;
  50. //! Sets the camera's Field Of View
  51. void SetFOV(float fov);
  52. //! Returns whether the camera automatically adjusts aspect ratio based on the Viewport
  53. bool GetAutoAspect() const;
  54. //! Sets whether the camera automatically adjusts aspect ratio based on the Viewport
  55. void SetAutoAspect(bool autoAspect);
  56. //! Returns the camera's aspect ratio
  57. float GetAspect() const;
  58. //! Sets the camera's aspect ratio
  59. void SetAspect(float aspect);
  60. //! Returns the camera's near clipping distance
  61. float GetNearClipDistance() const;
  62. //! Sets the camera's near clipping distance
  63. void SetNearClipDistance(float near);
  64. //! Returns the camera's far clipping distance
  65. float GetFarClipDistance() const;
  66. //! Sets the camera's far clipping distance
  67. void SetFarClipDistance(float far);
  68. //! Returns the camera's view frustum
  69. const Frustum& GetFrustum() const;
  70. //! Returns the projection matrix
  71. const Mat4& GetProjectionMatrix() const;
  72. //! Returns the view matrix
  73. const Mat4& GetViewMatrix() const;
  74. //! Loads the view and projection matrix
  75. virtual void Render();
  76. const Vec3& GetPosition() const { return mPosition; }
  77. protected:
  78. void UpdateProjectionMatrix();
  79. void UpdateViewMatrix();
  80. void UpdateFrustum();
  81. Vec3 mPosition;
  82. Vec3 mLookAt;
  83. Vec3 mUp;
  84. Mat4 mView;
  85. Mat4 mProjection;
  86. Frustum mFrustum;
  87. float mFOV;
  88. float mAspect;
  89. float mNear;
  90. float mFar;
  91. bool mActive : 1;
  92. bool mAutoAspect : 1;
  93. };
  94. } // namespace crown