Skip to content
Snippets Groups Projects
Commit 0a4595fd authored by BATON Theau's avatar BATON Theau
Browse files

Refactoring Generator and Particle namesapce

parent f1660de9
Branches
No related tags found
No related merge requests found
Showing
with 94 additions and 77 deletions
......@@ -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
......@@ -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),
......
......@@ -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;
......
......@@ -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) {
......
......@@ -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";}
......
......@@ -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) {
......
......@@ -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);
......
......@@ -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) {
......
......@@ -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);
......
......@@ -2,7 +2,7 @@
#include <chrono>
namespace pg {
namespace pg::particle {
Particle::Particle(const ct::Point& position)
: Particle(0, position) {}
......
......@@ -5,7 +5,7 @@
#include <CurveTools/CPU/CurveGenerator.hpp>
namespace pg
namespace pg::particle
{
class Particle
{
......
#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;
......
......@@ -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;}
......
#include "PhysicsParticle.hpp"
#include "Physics.hpp"
namespace pg {
PhysicsParticle::PhysicsParticle(size_t birth, const ct::Point& position, const glm::dvec3& velocity)
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()) {}
PhysicsParticle::PhysicsParticle(const ct::Point& position, const glm::dvec3& velocity)
: PhysicsParticle(0, position, velocity) {}
Physics::Physics(const ct::Point& position, const glm::dvec3& velocity)
: Physics(0, position, velocity) {}
void PhysicsParticle::update(double t)
{
void Physics::update(double t) {
m_acceleration -= static_cast<glm::dvec3>(m_friction) * m_velocity;
m_velocity += m_acceleration;
......
......@@ -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;}
......
......@@ -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
#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;
......
#pragma once
#include "ParticleGenerator.hpp"
#include "../PathParticle.hpp"
#include "Generator.hpp"
#include "../Path.hpp"
namespace pg {
namespace interface {
namespace pg::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;
};
......
#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;
......
#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;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment