CCamera.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <glm/glm.hpp>
  2. #include <glm/gtc/matrix_transform.hpp>
  3. #include "CCamera.h"
  4. using namespace WallpaperEngine;
  5. using namespace WallpaperEngine::Render;
  6. using namespace WallpaperEngine::Core::Types;
  7. CCamera::CCamera (CScene* scene, const Core::Scenes::CCamera* camera) :
  8. m_camera (camera),
  9. m_scene (scene),
  10. m_isOrthogonal (false)
  11. {
  12. // get the lookat position
  13. // TODO: ENSURE THIS IS ONLY USED WHEN NOT DOING AN ORTOGRAPHIC CAMERA AS IT THROWS OFF POINTS
  14. this->m_lookat = glm::lookAt (this->getEye (), this->getCenter (), this->getUp ());
  15. }
  16. CCamera::~CCamera ()
  17. {
  18. this->m_sceneCamera->remove ();
  19. }
  20. const glm::vec3& CCamera::getCenter () const
  21. {
  22. return this->m_camera->getCenter ();
  23. }
  24. const glm::vec3& CCamera::getEye () const
  25. {
  26. return this->m_camera->getEye ();
  27. }
  28. const glm::vec3& CCamera::getUp () const
  29. {
  30. return this->m_camera->getUp ();
  31. }
  32. const glm::mat4& CCamera::getProjection () const
  33. {
  34. return this->m_projection;
  35. }
  36. const glm::mat4& CCamera::getLookAt () const
  37. {
  38. return this->m_lookat;
  39. }
  40. const bool CCamera::isOrthogonal () const
  41. {
  42. return this->m_isOrthogonal;
  43. }
  44. void CCamera::setOrthogonalProjection (float width, float height)
  45. {
  46. // TODO: GET THE ZNEAR AND ZFAR FROM THE BACKGROUND (IF AVAILABLE)
  47. // get the orthogonal projection (the float is there to ensure the values are casted to float, so maths do work)
  48. this->m_projection = glm::ortho <float> (0, width, 0, height, 0, 1000);
  49. this->m_projection = glm::translate (this->m_projection, this->getEye ());
  50. // update the orthogonal flag
  51. this->m_isOrthogonal = true;
  52. }