From 5f58178cdce1b815378108356eaadc2bf61963af Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Tue, 1 Oct 2024 04:58:15 +0200 Subject: [PATCH] fix: emitter distance can be a vector --- .../Core/Objects/Particles/CEmitter.cpp | 23 +++++++++++++++---- .../Core/Objects/Particles/CEmitter.h | 10 ++++---- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp index 0714411..35628f7 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp @@ -11,12 +11,27 @@ CEmitter* CEmitter::fromJSON (json data) { const auto origin_it = jsonFindRequired (data, "origin", "Particle emitter must have an origin"); const auto rate_it = jsonFindRequired (data, "rate", "Particle emitter must have a rate"); - return new CEmitter (WallpaperEngine::Core::aToVector3 (*directions_it), *distancemax_it, *distancemin_it, + glm::vec3 distancemin = glm::vec3(0); + glm::vec3 distancemax = glm::vec3(0); + + if (distancemin_it->is_number()) { + distancemin = glm::vec3(static_cast(*distancemin_it)); + } else { + distancemin = WallpaperEngine::Core::aToVector3(*distancemin_it); + } + + if (distancemax_it->is_number()) { + distancemax = glm::vec3(static_cast(*distancemax_it)); + } else { + distancemax = WallpaperEngine::Core::aToVector3(*distancemax_it); + } + + return new CEmitter (WallpaperEngine::Core::aToVector3 (*directions_it), distancemax, distancemin, (id_it == data.end () ? 0 : static_cast (*id_it)), *name_it, WallpaperEngine::Core::aToVector3 (*origin_it), *rate_it); } -CEmitter::CEmitter (const glm::vec3& directions, uint32_t distancemax, uint32_t distancemin, uint32_t id, +CEmitter::CEmitter (const glm::vec3& directions, const glm::vec3& distancemax, const glm::vec3& distancemin, uint32_t id, std::string name, const glm::vec3& origin, double rate) : m_directions (directions), m_distancemax (distancemax), @@ -34,11 +49,11 @@ const std::string& CEmitter::getName () const { return this->m_name; } -const uint32_t CEmitter::getDistanceMax () const { +const glm::vec3& CEmitter::getDistanceMax () const { return this->m_distancemax; } -const uint32_t CEmitter::getDistanceMin () const { +const glm::vec3& CEmitter::getDistanceMin () const { return this->m_distancemin; } diff --git a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h index c34e34b..ef5221e 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h @@ -23,11 +23,11 @@ class CEmitter { /** * @return The maximum distance a particle can travel before being dead */ - [[nodiscard]] const uint32_t getDistanceMax () const; + [[nodiscard]] const glm::vec3& getDistanceMax () const; /** * @return The minimum distance a particle can travel before being dead */ - [[nodiscard]] const uint32_t getDistanceMin () const; + [[nodiscard]] const glm::vec3& getDistanceMin () const; /** * @return The direction a particle should move to */ @@ -42,16 +42,16 @@ class CEmitter { [[nodiscard]] const double getRate () const; protected: - CEmitter (const glm::vec3& directions, uint32_t distancemax, uint32_t distancemin, uint32_t id, std::string name, + CEmitter (const glm::vec3& directions, const glm::vec3& distancemax, const glm::vec3& distancemin, uint32_t id, std::string name, const glm::vec3& origin, double rate); private: /** Direction the particles should move to */ glm::vec3 m_directions; /** Maximum distance before the particle is dead */ - uint32_t m_distancemax; + glm::vec3 m_distancemax; /** Minimum distance before the particle is dead */ - uint32_t m_distancemin; + glm::vec3 m_distancemin; /** ID of the emitter */ uint32_t m_id; /** Name of the emitter, indicates the type of emitter */