Camera.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #include "Mat3.h"
  28. #include "Vec3.h"
  29. namespace crown
  30. {
  31. struct ProjectionType
  32. {
  33. enum Enum
  34. {
  35. ORTHOGRAPHIC,
  36. PERSPECTIVE
  37. };
  38. };
  39. class Quat;
  40. class Unit;
  41. /// Represents the point of view into the game world.
  42. struct Camera
  43. {
  44. void create(Unit& parent, int32_t node);
  45. Vec3 local_position() const;
  46. Quat local_rotation() const;
  47. Mat4 local_pose() const;
  48. Vec3 world_position() const;
  49. Quat world_rotation() const;
  50. Mat4 world_pose() const;
  51. void set_local_position(const Vec3& pos);
  52. void set_local_rotation(const Quat& rot);
  53. void set_local_pose(const Mat4& pose);
  54. void set_projection_type(ProjectionType::Enum type);
  55. ProjectionType::Enum projection_type() const;
  56. float fov() const;
  57. void set_fov(float fov);
  58. float aspect() const;
  59. void set_aspect(float aspect);
  60. float near_clip_distance() const;
  61. void set_near_clip_distance(float near);
  62. float far_clip_distance() const;
  63. void set_far_clip_distance(float far);
  64. public:
  65. void update_projection_matrix();
  66. void update_frustum();
  67. public:
  68. Unit* m_parent;
  69. int32_t m_node;
  70. ProjectionType::Enum m_projection_type;
  71. Mat4 m_projection;
  72. Frustum m_frustum;
  73. float m_FOV;
  74. float m_aspect;
  75. float m_near;
  76. float m_far;
  77. };
  78. } // namespace crown