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

camera.cpp 1.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "svl/util/camera.h"
  2. #include "glm/gtc/matrix_transform.hpp"
  3. namespace svl {
  4. namespace util {
  5. Camera::Camera(const glm::vec2 &viewport, CameraProjectionMode mode)
  6. {
  7. mViewport = viewport;
  8. mFieldOfView = 45.0f;
  9. mNearPlane = 0.01f;
  10. mFarPlane = 100.0f;
  11. mProjectionMode = mode;
  12. }
  13. Camera::~Camera()
  14. {
  15. }
  16. void Camera::updateProjectMatrix()
  17. {
  18. if (mProjectionMode == CameraProjectionMode::Perspective)
  19. {
  20. mProjectMatrix = glm::perspective(glm::radians(mFieldOfView), mViewport.x * 1.0f / mViewport.y, mNearPlane, mFarPlane);
  21. }
  22. else
  23. {
  24. mProjectMatrix = glm::ortho(-mViewport.x / 2.0f, mViewport.x / 2.0f, -mViewport.y / 2.0f, mViewport.y / 2.0f, mNearPlane, mFarPlane);
  25. }
  26. }
  27. glm::mat4 Camera::orientation() const
  28. {
  29. glm::mat4 orientation;
  30. orientation = glm::rotate(orientation, glm::radians(mVerticalAngle), glm::vec3(1, 0, 0));
  31. orientation = glm::rotate(orientation, glm::radians(mHorizontalAngle), glm::vec3(0, 1, 0));
  32. return orientation;
  33. }
  34. void Camera::lookAt(const glm::vec3 &at)
  35. {
  36. assert(mPosition != at);
  37. //position =
  38. }
  39. void Camera::move(const glm::vec3 &offset)
  40. {
  41. mPosition += offset;
  42. }
  43. void Camera::moveTo(const glm::vec3 &pos)
  44. {
  45. if (mPosition != pos)
  46. {
  47. mPosition = pos;
  48. }
  49. }
  50. const glm::mat4 &Camera::projectionMatrix()
  51. {
  52. return mProjectMatrix;
  53. }
  54. const glm::mat4 &Camera::viewMatrix()
  55. {
  56. return mViewMatrix;
  57. }
  58. } // namespace util
  59. } // namespace svl