Skip to content

Commit

Permalink
fix: emitter distance can be a vector
Browse files Browse the repository at this point in the history
  • Loading branch information
Almamu committed Oct 1, 2024
1 parent 7c6bebc commit 5f58178
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
23 changes: 19 additions & 4 deletions src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(*distancemin_it));
} else {
distancemin = WallpaperEngine::Core::aToVector3(*distancemin_it);
}

if (distancemax_it->is_number()) {
distancemax = glm::vec3(static_cast<uint32_t>(*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<uint32_t> (*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),
Expand All @@ -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;
}

Expand Down
10 changes: 5 additions & 5 deletions src/WallpaperEngine/Core/Objects/Particles/CEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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 */
Expand Down

0 comments on commit 5f58178

Please sign in to comment.