2
0

camera.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #define GLM_ENABLE_EXPERIMENTAL
  3. #include <glm/glm.hpp>
  4. #include <glm/gtc/matrix_transform.hpp>
  5. #include <glm/gtc/type_ptr.hpp>
  6. #include <glm/mat3x3.hpp>
  7. #include <glm/gtx/transform.hpp>
  8. struct Camera
  9. {
  10. Camera() = default;
  11. Camera(float aspectRatio, float fovRadians)
  12. :aspectRatio(aspectRatio),
  13. fovRadians(fovRadians)
  14. {
  15. }
  16. glm::vec3 up = {0.f,1.f,0.f};
  17. float aspectRatio = 1;
  18. float fovRadians = glm::radians(60.f);
  19. float closePlane = 0.01f;
  20. float farPlane = 400.f;
  21. glm::dvec3 position = {};
  22. glm::vec3 viewDirection = {0,0,-1};
  23. glm::mat4x4 getProjectionMatrix();
  24. glm::mat4x4 getViewMatrix();
  25. void rotateCamera(const glm::vec2 delta);
  26. float yaw = 0.f;
  27. float pitch = 0.f;
  28. void moveFPS(glm::vec3 direction);
  29. void rotateFPS(glm::ivec2 mousePos, float speed, bool shouldMove);
  30. glm::ivec2 lastMousePos = {};
  31. bool operator==(const Camera& other)
  32. {
  33. return
  34. (up == other.up)
  35. && (aspectRatio == other.aspectRatio)
  36. && (fovRadians == other.fovRadians)
  37. && (closePlane == other.closePlane)
  38. && (farPlane == other.farPlane)
  39. && (position == other.position)
  40. && (viewDirection == other.viewDirection)
  41. ;
  42. };
  43. bool operator!=(const Camera& other)
  44. {
  45. return !(*this == other);
  46. };
  47. void decomposePosition(glm::vec3 &floatPart, glm::ivec3 &intPart);
  48. void decomposePosition(glm::vec3 &floatPart, glm::dvec3 in, glm::ivec3 &intPart);
  49. };
  50. void decomposePosition(glm::dvec3 in, glm::vec3 &floatPart, glm::ivec3 &intPart);
  51. glm::ivec3 from3DPointToBlock(glm::dvec3 in);