Camera.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include "WallpaperEngine/Render/Wallpapers/CScene.h"
  3. #include <glm/mat4x4.hpp>
  4. #include <glm/vec2.hpp>
  5. #include <glm/vec3.hpp>
  6. #include "WallpaperEngine/Data/Model/Wallpaper.h"
  7. namespace WallpaperEngine::Render::Wallpapers {
  8. class CScene;
  9. }
  10. namespace WallpaperEngine::Render {
  11. using namespace WallpaperEngine::Data::Model;
  12. class Camera {
  13. public:
  14. Camera (Wallpapers::CScene& scene, const SceneData::Camera& camera);
  15. ~Camera ();
  16. // width/height is the layout objects are positioned in, canvas the rendered size centered on it (0 = layout size)
  17. void setOrthogonalProjection (float width, float height, float canvasWidth = 0.0f, float canvasHeight = 0.0f);
  18. // 3D scenes: the scene camera becomes perspective, getProjection/getLookAt stay screen space for 2D layers
  19. void setPerspectiveProjection (float width, float height);
  20. [[nodiscard]] const glm::vec3& getCenter () const;
  21. [[nodiscard]] const glm::vec3& getEye () const;
  22. [[nodiscard]] const glm::vec3& getConfiguredEye () const;
  23. [[nodiscard]] const glm::vec3& getUp () const;
  24. [[nodiscard]] const glm::mat4& getProjection () const;
  25. [[nodiscard]] const glm::mat4& getLookAt () const;
  26. [[nodiscard]] const glm::mat4& getFullscreenProjection () const;
  27. [[nodiscard]] Wallpapers::CScene& getScene () const;
  28. [[nodiscard]] bool isOrthogonal () const;
  29. [[nodiscard]] bool isPerspective () const;
  30. [[nodiscard]] const glm::mat4& getPerspective () const;
  31. [[nodiscard]] const glm::mat4& getView () const;
  32. [[nodiscard]] float getWidth () const;
  33. [[nodiscard]] float getHeight () const;
  34. [[nodiscard]] float getCanvasWidth () const;
  35. [[nodiscard]] float getCanvasHeight () const;
  36. [[nodiscard]] float getFov () const;
  37. [[nodiscard]] float getNearZ () const;
  38. [[nodiscard]] float getFarZ () const;
  39. // per frame view from a camera object in WE's world space (y up, origin bottom left); identity without one in 2D
  40. void setWorldView (const glm::mat4& view);
  41. /** 2D scenes: general zoom times the camera object's zoom, scales around the scene center (sub_14017FA70) */
  42. void setZoom (float zoom);
  43. void setPerspectiveView (const glm::mat4& view, float fov);
  44. [[nodiscard]] const glm::mat4& getWorldView () const;
  45. [[nodiscard]] float getViewFov () const;
  46. // the canvas part the output shows as margins (left, right, bottom, top, y up, negative for letterboxing) and its
  47. // aspect; 2D scenes project it onto the scene buffer (sub_140183A70), 3D ones use the aspect; also rebuilds
  48. // "perspective" layers (sub_1401E5B60)
  49. void setVisibleRegion (const glm::vec4& margins, float outputAspect);
  50. void updatePerspectiveLayers ();
  51. /** View projection of "perspective" layers, same space as getProjection () * getLookAt () in 2D scenes, WE's world
  52. * in 3D ones */
  53. [[nodiscard]] const glm::mat4& getPerspectiveLayerViewProjection () const;
  54. private:
  55. float m_width;
  56. float m_height;
  57. glm::vec3 m_eye;
  58. float m_canvasWidth = 0.0f;
  59. float m_canvasHeight = 0.0f;
  60. bool m_isOrthogonal = false;
  61. bool m_isPerspective = false;
  62. glm::mat4 m_perspective = {};
  63. glm::mat4 m_view = {};
  64. glm::mat4 m_projection = {};
  65. glm::mat4 m_lookat = {};
  66. glm::mat4 m_worldView = glm::mat4 (1.0f);
  67. glm::mat4 m_orthogonal = {};
  68. glm::mat4 m_fullscreen = {};
  69. glm::vec4 m_margins = {};
  70. float m_outputAspect = 0.0f;
  71. float m_zoom = 1.0f;
  72. float m_viewFov = 0.0f;
  73. glm::mat4 m_perspectiveLayer = {};
  74. const SceneData::Camera& m_camera;
  75. Wallpapers::CScene& m_scene;
  76. };
  77. }