From af846053c849e055815534120c872b73cd78f814 Mon Sep 17 00:00:00 2001 From: ambidot Date: Sun, 26 Jul 2020 18:01:36 -0500 Subject: [PATCH] Fixed positioning of miscellaneous foreground objects. --- wallpaperengine/image.cpp | 10 ++++---- wallpaperengine/irr/CImageLoaderTEX.cpp | 8 +++---- wallpaperengine/scene.cpp | 31 ++++++++++++++++--------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/wallpaperengine/image.cpp b/wallpaperengine/image.cpp index 18bd745..16d7687 100644 --- a/wallpaperengine/image.cpp +++ b/wallpaperengine/image.cpp @@ -79,10 +79,12 @@ namespace wp irr::f32 xscale = this->m_parent->getScale ().X; irr::f32 yscale = this->m_parent->getScale ().Y; - irr::f32 xright = this->m_parent->getOrigin ().X; - irr::f32 xleft = this->m_parent->getOrigin ().X - xsize * xscale; - irr::f32 ytop = this->m_parent->getOrigin ().Y; - irr::f32 ybottom = this->m_parent->getOrigin ().Y - ysize * yscale; + float scene_w = this->m_parent->getScene ()->getProjectionWidth (); + float scene_h = this->m_parent->getScene ()->getProjectionHeight (); + irr::f32 xright = -scene_w/2. + this->m_parent->getOrigin ().X + xsize*xscale/2.; + irr::f32 xleft = -scene_w/2. + this->m_parent->getOrigin ().X - xsize*xscale/2.; + irr::f32 ytop = -scene_h/2. + this->m_parent->getOrigin ().Y + ysize*yscale/2.; + irr::f32 ybottom = -scene_h/2. + this->m_parent->getOrigin ().Y - ysize*yscale/2.; irr::f32 z = this->m_parent->getScene ()->getCamera ()->getEye ().Z; m_vertices [0].Pos = irr::core::vector3df (xleft, ytop, z); // top left diff --git a/wallpaperengine/irr/CImageLoaderTEX.cpp b/wallpaperengine/irr/CImageLoaderTEX.cpp index f444602..4c4cdb6 100644 --- a/wallpaperengine/irr/CImageLoaderTEX.cpp +++ b/wallpaperengine/irr/CImageLoaderTEX.cpp @@ -76,9 +76,7 @@ namespace irr { input->seek (4, true); // ignore bytes input->read (buffer, 9); - if (input->getFileName().find("materials/flowmask.tex") != std::string::npos || - input->getFileName().find("godrays_downsample2_mask") != std::string::npos || - input->getFileName().find("materials/util/white.tex") != std::string::npos) + if (input->getFileName().find("materials/util/white.tex") != std::string::npos) { // relevant shaders are currently drawing these masks opaque; return a transparent image instead wp::irrlicht::device->getLogger ()->log ("LOAD TEX: Skipping broken mask", input->getFileName ().c_str (), irr::ELL_INFORMATION); @@ -274,7 +272,7 @@ namespace irr { delete [] decompressedBuffer; #if 0 - // dump image to a TGA file (adapted from maluoi's gist) + // dump image to TGA file (adapted from maluoi's gist) u32 bytesPerPixel = image->getBytesPerPixel (); if (bytesPerPixel != 3 && bytesPerPixel != 4) wp::irrlicht::device->getLogger ()->log (("Unexpected bytesPerPixel of " + std::to_string (bytesPerPixel)).c_str (), input->getFileName ().c_str (), irr::ELL_ERROR); @@ -283,7 +281,7 @@ namespace irr { std::string fileName = input->getFileName ().c_str (); std::replace (fileName.begin (), fileName.end (), '/', '-'); std::string path = std::string (getenv("HOME")) + "/stuff/wallpaperengine-dumps/"; - system(("mkdir -p " + path).c_str()); + system (("mkdir -p " + path).c_str ()); path += fileName + ".tga"; FILE *dumpFile = fopen (path.c_str (), "wb"); uint8_t header[18] = { 0,0,2,0,0,0,0,0,0,0,0,0, diff --git a/wallpaperengine/scene.cpp b/wallpaperengine/scene.cpp index 5a3dbfb..94a0fcc 100644 --- a/wallpaperengine/scene.cpp +++ b/wallpaperengine/scene.cpp @@ -16,6 +16,14 @@ namespace wp { this->m_content = wp::fs::utils::loadFullFile (file); this->m_json = json::parse (this->m_content); +#if 0 + // dump scene json to file + std::string path = std::string (getenv("HOME")) + "/stuff/wallpaperengine-dumps/"; + system (("mkdir -p " + path).c_str ()); + path += file.c_str (); + std::ofstream out = std::ofstream (path); + out << this->m_json.dump (4) << std::endl; +#endif // check basic elements json::const_iterator camera_it = this->m_json.find ("camera"); @@ -27,17 +35,7 @@ namespace wp this->m_camera = new camera (*camera_it); } - if (objects_it != this->m_json.end () && objects_it.value ().is_array () == true) - { - json::const_iterator cur = this->m_json ["objects"].begin (); - json::const_iterator end = this->m_json ["objects"].end (); - - for (; cur != end; cur ++) - { - this->m_objects.push_back (new object (*cur, this)); - } - } - + // read orthogonalprojection before loading objects so they can set their vertices properly json::const_iterator orthogonalprojection = (*general_it).find ("orthogonalprojection"); if (orthogonalprojection != (*general_it).end () && (*orthogonalprojection).is_object () == true) @@ -57,6 +55,17 @@ namespace wp this->m_isOrthogonal = true; } + + if (objects_it != this->m_json.end () && objects_it.value ().is_array () == true) + { + json::const_iterator cur = this->m_json ["objects"].begin (); + json::const_iterator end = this->m_json ["objects"].end (); + + for (; cur != end; cur ++) + { + this->m_objects.push_back (new object (*cur, this)); + } + } } scene::~scene ()