From 4d5cdf57b26bb4bf0a19918273e7084137ce9d05 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Fri, 28 Oct 2022 09:29:56 +0200 Subject: [PATCH] First attempt at automatically detect orthographic projection's size Signed-off-by: Alexis Maiquez --- src/WallpaperEngine/Core/CScene.cpp | 2 +- src/WallpaperEngine/Core/CScene.h | 2 +- .../Core/Scenes/CProjection.cpp | 22 ++++++++++++++++++- src/WallpaperEngine/Core/Scenes/CProjection.h | 7 ++++++ src/WallpaperEngine/Render/CScene.cpp | 21 ++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/WallpaperEngine/Core/CScene.cpp b/src/WallpaperEngine/Core/CScene.cpp index 15cf964..309754f 100644 --- a/src/WallpaperEngine/Core/CScene.cpp +++ b/src/WallpaperEngine/Core/CScene.cpp @@ -210,7 +210,7 @@ const FloatColor& CScene::getClearColor () const return this->m_clearColor; } -const Scenes::CProjection* CScene::getOrthogonalProjection () const +Scenes::CProjection* CScene::getOrthogonalProjection () const { return this->m_orthogonalProjection; } diff --git a/src/WallpaperEngine/Core/CScene.h b/src/WallpaperEngine/Core/CScene.h index 94d9473..3f7c3e8 100644 --- a/src/WallpaperEngine/Core/CScene.h +++ b/src/WallpaperEngine/Core/CScene.h @@ -38,7 +38,7 @@ namespace WallpaperEngine::Core const double getCameraShakeRoughness() const; const double getCameraShakeSpeed() const; const FloatColor& getClearColor() const; - const Scenes::CProjection* getOrthogonalProjection() const; + Scenes::CProjection* getOrthogonalProjection() const; const FloatColor& getSkylightColor() const; const Scenes::CCamera* getCamera () const; diff --git a/src/WallpaperEngine/Core/Scenes/CProjection.cpp b/src/WallpaperEngine/Core/Scenes/CProjection.cpp index 183e4d0..d4b9572 100644 --- a/src/WallpaperEngine/Core/Scenes/CProjection.cpp +++ b/src/WallpaperEngine/Core/Scenes/CProjection.cpp @@ -8,6 +8,11 @@ CProjection::CProjection (uint32_t width, uint32_t height) : { } +CProjection::CProjection (bool isAuto) : + m_isAuto (isAuto) +{ +} + const uint32_t& CProjection::getWidth () const { return this->m_width; @@ -18,6 +23,21 @@ const uint32_t& CProjection::getHeight () const return this->m_height; } +const bool CProjection::isAuto () const +{ + return this->m_isAuto; +} + +void CProjection::setWidth (uint32_t width) +{ + this->m_width = width; +} + +void CProjection::setHeight (uint32_t height) +{ + this->m_height = height; +} + CProjection* CProjection::fromJSON (json data) { auto auto_it = jsonFindDefault (data, "auto", false); @@ -27,7 +47,7 @@ CProjection* CProjection::fromJSON (json data) // TODO: PROPERLY SUPPORT AUTO-DETECTING SIZE if (auto_it == true) - return new CProjection (1920, 1080); + return new CProjection (true); else return new CProjection ( *width_it, diff --git a/src/WallpaperEngine/Core/Scenes/CProjection.h b/src/WallpaperEngine/Core/Scenes/CProjection.h index 4078945..f81e4e4 100644 --- a/src/WallpaperEngine/Core/Scenes/CProjection.h +++ b/src/WallpaperEngine/Core/Scenes/CProjection.h @@ -13,10 +13,17 @@ namespace WallpaperEngine::Core::Scenes const uint32_t& getWidth () const; const uint32_t& getHeight () const; + const bool isAuto () const; + + void setWidth (uint32_t width); + void setHeight (uint32_t height); + protected: CProjection (uint32_t width, uint32_t height); + CProjection (bool isAuto); private: uint32_t m_width; uint32_t m_height; + bool m_isAuto; }; }; diff --git a/src/WallpaperEngine/Render/CScene.cpp b/src/WallpaperEngine/Render/CScene.cpp index 8e42f47..1d8ceee 100644 --- a/src/WallpaperEngine/Render/CScene.cpp +++ b/src/WallpaperEngine/Render/CScene.cpp @@ -14,10 +14,31 @@ CScene::CScene (Core::CScene* scene, CContainer* container, CContext* context) : { // setup the scene camera this->m_camera = new CCamera (this, scene->getCamera ()); + + // detect size if the orthogonal project is auto + if (scene->getOrthogonalProjection ()->isAuto () == true) + { + // calculate the size of the projection based on the size of everything + auto cur = scene->getObjects ().begin (); + auto end = scene->getObjects ().end (); + + for (; cur != end; cur ++) + { + if ((*cur)->is () == false) + continue; + + glm::vec2 size = (*cur)->as ()->getSize (); + + scene->getOrthogonalProjection ()->setWidth (size.x); + scene->getOrthogonalProjection ()->setHeight (size.y); + } + } + this->m_camera->setOrthogonalProjection ( scene->getOrthogonalProjection ()->getWidth (), scene->getOrthogonalProjection ()->getHeight () ); + // setup framebuffers this->setupFramebuffers ();