Guest User

Untitled

a guest
Sep 2nd, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include <iostream>
  4.  
  5. #include <glm/glm.hpp>
  6. #include <glm/gtc/matrix_transform.hpp>
  7. #include <glm/gtc/type_ptr.hpp>
  8.  
  9. // The FPS Camera that is used for the player's movement, frustum culling
  10.  
  11. namespace Minecraft
  12. {
  13. class FPSCamera
  14. {
  15. public :
  16. FPSCamera(float fov, float aspect, float zNear, float zFar, float sensitivity = 0.25f);
  17. ~FPSCamera();
  18.  
  19. void UpdateOnMouseMovement(double xpos, double ypos);
  20. void SetPosition(const glm::vec3& position);
  21. void ChangePosition(const glm::vec3& position_increment);
  22. void SetFront(const glm::vec3& front);
  23. void SetRotation(float angle);
  24. void SetFov(float fov);
  25. void SetAspect(float aspect);
  26. void SetNearAndFarPlane(float zNear, float zFar);
  27. void SetPerspectiveMatrix(float fov, float aspect_ratio, float zNear, float zFar);
  28.  
  29. inline float GetYaw()
  30. {
  31. return _Yaw;
  32. }
  33.  
  34. inline float GetPitch()
  35. {
  36. return _Pitch;
  37. }
  38.  
  39. inline void SetSensitivity(float sensitivity)
  40. {
  41. _Sensitivity = sensitivity;
  42. }
  43.  
  44. float GetSensitivity() { return _Sensitivity; }
  45.  
  46. inline const glm::vec3& GetPosition()
  47. {
  48. return m_Position;
  49. }
  50.  
  51. inline float GetFov()
  52. {
  53. return m_Fov;
  54. }
  55.  
  56. inline float GetRotation()
  57. {
  58. return m_Rotation;
  59. }
  60.  
  61. inline const glm::mat4& GetViewProjection()
  62. {
  63. return m_ViewProjectionMatrix;
  64. }
  65.  
  66. inline const glm::mat4& GetProjectionMatrix()
  67. {
  68. return m_ProjectionMatrix;
  69. }
  70.  
  71. inline const glm::mat4& GetViewMatrix()
  72. {
  73. return m_ViewMatrix;
  74. }
  75.  
  76. inline const glm::vec3& GetFront()
  77. {
  78. return m_Front;
  79. }
  80.  
  81. inline const glm::vec3& GetUp()
  82. {
  83. return m_Up;
  84. }
  85.  
  86. inline const glm::vec3 GetRight()
  87. {
  88. return glm::normalize(glm::cross(m_Front, m_Up));
  89. }
  90.  
  91. inline float GetAspect()
  92. {
  93. return m_Aspect;
  94. }
  95.  
  96. inline float GetNearPlane()
  97. {
  98. return m_zNear;
  99. }
  100.  
  101. inline float GetFarPlane()
  102. {
  103. return m_zFar;
  104. }
  105.  
  106. inline void ResetAcceleration()
  107. {
  108. m_Acceleration = glm::vec3(0.0f);
  109. }
  110.  
  111. inline void ResetVelocity()
  112. {
  113. m_Velocity = glm::vec3(0.0f);
  114. }
  115.  
  116. inline void ApplyAcceleration(const glm::vec3& acceleration)
  117. {
  118. m_Acceleration = m_Acceleration + acceleration;
  119. }
  120.  
  121. void Refresh()
  122. {
  123. RecalculateProjectionMatrix();
  124. RecalculateViewMatrix();
  125. }
  126.  
  127. void OnUpdate();
  128.  
  129. private :
  130.  
  131. void RecalculateViewMatrix();
  132. void RecalculateProjectionMatrix();
  133.  
  134. float m_Rotation;
  135. float m_Fov;
  136. float m_Aspect;
  137. float m_zNear;
  138. float m_zFar;
  139.  
  140. glm::vec3 m_Position;
  141. glm::vec3 m_Front;
  142. glm::vec3 m_Up;
  143.  
  144. glm::vec3 m_Acceleration;
  145. glm::vec3 m_Velocity;
  146.  
  147. glm::mat4 m_ViewMatrix;
  148. glm::mat4 m_ProjectionMatrix;
  149. glm::mat4 m_ViewProjectionMatrix;
  150.  
  151. // The yaw and pitch of the camera :
  152. bool _FirstMove = false;
  153. float _Sensitivity = 0.2;
  154. float _PrevMx = 0.0f;
  155. float _PrevMy = 0.0f;
  156. float _Yaw = 0.0f;
  157. float _Pitch = 0.0f;
  158. };
  159. }
Advertisement
Add Comment
Please, Sign In to add comment