Bladeren bron

First attempt at automatically detect orthographic projection's size

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
Alexis Maiquez 3 jaren geleden
bovenliggende
commit
4d5cdf57b2

+ 1 - 1
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;
 }

+ 1 - 1
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;
 

+ 21 - 1
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 <bool> (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,

+ 7 - 0
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;
     };
 };

+ 21 - 0
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<Core::Objects::CImage> () == false)
+                continue;
+
+            glm::vec2 size = (*cur)->as <Core::Objects::CImage> ()->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 ();