First attempt at automatically detect orthographic projection's size

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2022-10-28 09:29:56 +02:00
parent 23585e4a07
commit 4d5cdf57b2
5 changed files with 51 additions and 3 deletions

View File

@ -210,7 +210,7 @@ const FloatColor& CScene::getClearColor () const
return this->m_clearColor; return this->m_clearColor;
} }
const Scenes::CProjection* CScene::getOrthogonalProjection () const Scenes::CProjection* CScene::getOrthogonalProjection () const
{ {
return this->m_orthogonalProjection; return this->m_orthogonalProjection;
} }

View File

@ -38,7 +38,7 @@ namespace WallpaperEngine::Core
const double getCameraShakeRoughness() const; const double getCameraShakeRoughness() const;
const double getCameraShakeSpeed() const; const double getCameraShakeSpeed() const;
const FloatColor& getClearColor() const; const FloatColor& getClearColor() const;
const Scenes::CProjection* getOrthogonalProjection() const; Scenes::CProjection* getOrthogonalProjection() const;
const FloatColor& getSkylightColor() const; const FloatColor& getSkylightColor() const;
const Scenes::CCamera* getCamera () const; const Scenes::CCamera* getCamera () const;

View File

@ -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 const uint32_t& CProjection::getWidth () const
{ {
return this->m_width; return this->m_width;
@ -18,6 +23,21 @@ const uint32_t& CProjection::getHeight () const
return this->m_height; 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) CProjection* CProjection::fromJSON (json data)
{ {
auto auto_it = jsonFindDefault <bool> (data, "auto", false); auto auto_it = jsonFindDefault <bool> (data, "auto", false);
@ -27,7 +47,7 @@ CProjection* CProjection::fromJSON (json data)
// TODO: PROPERLY SUPPORT AUTO-DETECTING SIZE // TODO: PROPERLY SUPPORT AUTO-DETECTING SIZE
if (auto_it == true) if (auto_it == true)
return new CProjection (1920, 1080); return new CProjection (true);
else else
return new CProjection ( return new CProjection (
*width_it, *width_it,

View File

@ -13,10 +13,17 @@ namespace WallpaperEngine::Core::Scenes
const uint32_t& getWidth () const; const uint32_t& getWidth () const;
const uint32_t& getHeight () const; const uint32_t& getHeight () const;
const bool isAuto () const;
void setWidth (uint32_t width);
void setHeight (uint32_t height);
protected: protected:
CProjection (uint32_t width, uint32_t height); CProjection (uint32_t width, uint32_t height);
CProjection (bool isAuto);
private: private:
uint32_t m_width; uint32_t m_width;
uint32_t m_height; uint32_t m_height;
bool m_isAuto;
}; };
}; };

View File

@ -14,10 +14,31 @@ CScene::CScene (Core::CScene* scene, CContainer* container, CContext* context) :
{ {
// setup the scene camera // setup the scene camera
this->m_camera = new CCamera (this, scene->getCamera ()); 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 ( this->m_camera->setOrthogonalProjection (
scene->getOrthogonalProjection ()->getWidth (), scene->getOrthogonalProjection ()->getWidth (),
scene->getOrthogonalProjection ()->getHeight () scene->getOrthogonalProjection ()->getHeight ()
); );
// setup framebuffers // setup framebuffers
this->setupFramebuffers (); this->setupFramebuffers ();