From 0a4595fdaef533c541471c078e9ae57982518f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9au?= <theau.baton@etu.univ-amu.fr> Date: Sat, 25 May 2024 19:06:26 +0200 Subject: [PATCH] Refactoring Generator and Particle namesapce --- ParticleGenerator/res/config/imgui.ini | 13 +++++++------ .../src/Interface/Generator/PathGenerator.cpp | 4 ++-- .../src/Interface/Generator/PathGenerator.hpp | 8 ++++---- .../Interface/Generator/PhysicGenerator.cpp | 4 ++-- .../Interface/Generator/PhysicGenerator.hpp | 8 ++++---- .../src/Interface/Scene/Path.cpp | 2 +- .../src/Interface/Scene/Path.hpp | 2 +- .../src/Interface/Scene/Physic.cpp | 2 +- .../src/Interface/Scene/Physic.hpp | 4 ++-- ParticleGenerator/src/Particle/Particle.cpp | 2 +- ParticleGenerator/src/Particle/Particle.hpp | 2 +- .../Particle/{PathParticle.cpp => Path.cpp} | 12 ++++++------ .../Particle/{PathParticle.hpp => Path.hpp} | 8 ++++---- ParticleGenerator/src/Particle/Physics.cpp | 16 ++++++++++++++++ .../{PhysicsParticle.hpp => Physics.hpp} | 8 ++++---- .../src/Particle/PhysicsParticle.cpp | 17 ----------------- .../{ParticleGenerator.hpp => Generator.hpp} | 13 +++++++------ ...articleGenerator.cpp => PathGenerator.cpp} | 16 ++++++++-------- ...articleGenerator.hpp => PathGenerator.hpp} | 19 +++++++++---------- ...icleGenerator.cpp => PhysicsGenerator.cpp} | 16 ++++++++-------- ...icleGenerator.hpp => PhysicsGenerator.hpp} | 12 ++++++------ ParticleGenerator/src/Scene/Scene.hpp | 2 +- .../src/Scene/Scenes/MeshGenerator.cpp | 6 +++--- .../src/Scene/Scenes/MeshGenerator.hpp | 4 ++-- ParticleGenerator/src/Scene/Scenes/Path.cpp | 4 ++-- ParticleGenerator/src/Scene/Scenes/Path.hpp | 6 +++--- ParticleGenerator/src/Scene/Scenes/Physic.cpp | 4 ++-- ParticleGenerator/src/Scene/Scenes/Physic.hpp | 6 +++--- .../src/Scene/Scenes/PhysicSprite.cpp | 4 ++-- .../src/Scene/Scenes/PhysicSprite.hpp | 6 +++--- .../src/Scene/Scenes/Trajectory.cpp | 2 +- .../src/Scene/Scenes/Trajectory.hpp | 8 ++++---- 32 files changed, 120 insertions(+), 120 deletions(-) rename ParticleGenerator/src/Particle/{PathParticle.cpp => Path.cpp} (59%) rename ParticleGenerator/src/Particle/{PathParticle.hpp => Path.hpp} (77%) create mode 100644 ParticleGenerator/src/Particle/Physics.cpp rename ParticleGenerator/src/Particle/{PhysicsParticle.hpp => Physics.hpp} (70%) delete mode 100644 ParticleGenerator/src/Particle/PhysicsParticle.cpp rename ParticleGenerator/src/Particle/generator/{ParticleGenerator.hpp => Generator.hpp} (66%) rename ParticleGenerator/src/Particle/generator/{PathParticleGenerator.cpp => PathGenerator.cpp} (67%) rename ParticleGenerator/src/Particle/generator/{PathParticleGenerator.hpp => PathGenerator.hpp} (69%) rename ParticleGenerator/src/Particle/generator/{PhysicsParticleGenerator.cpp => PhysicsGenerator.cpp} (83%) rename ParticleGenerator/src/Particle/generator/{PhysicsParticleGenerator.hpp => PhysicsGenerator.hpp} (80%) diff --git a/ParticleGenerator/res/config/imgui.ini b/ParticleGenerator/res/config/imgui.ini index 36effb4..2debb9c 100644 --- a/ParticleGenerator/res/config/imgui.ini +++ b/ParticleGenerator/res/config/imgui.ini @@ -2,11 +2,12 @@ Pos=60,60 Size=400,400 -[Window][Dear ImGui Demo] -Pos=891,315 -Size=550,680 - [Window][Particle Generator] -Pos=60,60 -Size=263,184 +Pos=86,73 +Size=848,814 + +[Window][Dear ImGui Demo] +Pos=984,78 +Size=598,693 +Collapsed=1 diff --git a/ParticleGenerator/src/Interface/Generator/PathGenerator.cpp b/ParticleGenerator/src/Interface/Generator/PathGenerator.cpp index 1889154..887f7a0 100644 --- a/ParticleGenerator/src/Interface/Generator/PathGenerator.cpp +++ b/ParticleGenerator/src/Interface/Generator/PathGenerator.cpp @@ -4,10 +4,10 @@ #include <imgui.h> -#include "../../Particle/generator/PathParticleGenerator.hpp" +#include "../../Particle/generator/PathGenerator.hpp" namespace pg::interface { - PathGenerator::PathGenerator(PathParticleGenerator * parent, scene::Trajectory * trajectory) + PathGenerator::PathGenerator(particle::PathGenerator * parent, scene::Trajectory * trajectory) : Generator(parent), _trajectory(trajectory), _next(0.f, 0.f, 0.f), diff --git a/ParticleGenerator/src/Interface/Generator/PathGenerator.hpp b/ParticleGenerator/src/Interface/Generator/PathGenerator.hpp index d1f480f..01c6f58 100644 --- a/ParticleGenerator/src/Interface/Generator/PathGenerator.hpp +++ b/ParticleGenerator/src/Interface/Generator/PathGenerator.hpp @@ -5,12 +5,12 @@ #include <glm/vec3.hpp> -namespace pg { - class PathParticleGenerator; +namespace pg::particle { + class PathGenerator; } namespace pg::interface { - class PathGenerator : public Generator<pg::PathParticleGenerator> { + class PathGenerator : public Generator<particle::PathGenerator> { private: scene::Trajectory * _trajectory; @@ -18,7 +18,7 @@ namespace pg::interface { int _index; public: - PathGenerator(PathParticleGenerator *, scene::Trajectory * = nullptr); + PathGenerator(particle::PathGenerator *, scene::Trajectory * = nullptr); virtual ~PathGenerator() = default; void draw(double) override; diff --git a/ParticleGenerator/src/Interface/Generator/PhysicGenerator.cpp b/ParticleGenerator/src/Interface/Generator/PhysicGenerator.cpp index cf3cdb0..3f704e5 100644 --- a/ParticleGenerator/src/Interface/Generator/PhysicGenerator.cpp +++ b/ParticleGenerator/src/Interface/Generator/PhysicGenerator.cpp @@ -4,10 +4,10 @@ #include <imgui.h> -#include "../../Particle/generator/PhysicsParticleGenerator.hpp" +#include "../../Particle/generator/PhysicsGenerator.hpp" namespace pg::interface { - PhysicGenerator::PhysicGenerator(pg::PhysicsParticleGenerator * parent) + PhysicGenerator::PhysicGenerator(particle::PhysicsGenerator * parent) : Generator(parent) {} void PhysicGenerator::draw(double) { diff --git a/ParticleGenerator/src/Interface/Generator/PhysicGenerator.hpp b/ParticleGenerator/src/Interface/Generator/PhysicGenerator.hpp index 4ec8151..1c1204b 100644 --- a/ParticleGenerator/src/Interface/Generator/PhysicGenerator.hpp +++ b/ParticleGenerator/src/Interface/Generator/PhysicGenerator.hpp @@ -2,14 +2,14 @@ #include "../Interface.hpp" -namespace pg { - class PhysicsParticleGenerator; +namespace pg::particle { + class PhysicsGenerator; } namespace pg::interface { - class PhysicGenerator : public Generator<pg::PhysicsParticleGenerator> { + class PhysicGenerator : public Generator<particle::PhysicsGenerator> { public: - PhysicGenerator(pg::PhysicsParticleGenerator *); + PhysicGenerator(particle::PhysicsGenerator *); virtual void draw(double = 0.0); inline std::string title() const {return "Physic Generator Interface";} diff --git a/ParticleGenerator/src/Interface/Scene/Path.cpp b/ParticleGenerator/src/Interface/Scene/Path.cpp index 93678aa..e698158 100644 --- a/ParticleGenerator/src/Interface/Scene/Path.cpp +++ b/ParticleGenerator/src/Interface/Scene/Path.cpp @@ -6,7 +6,7 @@ #include "../../tfd/tinyfiledialogs.h" namespace pg::interface { - Path::Path(scene::Path * parent, pg::PathParticleGenerator * generator, pg::scene::Trajectory * trajectory) + Path::Path(scene::Path * parent, particle::PathGenerator * generator, scene::Trajectory * trajectory) : Scene(parent), SceneParticle(parent), _interface(generator, trajectory) {} void Path::draw(double current_time) { diff --git a/ParticleGenerator/src/Interface/Scene/Path.hpp b/ParticleGenerator/src/Interface/Scene/Path.hpp index edd8976..6359ed4 100644 --- a/ParticleGenerator/src/Interface/Scene/Path.hpp +++ b/ParticleGenerator/src/Interface/Scene/Path.hpp @@ -18,7 +18,7 @@ namespace pg::interface { PathGenerator _interface; public: - Path(scene::Path *, pg::PathParticleGenerator *, pg::scene::Trajectory * = nullptr); + Path(scene::Path *, particle::PathGenerator *, pg::scene::Trajectory * = nullptr); virtual ~Path() = default; virtual void draw(double); diff --git a/ParticleGenerator/src/Interface/Scene/Physic.cpp b/ParticleGenerator/src/Interface/Scene/Physic.cpp index 4981e66..8f5e975 100644 --- a/ParticleGenerator/src/Interface/Scene/Physic.cpp +++ b/ParticleGenerator/src/Interface/Scene/Physic.cpp @@ -8,7 +8,7 @@ #include <iostream> namespace pg::interface { - Physic::Physic(scene::Physic * parent, pg::PhysicsParticleGenerator * generator) + Physic::Physic(scene::Physic * parent, particle::PhysicsGenerator * generator) : Scene(parent), SceneParticle(parent), _interface(generator) {} void Physic::draw(double current_time) { diff --git a/ParticleGenerator/src/Interface/Scene/Physic.hpp b/ParticleGenerator/src/Interface/Scene/Physic.hpp index 9db411c..cbb7f65 100644 --- a/ParticleGenerator/src/Interface/Scene/Physic.hpp +++ b/ParticleGenerator/src/Interface/Scene/Physic.hpp @@ -3,7 +3,7 @@ #include "../Interface.hpp" #include "SceneParticle.hpp" #include "../Generator/PhysicGenerator.hpp" -#include "../../Particle/generator/PhysicsParticleGenerator.hpp" +#include "../../Particle/generator/PhysicsGenerator.hpp" #include <glm/vec4.hpp> @@ -17,7 +17,7 @@ namespace pg::interface { PhysicGenerator _interface; public: - Physic(scene::Physic *, pg::PhysicsParticleGenerator *); + Physic(scene::Physic *, particle::PhysicsGenerator *); virtual ~Physic() = default; virtual void draw(double); diff --git a/ParticleGenerator/src/Particle/Particle.cpp b/ParticleGenerator/src/Particle/Particle.cpp index bd2ba6e..344eb48 100644 --- a/ParticleGenerator/src/Particle/Particle.cpp +++ b/ParticleGenerator/src/Particle/Particle.cpp @@ -2,7 +2,7 @@ #include <chrono> -namespace pg { +namespace pg::particle { Particle::Particle(const ct::Point& position) : Particle(0, position) {} diff --git a/ParticleGenerator/src/Particle/Particle.hpp b/ParticleGenerator/src/Particle/Particle.hpp index 1f6097e..0d0ef55 100644 --- a/ParticleGenerator/src/Particle/Particle.hpp +++ b/ParticleGenerator/src/Particle/Particle.hpp @@ -5,7 +5,7 @@ #include <CurveTools/CPU/CurveGenerator.hpp> -namespace pg +namespace pg::particle { class Particle { diff --git a/ParticleGenerator/src/Particle/PathParticle.cpp b/ParticleGenerator/src/Particle/Path.cpp similarity index 59% rename from ParticleGenerator/src/Particle/PathParticle.cpp rename to ParticleGenerator/src/Particle/Path.cpp index cc6682e..35b714c 100644 --- a/ParticleGenerator/src/Particle/PathParticle.cpp +++ b/ParticleGenerator/src/Particle/Path.cpp @@ -1,9 +1,9 @@ -#include "PathParticle.hpp" +#include "Path.hpp" #include <iostream> -namespace pg { - PathParticle::PathParticle(ct::CurveGenerator* generator, const ct::Curve& path, double u, double inc) +namespace pg::particle { + Path::Path(ct::CurveGenerator* generator, const ct::Curve& path, double u, double inc) : Particle(), m_generator(generator), m_ctrlPoints(path), m_positionVariation(), m_u(u), m_increment(inc), m_limitor(0.0) { if(!path.empty()) { @@ -11,13 +11,13 @@ namespace pg { } } - PathParticle::PathParticle(size_t birth, ct::CurveGenerator* generator, const ct::Curve& controlPoints, double u, double inc) - : PathParticle(generator, controlPoints, u, inc) + Path::Path(size_t birth, ct::CurveGenerator* generator, const ct::Curve& controlPoints, double u, double inc) + : Path(generator, controlPoints, u, inc) { this->setBorn(birth); } - void PathParticle::update(double delta) + void Path::update(double delta) { this->m_u += this->m_increment; diff --git a/ParticleGenerator/src/Particle/PathParticle.hpp b/ParticleGenerator/src/Particle/Path.hpp similarity index 77% rename from ParticleGenerator/src/Particle/PathParticle.hpp rename to ParticleGenerator/src/Particle/Path.hpp index f149275..5803191 100644 --- a/ParticleGenerator/src/Particle/PathParticle.hpp +++ b/ParticleGenerator/src/Particle/Path.hpp @@ -3,8 +3,8 @@ #include "Particle.hpp" #include <CurveTools/CPU/CurveGenerator.hpp> -namespace pg { - class PathParticle : public Particle +namespace pg::particle { + class Path : public Particle { private: ct::CurveGenerator* m_generator; @@ -13,8 +13,8 @@ namespace pg { double m_u, m_increment, m_limitor; public: - PathParticle(size_t birth, ct::CurveGenerator* generator, const ct::Curve& controlPoints, double u = 0.0, double inc = 0.0); - PathParticle(ct::CurveGenerator* generator, const ct::Curve& path, double u = 0.0, double inc = 0.0); + Path(size_t birth, ct::CurveGenerator* generator, const ct::Curve& controlPoints, double u = 0.0, double inc = 0.0); + Path(ct::CurveGenerator* generator, const ct::Curve& path, double u = 0.0, double inc = 0.0); inline const ct::Curve & getControlPoints() const {return this->m_ctrlPoints;} inline glm::dvec3 getPositionVariation() const {return m_positionVariation;} diff --git a/ParticleGenerator/src/Particle/Physics.cpp b/ParticleGenerator/src/Particle/Physics.cpp new file mode 100644 index 0000000..f2fff0f --- /dev/null +++ b/ParticleGenerator/src/Particle/Physics.cpp @@ -0,0 +1,16 @@ +#include "Physics.hpp" + +namespace pg::particle { + Physics::Physics(size_t birth, const ct::Point& position, const glm::dvec3& velocity) + : Particle(birth, position), m_velocity(velocity), m_acceleration(ct::Point()), m_friction(ct::Point()) {} + + Physics::Physics(const ct::Point& position, const glm::dvec3& velocity) + : Physics(0, position, velocity) {} + + void Physics::update(double t) { + m_acceleration -= static_cast<glm::dvec3>(m_friction) * m_velocity; + m_velocity += m_acceleration; + + this->translate(this->m_velocity); + } +} \ No newline at end of file diff --git a/ParticleGenerator/src/Particle/PhysicsParticle.hpp b/ParticleGenerator/src/Particle/Physics.hpp similarity index 70% rename from ParticleGenerator/src/Particle/PhysicsParticle.hpp rename to ParticleGenerator/src/Particle/Physics.hpp index 2942097..b56a4c7 100644 --- a/ParticleGenerator/src/Particle/PhysicsParticle.hpp +++ b/ParticleGenerator/src/Particle/Physics.hpp @@ -2,8 +2,8 @@ #include "Particle.hpp" -namespace pg { - class PhysicsParticle : public Particle +namespace pg::particle { + class Physics : public Particle { private: glm::dvec3 m_velocity; @@ -11,8 +11,8 @@ namespace pg { glm::dvec3 m_friction; public: - PhysicsParticle(size_t birth, const ct::Point& position = ct::Point(), const glm::dvec3& velocity = ct::Point()); - PhysicsParticle(const ct::Point& position = ct::Point(), const glm::dvec3& velocity = ct::Point()); + Physics(size_t birth, const ct::Point& position = ct::Point(), const glm::dvec3& velocity = ct::Point()); + Physics(const ct::Point& position = ct::Point(), const glm::dvec3& velocity = ct::Point()); inline glm::dvec3 getVelocity() const {return this->m_velocity;} inline glm::dvec3 getAcceleration() const {return this->m_acceleration;} diff --git a/ParticleGenerator/src/Particle/PhysicsParticle.cpp b/ParticleGenerator/src/Particle/PhysicsParticle.cpp deleted file mode 100644 index 097b537..0000000 --- a/ParticleGenerator/src/Particle/PhysicsParticle.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "PhysicsParticle.hpp" - -namespace pg { - PhysicsParticle::PhysicsParticle(size_t birth, const ct::Point& position, const glm::dvec3& velocity) - : Particle(birth, position), m_velocity(velocity), m_acceleration(ct::Point()), m_friction(ct::Point()) {} - - PhysicsParticle::PhysicsParticle(const ct::Point& position, const glm::dvec3& velocity) - : PhysicsParticle(0, position, velocity) {} - - void PhysicsParticle::update(double t) - { - m_acceleration -= static_cast<glm::dvec3>(m_friction) * m_velocity; - m_velocity += m_acceleration; - - this->translate(this->m_velocity); - } -} \ No newline at end of file diff --git a/ParticleGenerator/src/Particle/generator/ParticleGenerator.hpp b/ParticleGenerator/src/Particle/generator/Generator.hpp similarity index 66% rename from ParticleGenerator/src/Particle/generator/ParticleGenerator.hpp rename to ParticleGenerator/src/Particle/generator/Generator.hpp index 7536d75..ae234af 100644 --- a/ParticleGenerator/src/Particle/generator/ParticleGenerator.hpp +++ b/ParticleGenerator/src/Particle/generator/Generator.hpp @@ -3,15 +3,17 @@ #include <memory> #include "../Particle.hpp" -namespace pg { - class ParticleGenerator { +namespace pg::particle { + + template <typename T> + class Generator { protected: float m_positionVariation; glm::vec3 m_position; glm::vec3 m_rotation; public: - ParticleGenerator(const glm::vec3& position = glm::vec3(0.f), float positionVariation = 0.0) + Generator(const glm::vec3& position = glm::vec3(0.f), float positionVariation = 0.0) : m_position(position), m_positionVariation(positionVariation), m_rotation(0.0) {} inline float getPositionVariation() const {return this->m_positionVariation;} @@ -22,8 +24,7 @@ namespace pg { inline void setPosition(const glm::vec3& position) {this->m_position = position;} inline void setRotation(const glm::vec3& rotation) {this->m_rotation = rotation;} - virtual std::vector<std::unique_ptr<Particle>> generate(size_t count, size_t birth = 0) const = 0; - - inline std::vector<std::unique_ptr<Particle>> operator()(size_t count, size_t birth = 0) const {return this->generate(count, birth);} + virtual std::vector<std::unique_ptr<T>> generate(size_t count, size_t birth = 0) const = 0; + inline std::vector<std::unique_ptr<T>> operator()(size_t count, size_t birth = 0) const {return this->generate(count, birth);} }; } \ No newline at end of file diff --git a/ParticleGenerator/src/Particle/generator/PathParticleGenerator.cpp b/ParticleGenerator/src/Particle/generator/PathGenerator.cpp similarity index 67% rename from ParticleGenerator/src/Particle/generator/PathParticleGenerator.cpp rename to ParticleGenerator/src/Particle/generator/PathGenerator.cpp index 009867c..fc759ff 100644 --- a/ParticleGenerator/src/Particle/generator/PathParticleGenerator.cpp +++ b/ParticleGenerator/src/Particle/generator/PathGenerator.cpp @@ -1,26 +1,26 @@ -#include "PathParticleGenerator.hpp" +#include "PathGenerator.hpp" #include <random> #define GLM_ENABLE_EXPERIMENTAL #include <glm/gtx/rotate_vector.hpp> -namespace pg { - PathParticleGenerator::PathParticleGenerator(ct::CurveGenerator * generator, const ct::Curve& controlPoints, const ct::Point& position, float positionVariation) - : ParticleGenerator(position, positionVariation), m_generator(generator), m_controlPoints(), m_u(0.0), m_spacing(0.0), m_increment(0.0) { +namespace pg::particle { + PathGenerator::PathGenerator(ct::CurveGenerator * generator, const ct::Curve& controlPoints, const ct::Point& position, float positionVariation) + : Generator(position, positionVariation), m_generator(generator), m_controlPoints(), m_u(0.0), m_spacing(0.0), m_increment(0.0) { for(auto & point : controlPoints) { this->m_controlPoints.push_back(this->m_position + glm::vec3(point)); } } - std::vector<std::unique_ptr<Particle>> PathParticleGenerator::generate(size_t count, size_t birth) const { + std::vector<std::unique_ptr<Path>> PathGenerator::generate(size_t count, size_t birth) const { std::random_device device; std::mt19937 randomEngine(device()); using ureal_dist = std::uniform_real_distribution<double>; ureal_dist positionGenerator(-this->getPositionVariation(), this->getPositionVariation()); - std::vector<std::unique_ptr<Particle>> particles; + std::vector<std::unique_ptr<Path>> particles; particles.reserve(count); std::vector<ct::Point> realCtrlPoint; @@ -43,7 +43,7 @@ namespace pg { positionVariation.y = positionGenerator(randomEngine); positionVariation.z = positionGenerator(randomEngine); - PathParticle * particle = new PathParticle(birth, m_generator, realCtrlPoint, m_u + u_space, m_increment); + Path * particle = new Path(birth, m_generator, realCtrlPoint, m_u + u_space, m_increment); particle->setPositionVariation(positionVariation); particle->setParameterLifeLimitor(this->m_limitor); @@ -52,7 +52,7 @@ namespace pg { u_space = 0.0; } - particles.push_back(std::unique_ptr<PathParticle>(particle)); + particles.push_back(std::unique_ptr<Path>(particle)); } return particles; diff --git a/ParticleGenerator/src/Particle/generator/PathParticleGenerator.hpp b/ParticleGenerator/src/Particle/generator/PathGenerator.hpp similarity index 69% rename from ParticleGenerator/src/Particle/generator/PathParticleGenerator.hpp rename to ParticleGenerator/src/Particle/generator/PathGenerator.hpp index 477f1eb..8263cdb 100644 --- a/ParticleGenerator/src/Particle/generator/PathParticleGenerator.hpp +++ b/ParticleGenerator/src/Particle/generator/PathGenerator.hpp @@ -1,22 +1,21 @@ #pragma once -#include "ParticleGenerator.hpp" -#include "../PathParticle.hpp" +#include "Generator.hpp" +#include "../Path.hpp" +namespace pg::interface { + class PathGenerator; +} -namespace pg { - namespace interface { - class PathGenerator; - } - - class PathParticleGenerator : public ParticleGenerator { +namespace pg::particle { + class PathGenerator : public Generator<Path> { private: ct::Curve m_controlPoints; ct::CurveGenerator * m_generator; float m_u, m_spacing, m_increment, m_limitor; public: - PathParticleGenerator(ct::CurveGenerator * generator, const ct::Curve& controlPoints, const ct::Point& position = ct::Point(), float positionVariation = 0.0); + PathGenerator(ct::CurveGenerator * generator, const ct::Curve& controlPoints, const ct::Point& position = ct::Point(), float positionVariation = 0.0); inline ct::CurveGenerator * getGenerator() const {return this->m_generator;} inline const ct::Curve& getControlPoint() const {return this->m_controlPoints;} @@ -31,7 +30,7 @@ namespace pg { inline void setParameterIncrement(float inc) {this->m_increment = inc;} inline void setParameterLifeLimitor(float limitor) {this->m_limitor = limitor;} - virtual std::vector<std::unique_ptr<Particle>> generate(size_t count, size_t birth = 0) const = 0; + virtual std::vector<std::unique_ptr<Path>> generate(size_t count, size_t birth = 0) const; friend class interface::PathGenerator; }; diff --git a/ParticleGenerator/src/Particle/generator/PhysicsParticleGenerator.cpp b/ParticleGenerator/src/Particle/generator/PhysicsGenerator.cpp similarity index 83% rename from ParticleGenerator/src/Particle/generator/PhysicsParticleGenerator.cpp rename to ParticleGenerator/src/Particle/generator/PhysicsGenerator.cpp index 5841bb7..ed06658 100644 --- a/ParticleGenerator/src/Particle/generator/PhysicsParticleGenerator.cpp +++ b/ParticleGenerator/src/Particle/generator/PhysicsGenerator.cpp @@ -1,4 +1,4 @@ -#include "PhysicsParticleGenerator.hpp" +#include "PhysicsGenerator.hpp" #include <random> @@ -7,10 +7,10 @@ #define GLM_ENABLE_EXPERIMENTAL #include <glm/gtx/rotate_vector.hpp> -namespace pg +namespace pg::particle { - PhysicsParticleGenerator::PhysicsParticleGenerator(const ct::Point& position, float positionVariation, const glm::dvec3& velocity) - : ParticleGenerator(position, positionVariation), + PhysicsGenerator::PhysicsGenerator(const ct::Point& position, float positionVariation, const glm::dvec3& velocity) + : Generator(position, positionVariation), m_velocity(velocity), m_acceleration(), m_friction(), @@ -18,7 +18,7 @@ namespace pg m_velocityVariation(), m_accelerationVariation() {} - std::vector<std::unique_ptr<Particle>> PhysicsParticleGenerator::generate(size_t count, size_t birth) const { + std::vector<std::unique_ptr<Physics>> PhysicsGenerator::generate(size_t count, size_t birth) const { std::random_device device; std::mt19937 randomEngine(device()); @@ -40,10 +40,10 @@ namespace pg ureal_dist fy(0.0, this->m_frictionVariation.y); ureal_dist fz(0.0, this->m_frictionVariation.z); - std::vector<std::unique_ptr<Particle>> particles; + std::vector<std::unique_ptr<Physics>> particles; for (size_t i = 0; i < count; ++i) { - PhysicsParticle * particle = new PhysicsParticle(birth, this->getPosition()); + Physics * particle = new Physics(birth, this->getPosition()); particle->translate({p(randomEngine), p(randomEngine), p(randomEngine)}); @@ -71,7 +71,7 @@ namespace pg particle->setAcceleration(realAcceleration); particle->setFriction(realFriction); - particles.push_back(std::unique_ptr<Particle>(particle)); + particles.push_back(std::unique_ptr<Physics>(particle)); } return particles; diff --git a/ParticleGenerator/src/Particle/generator/PhysicsParticleGenerator.hpp b/ParticleGenerator/src/Particle/generator/PhysicsGenerator.hpp similarity index 80% rename from ParticleGenerator/src/Particle/generator/PhysicsParticleGenerator.hpp rename to ParticleGenerator/src/Particle/generator/PhysicsGenerator.hpp index 155a07c..d5efbd1 100644 --- a/ParticleGenerator/src/Particle/generator/PhysicsParticleGenerator.hpp +++ b/ParticleGenerator/src/Particle/generator/PhysicsGenerator.hpp @@ -1,18 +1,18 @@ #pragma once -#include "ParticleGenerator.hpp" -#include "../PhysicsParticle.hpp" +#include "Generator.hpp" +#include "../Physics.hpp" #include "../../Interface/Generator/PhysicGenerator.hpp" -namespace pg { +namespace pg::particle { template <typename T> struct Interval { T upper; T lower; }; - class PhysicsParticleGenerator : public ParticleGenerator { + class PhysicsGenerator : public Generator<Physics> { private: glm::vec3 m_velocity; glm::vec3 m_acceleration; @@ -22,7 +22,7 @@ namespace pg { Interval<glm::vec3> m_accelerationVariation; public: - PhysicsParticleGenerator(const ct::Point& position = ct::Point(), float positionVariation = 0.0, const glm::dvec3& velocity = glm::dvec3(0.0, 0.0, 0.0)); + PhysicsGenerator(const ct::Point& position = ct::Point(), float positionVariation = 0.0, const glm::dvec3& velocity = glm::dvec3(0.0, 0.0, 0.0)); inline const glm::vec3 & getVelocity() const {return this->m_velocity;} inline const glm::vec3 & getAcceleration() const {return this->m_acceleration;} @@ -39,7 +39,7 @@ namespace pg { inline void setAccelerationVariation(const Interval<glm::vec3> & accelerationVariation) {this->m_accelerationVariation = accelerationVariation;} inline void setFrictionVariation(const glm::vec3 & frictionVariation) {this->m_frictionVariation = frictionVariation;} - std::vector<std::unique_ptr<Particle>> generate(size_t count, size_t birth = 0) const override; + std::vector<std::unique_ptr<Physics>> generate(size_t count, size_t birth = 0) const override; friend class interface::PhysicGenerator; }; diff --git a/ParticleGenerator/src/Scene/Scene.hpp b/ParticleGenerator/src/Scene/Scene.hpp index 0539574..f3bb177 100644 --- a/ParticleGenerator/src/Scene/Scene.hpp +++ b/ParticleGenerator/src/Scene/Scene.hpp @@ -24,7 +24,7 @@ namespace pg::scene { virtual void destroy() = 0; }; - using ParticleContainer = std::vector<std::unique_ptr<pg::Particle>>; + using ParticleContainer = std::vector<std::unique_ptr<pg::particle::Particle>>; class SceneParticle : public Scene { private: diff --git a/ParticleGenerator/src/Scene/Scenes/MeshGenerator.cpp b/ParticleGenerator/src/Scene/Scenes/MeshGenerator.cpp index 8294c0e..2c8daad 100644 --- a/ParticleGenerator/src/Scene/Scenes/MeshGenerator.cpp +++ b/ParticleGenerator/src/Scene/Scenes/MeshGenerator.cpp @@ -76,7 +76,7 @@ namespace pg::scene { auto end = std::chrono::high_resolution_clock::now(); if(!this->isFreezeEnable()) { - pg::Particle::purge(this->_particles, static_cast<size_t>(current_time), this->getLifetime()); + particle::Particle::purge(this->_particles, static_cast<size_t>(current_time), this->getLifetime()); if(duration_cast<std::chrono::milliseconds>(end - start).count() >= this->getSpawnFrequence()) { start = std::chrono::high_resolution_clock::now(); if(this->isSpawnEnable()) { @@ -170,7 +170,7 @@ namespace pg::scene { auto & indices = geometry.indices; for(size_t i = 0; i < geometry.indices.size(); i+= 3) { - PhysicsParticleGenerator generator; + particle::PhysicsGenerator generator; glm::vec3 & p1 = vertices[indices[i]].position, p2 = vertices[indices[i+1]].position, p3 = vertices[indices[i+2]].position; glm::vec3 baricenter = (p1 + p2 + p3) / 3.f; @@ -187,7 +187,7 @@ namespace pg::scene { void MeshGenerator::spawn(int count, double current_time) { for(auto & generator : this->_generators) { if((count + this->_particles.size()) <= this->getMaxParticles()) { - std::vector<std::unique_ptr<pg::Particle>> newParticles = generator.generate(count, static_cast<size_t>(current_time)); + std::vector<std::unique_ptr<particle::Physics>> newParticles = generator.generate(count, static_cast<size_t>(current_time)); this->_particles.insert(this->_particles.begin(), std::make_move_iterator(newParticles.begin()), std::make_move_iterator(newParticles.end())); } } diff --git a/ParticleGenerator/src/Scene/Scenes/MeshGenerator.hpp b/ParticleGenerator/src/Scene/Scenes/MeshGenerator.hpp index 428d93e..82ef60d 100644 --- a/ParticleGenerator/src/Scene/Scenes/MeshGenerator.hpp +++ b/ParticleGenerator/src/Scene/Scenes/MeshGenerator.hpp @@ -8,7 +8,7 @@ #include "../../Mesh/Mesh.hpp" #include "../../Mesh/Billboard.hpp" #include "../../Renderer/Renderer.hpp" -#include "../../Particle/generator/PhysicsParticleGenerator.hpp" +#include "../../Particle/generator/PhysicsGenerator.hpp" #include "../../Interface/Scene/MeshGenerator.hpp" namespace pg::scene { @@ -19,7 +19,7 @@ namespace pg::scene { glm::vec3 _meshPosition; glm::vec3 _meshRotation; - std::vector<PhysicsParticleGenerator> _generators; + std::vector<particle::PhysicsGenerator> _generators; Billboard _billboard; Material _billboardTexture; Program _billboardProgram; diff --git a/ParticleGenerator/src/Scene/Scenes/Path.cpp b/ParticleGenerator/src/Scene/Scenes/Path.cpp index cf776fb..c16a957 100644 --- a/ParticleGenerator/src/Scene/Scenes/Path.cpp +++ b/ParticleGenerator/src/Scene/Scenes/Path.cpp @@ -60,7 +60,7 @@ namespace pg::scene { auto end = std::chrono::high_resolution_clock::now(); if(!this->isFreezeEnable()) { - pg::Particle::purge(this->_particles, static_cast<size_t>(current_time), this->getLifetime()); + pg::particle::Particle::purge(this->_particles, static_cast<size_t>(current_time), this->getLifetime()); if(duration_cast<std::chrono::milliseconds>(end - start).count() >= 500) { start = std::chrono::high_resolution_clock::now(); if(this->isSpawnEnable()) { @@ -128,7 +128,7 @@ namespace pg::scene { void Path::spawn(int count, double current_time) { if((count + this->_particles.size()) <= this->getMaxParticles()) { - std::vector<std::unique_ptr<pg::Particle>> newParticles = this->_generator.generate(count, static_cast<size_t>(current_time)); + std::vector<std::unique_ptr<pg::particle::Path>> newParticles = this->_generator.generate(count, static_cast<size_t>(current_time)); this->_particles.insert(this->_particles.begin(), std::make_move_iterator(newParticles.begin()), std::make_move_iterator(newParticles.end())); } diff --git a/ParticleGenerator/src/Scene/Scenes/Path.hpp b/ParticleGenerator/src/Scene/Scenes/Path.hpp index 246a6dd..3c16f4c 100644 --- a/ParticleGenerator/src/Scene/Scenes/Path.hpp +++ b/ParticleGenerator/src/Scene/Scenes/Path.hpp @@ -4,7 +4,7 @@ #include "Trajectory.hpp" #include "../../Renderer/Renderer.hpp" -#include "../../Particle/generator/PathParticleGenerator.hpp" +#include "../../Particle/generator/PathGenerator.hpp" #include "../../Interface/Scene/Path.hpp" #include "../../Mesh/Billboard.hpp" #include "../../System/Window.hpp" @@ -18,7 +18,7 @@ namespace pg::scene { Billboard _billboard; Trajectory _trajectory; Material _texture; - PathParticleGenerator _generator; + particle::PathGenerator _generator; glm::vec4 _color; interface::Path _interface; @@ -34,7 +34,7 @@ namespace pg::scene { inline const Program & getProgram() const {return this->_program;} inline const Material & getTexture() const {return this->_texture;} - inline const PathParticleGenerator & getGenerator() const {return this->_generator;} + inline const particle::PathGenerator & getGenerator() const {return this->_generator;} void changeParticletexture(const std::string &); diff --git a/ParticleGenerator/src/Scene/Scenes/Physic.cpp b/ParticleGenerator/src/Scene/Scenes/Physic.cpp index eee1755..9e08faa 100644 --- a/ParticleGenerator/src/Scene/Scenes/Physic.cpp +++ b/ParticleGenerator/src/Scene/Scenes/Physic.cpp @@ -56,7 +56,7 @@ namespace pg::scene { auto end = std::chrono::high_resolution_clock::now(); if(!this->isFreezeEnable()) { - pg::Particle::purge(this->_particles, static_cast<size_t>(current_time), this->getLifetime()); + particle::Particle::purge(this->_particles, static_cast<size_t>(current_time), this->getLifetime()); if(duration_cast<std::chrono::milliseconds>(end - start).count() >= this->getSpawnFrequence()) { start = std::chrono::high_resolution_clock::now(); if(this->isSpawnEnable()) { @@ -122,7 +122,7 @@ namespace pg::scene { void Physic::spawn(int count, double current_time) { if((count + this->_particles.size()) <= this->getMaxParticles()) { - std::vector<std::unique_ptr<pg::Particle>> newParticles = this->_generator.generate(count, static_cast<size_t>(current_time)); + std::vector<std::unique_ptr<pg::particle::Physics>> newParticles = this->_generator.generate(count, static_cast<size_t>(current_time)); this->_particles.insert(this->_particles.begin(), std::make_move_iterator(newParticles.begin()), std::make_move_iterator(newParticles.end())); } } diff --git a/ParticleGenerator/src/Scene/Scenes/Physic.hpp b/ParticleGenerator/src/Scene/Scenes/Physic.hpp index 17c9bf1..8b36ea2 100644 --- a/ParticleGenerator/src/Scene/Scenes/Physic.hpp +++ b/ParticleGenerator/src/Scene/Scenes/Physic.hpp @@ -3,7 +3,7 @@ #include "../Scene.hpp" #include "../../Renderer/Renderer.hpp" -#include "../../Particle/generator/PhysicsParticleGenerator.hpp" +#include "../../Particle/generator/PhysicsGenerator.hpp" #include "../../Interface/Scene/Physic.hpp" #include "../../Mesh/Billboard.hpp" @@ -16,7 +16,7 @@ namespace pg::scene { Program _program; Material _texture; Billboard _billboards; - PhysicsParticleGenerator _generator; + particle::PhysicsGenerator _generator; glm::vec4 _color; interface::Physic _interface; @@ -27,7 +27,7 @@ namespace pg::scene { inline const Program & getProgram() const {return this->_program;} inline const Material & getTexture() const {return this->_texture;} - inline const PhysicsParticleGenerator & getGenerator() const {return this->_generator;} + inline const particle::PhysicsGenerator & getGenerator() const {return this->_generator;} void changeParticletexture(const std::string &); diff --git a/ParticleGenerator/src/Scene/Scenes/PhysicSprite.cpp b/ParticleGenerator/src/Scene/Scenes/PhysicSprite.cpp index 494c2f6..c97ca9b 100644 --- a/ParticleGenerator/src/Scene/Scenes/PhysicSprite.cpp +++ b/ParticleGenerator/src/Scene/Scenes/PhysicSprite.cpp @@ -61,7 +61,7 @@ namespace pg::scene { auto end = std::chrono::high_resolution_clock::now(); if(!this->isFreezeEnable()) { - pg::Particle::purge(this->_particles, static_cast<size_t>(current_time), this->getLifetime()); + pg::particle::Particle::purge(this->_particles, static_cast<size_t>(current_time), this->getLifetime()); if(duration_cast<std::chrono::milliseconds>(end - start).count() >= this->getSpawnFrequence()) { start = std::chrono::high_resolution_clock::now(); if(this->isSpawnEnable()) { @@ -134,7 +134,7 @@ namespace pg::scene { void PhysicSprite::spawn(int count, double current_time) { if((count + this->_particles.size()) <= this->getMaxParticles()) { - std::vector<std::unique_ptr<pg::Particle>> newParticles = this->_generator.generate(count, static_cast<size_t>(current_time)); + std::vector<std::unique_ptr<pg::particle::Physics>> newParticles = this->_generator.generate(count, static_cast<size_t>(current_time)); this->_particles.insert(this->_particles.end(), std::make_move_iterator(newParticles.begin()), std::make_move_iterator(newParticles.end())); } } diff --git a/ParticleGenerator/src/Scene/Scenes/PhysicSprite.hpp b/ParticleGenerator/src/Scene/Scenes/PhysicSprite.hpp index 8a7d74c..59e489e 100644 --- a/ParticleGenerator/src/Scene/Scenes/PhysicSprite.hpp +++ b/ParticleGenerator/src/Scene/Scenes/PhysicSprite.hpp @@ -3,7 +3,7 @@ #include "../Scene.hpp" #include "../../Renderer/Renderer.hpp" -#include "../../Particle/generator/PhysicsParticleGenerator.hpp" +#include "../../Particle/generator/PhysicsGenerator.hpp" #include "../../Interface/Scene/Physic.hpp" #include "../../Mesh/Billboard.hpp" @@ -17,7 +17,7 @@ namespace pg::scene { Material _texture; Billboard _billboards; std::vector<glm::vec4> _frames; - PhysicsParticleGenerator _generator; + particle::PhysicsGenerator _generator; glm::vec4 _color; public: @@ -26,7 +26,7 @@ namespace pg::scene { inline const Program & getProgram() const {return this->_program;} inline const Material & getTexture() const {return this->_texture;} - inline const PhysicsParticleGenerator & getGenerator() const {return this->_generator;} + inline const particle::PhysicsGenerator & getGenerator() const {return this->_generator;} void changeParticletexture(const std::string &); diff --git a/ParticleGenerator/src/Scene/Scenes/Trajectory.cpp b/ParticleGenerator/src/Scene/Scenes/Trajectory.cpp index 3038418..ec73c94 100644 --- a/ParticleGenerator/src/Scene/Scenes/Trajectory.cpp +++ b/ParticleGenerator/src/Scene/Scenes/Trajectory.cpp @@ -4,7 +4,7 @@ #include <CurveTools/CPU/CurveSampler.hpp> namespace pg::scene { - Trajectory::Trajectory(PathParticleGenerator * generator, double increment) + Trajectory::Trajectory(particle::PathGenerator * generator, double increment) : _generator(generator), _vbo(this->_vao, {layout::POSITION, layout::COLOR}), _increment(increment), diff --git a/ParticleGenerator/src/Scene/Scenes/Trajectory.hpp b/ParticleGenerator/src/Scene/Scenes/Trajectory.hpp index 9baa821..c9a1d6c 100644 --- a/ParticleGenerator/src/Scene/Scenes/Trajectory.hpp +++ b/ParticleGenerator/src/Scene/Scenes/Trajectory.hpp @@ -1,14 +1,14 @@ #pragma once #include "../../Renderer/Renderer.hpp" -#include "../../Particle/generator/PathParticleGenerator.hpp" +#include "../../Particle/generator/PathGenerator.hpp" #include "../../Interface/Scene/Trajectory.hpp" #include "../Scene.hpp" namespace pg::scene { class Trajectory : public Scene { private: - PathParticleGenerator * _generator; + particle::PathGenerator * _generator; VertexArray _vao; VerticeBuffer _vbo; Program _program; @@ -22,9 +22,9 @@ namespace pg::scene { interface::Trajectory _interface; public: - Trajectory(PathParticleGenerator *, double = 0.01f); + Trajectory(particle::PathGenerator *, double = 0.01f); - inline PathParticleGenerator * getGenerator() const {return this->_generator;} + inline particle::PathGenerator * getGenerator() const {return this->_generator;} inline double getIncrement() const {return this->_increment;} inline const glm::vec4 & getColor() const {return this->_color;} inline float getPointSize() const {return this->_pointSize;} -- GitLab