Camera.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include "Types.h"
  25. #include "Frustum.h"
  26. #include "Mat4.h"
  27. namespace crown
  28. {
  29. struct ProjectionType
  30. {
  31. enum Enum
  32. {
  33. ORTHOGRAPHIC,
  34. PERSPECTIVE
  35. };
  36. };
  37. class Quat;
  38. class Unit;
  39. /// Represents the point of view into the game world.
  40. struct Camera
  41. {
  42. void create(int32_t node, const Vec3& pos, const Quat& rot);
  43. Vec3 local_position() const;
  44. Quat local_rotation() const;
  45. Mat4 local_pose() const;
  46. Vec3 world_position() const;
  47. Quat world_rotation() const;
  48. Mat4 world_pose() const;
  49. void set_local_position(const Vec3& pos);
  50. void set_local_rotation(const Quat& rot);
  51. void set_local_pose(const Mat4& pose);
  52. void set_projection_type(ProjectionType::Enum type);
  53. ProjectionType::Enum projection_type() const;
  54. float fov() const;
  55. void set_fov(float fov);
  56. float aspect() const;
  57. void set_aspect(float aspect);
  58. float near_clip_distance() const;
  59. void set_near_clip_distance(float near);
  60. float far_clip_distance() const;
  61. void set_far_clip_distance(float far);
  62. public:
  63. void update_projection_matrix();
  64. void update_frustum();
  65. public:
  66. int32_t m_node;
  67. Mat4 m_local_pose;
  68. Mat4 m_world_pose;
  69. ProjectionType::Enum m_projection_type;
  70. Mat4 m_projection;
  71. Frustum m_frustum;
  72. float m_FOV;
  73. float m_aspect;
  74. float m_near;
  75. float m_far;
  76. };
  77. } // namespace crown