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. }
  19. const glm::vec3& CCamera::getCenter () const
  20. {
  21. return this->m_camera->getCenter ();
  22. }
  23. const glm::vec3& CCamera::getEye () const
  24. {
  25. return this->m_camera->getEye ();
  26. }
  27. const glm::vec3& CCamera::getUp () const
  28. {
  29. return this->m_camera->getUp ();
  30. }
  31. const glm::mat4& CCamera::getProjection () const
  32. {
  33. return this->m_projection;
  34. }
  35. const glm::mat4& CCamera::getLookAt () const
  36. {
  37. return this->m_lookat;
  38. }
  39. const bool CCamera::isOrthogonal () const
  40. {
  41. return this->m_isOrthogonal;
  42. }
  43. void CCamera::setOrthogonalProjection (float width, float height)
  44. {
  45. // TODO: GET THE ZNEAR AND ZFAR FROM THE BACKGROUND (IF AVAILABLE)
  46. // get the orthogonal projection (the float is there to ensure the values are casted to float, so maths do work)
  47. this->m_projection = glm::ortho <float> (-width / 2.0, width / 2.0, -height / 2.0, height / 2.0, 0, 1000);
  48. this->m_projection = glm::translate (this->m_projection, this->getEye ());
  49. // update the orthogonal flag
  50. this->m_isOrthogonal = true;
  51. }