You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.9 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // Lol Engine is free software. It comes without any warranty, to
  7. // the extent permitted by applicable law. You can redistribute it
  8. // and/or modify it under the terms of the Do What the Fuck You Want
  9. // to Public License, Version 2, as published by the WTFPL Task Force.
  10. // See http://www.wtfpl.net/ for more details.
  11. //
  12. #pragma once
  13. //
  14. // The Camera class
  15. // ----------------
  16. //
  17. #include <lol/math/matrix.h>
  18. #include "engine/worldentity.h"
  19. namespace lol
  20. {
  21. class Camera : public WorldEntity
  22. {
  23. public:
  24. Camera();
  25. ~Camera();
  26. std::string GetName() const { return "<camera>"; }
  27. //View functions
  28. void SetView(mat4 const &view);
  29. void SetView(vec3 eye, vec3 target, vec3 up);
  30. void SetView(vec3 pos, vec3 rot);
  31. void SetView(vec3 pos, quat rot);
  32. mat4 GetView() const;
  33. //Projections functions
  34. //private:
  35. void SetProjection(mat4 const &proj);
  36. public:
  37. void SetProjection(float fov, float near, float far);
  38. void SetProjection(float fov, float near, float far, float screen_size, float screen_ratio);
  39. mat4 GetProjection() const;
  40. //Projections manipulation functions
  41. void SetFov(float fov);
  42. void SetScreenInfos(float screen_size);
  43. void SetScreenInfos(float screen_size, float screen_ratio);
  44. void SetDrawInfos(float far);
  45. void SetDrawInfos(float near, float far);
  46. void SetScreenScale(vec2 scale);
  47. void UseShift(bool should_shift);
  48. void UseTarget(bool use_target);
  49. float GetFov() const { return m_fov; }
  50. float GetScreenSize() const { return m_screen_size; }
  51. float GetScreenRatio() const { return m_screen_ratio; }
  52. float GetNear() const { return m_near; }
  53. float GetFar() const { return m_far; }
  54. vec2 GetScreenScale() const { return m_screen_scale; }
  55. bool IsShifted() const { return m_is_shifted; }
  56. bool IsTargeting() const { return (m_target_distance != .0f); }
  57. //camera manipulation Functions
  58. void SetPosition(vec3 pos, bool keep_target=false);
  59. void SetTarget(vec3 target, vec3 up);
  60. void SetRotation(vec3 rot);
  61. void SetRotation(quat rot);
  62. vec3 GetPosition() const;
  63. vec3 GetTarget() const;
  64. vec3 GetUp() const;
  65. vec3 GetRotationEuler() const;
  66. quat GetRotation() const;
  67. //Convenience functions
  68. float GetFrustumHeightAtDistance(float distance, float fov) const;
  69. float GetFOVForHeightAndDistance(float distance, float height) const;
  70. protected:
  71. virtual void TickGame(float seconds);
  72. virtual void TickDraw(float seconds, Scene &scene);
  73. //private:
  74. public:
  75. //Work datas
  76. mat4 m_view_matrix;
  77. mat4 m_proj_matrix;
  78. //Datas used to create above matrix
  79. float m_target_distance;
  80. float m_fov;
  81. float m_screen_size;
  82. float m_screen_ratio;
  83. float m_near;
  84. float m_far;
  85. vec2 m_screen_scale;
  86. bool m_is_shifted;
  87. bool m_fix_up;
  88. };
  89. } /* namespace lol */