diff --git a/ParticleGenerator/res/config/imgui.ini b/ParticleGenerator/res/config/imgui.ini index 2049a5ed91703b1c8fcee9b217bf4211a5023975..66570e980fd9b91b81d11036729f9fe88dd0631c 100644 --- a/ParticleGenerator/res/config/imgui.ini +++ b/ParticleGenerator/res/config/imgui.ini @@ -3,8 +3,9 @@ Pos=60,60 Size=400,400 [Window][Dear ImGui Demo] -Pos=650,20 +Pos=926,43 Size=550,680 +Collapsed=1 [Window][Particle Generator] Pos=60,60 diff --git a/ParticleGenerator/src/Interface/Generator/PathUniqueGenerator.cpp b/ParticleGenerator/src/Interface/Generator/PathGenerator.cpp similarity index 92% rename from ParticleGenerator/src/Interface/Generator/PathUniqueGenerator.cpp rename to ParticleGenerator/src/Interface/Generator/PathGenerator.cpp index 11a6872aecaf35df9caaf1981c45c5006f7ba4e3..887f7a097a5247927e268f1010374d4cd87c8cf0 100644 --- a/ParticleGenerator/src/Interface/Generator/PathUniqueGenerator.cpp +++ b/ParticleGenerator/src/Interface/Generator/PathGenerator.cpp @@ -1,19 +1,19 @@ #pragma once -#include "PathUniqueGenerator.hpp" +#include "PathGenerator.hpp" #include <imgui.h> -#include "../../Particle/generator/PathUniqueGenerator.hpp" +#include "../../Particle/generator/PathGenerator.hpp" namespace pg::interface { - PathUniqueGenerator::PathUniqueGenerator(particle::PathUniqueGenerator * parent, scene::Trajectory * trajectory) + PathGenerator::PathGenerator(particle::PathGenerator * parent, scene::Trajectory * trajectory) : Generator(parent), _trajectory(trajectory), _next(0.f, 0.f, 0.f), _index(0) {} - void PathUniqueGenerator::draw(double current_time) { + void PathGenerator::draw(double current_time) { ImGui::Text("Physic generator at %f / %f / %f (x, y, z) - variation : %f.", this->parent()->m_position.x, this->parent()->m_position.y, this->parent()->m_position.z, this->parent()->m_positionVariation); ImGui::Text("Default u : %f", this->parent()->m_u); ImGui::Text("u increment : %f", this->parent()->m_increment); diff --git a/ParticleGenerator/src/Interface/Generator/PathUniqueGenerator.hpp b/ParticleGenerator/src/Interface/Generator/PathGenerator.hpp similarity index 63% rename from ParticleGenerator/src/Interface/Generator/PathUniqueGenerator.hpp rename to ParticleGenerator/src/Interface/Generator/PathGenerator.hpp index 91f5ea8ecef73f3f22c784cf75a479b013884366..01c6f58b1e07f85bc20fda74f8615bb65724a53b 100644 --- a/ParticleGenerator/src/Interface/Generator/PathUniqueGenerator.hpp +++ b/ParticleGenerator/src/Interface/Generator/PathGenerator.hpp @@ -6,11 +6,11 @@ #include <glm/vec3.hpp> namespace pg::particle { - class PathUniqueGenerator; + class PathGenerator; } namespace pg::interface { - class PathUniqueGenerator : public Generator<particle::PathUniqueGenerator> { + class PathGenerator : public Generator<particle::PathGenerator> { private: scene::Trajectory * _trajectory; @@ -18,8 +18,8 @@ namespace pg::interface { int _index; public: - PathUniqueGenerator(particle::PathUniqueGenerator *, scene::Trajectory * = nullptr); - virtual ~PathUniqueGenerator() = default; + PathGenerator(particle::PathGenerator *, scene::Trajectory * = nullptr); + virtual ~PathGenerator() = default; void draw(double) override; virtual inline std::string title() const {return "Path Generator Interface";} diff --git a/ParticleGenerator/src/Interface/Scene/Path.cpp b/ParticleGenerator/src/Interface/Scene/Path.cpp index d283ce0786c17f7737fcd5ed15e942fc750748ab..e6981583a59bec0c8e45ec35e6537b8397a547d9 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, particle::PathUniqueGenerator * generator, 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 a1f381d3760f7af520f3c7e3f6fe692075e1cfbd..6359ed4546f847d9b9a1fe0aaf90bcf926fea6b3 100644 --- a/ParticleGenerator/src/Interface/Scene/Path.hpp +++ b/ParticleGenerator/src/Interface/Scene/Path.hpp @@ -2,7 +2,7 @@ #include "../Interface.hpp" #include "SceneParticle.hpp" -#include "../Generator/PathUniqueGenerator.hpp" +#include "../Generator/PathGenerator.hpp" #include "../../Scene/Scenes/Trajectory.hpp" #include <glm/vec4.hpp> @@ -15,10 +15,10 @@ namespace pg::scene { namespace pg::interface { class Path : public Scene<scene::Path>, public SceneParticle { private: - PathUniqueGenerator _interface; + PathGenerator _interface; public: - Path(scene::Path *, particle::PathUniqueGenerator *, 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/Particle/generator/PathGenerator.cpp b/ParticleGenerator/src/Particle/generator/PathGenerator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bdd41d4337f7bdab623ca6f494cdabb465e93c6a --- /dev/null +++ b/ParticleGenerator/src/Particle/generator/PathGenerator.cpp @@ -0,0 +1,10 @@ +#include "PathGenerator.hpp" + +namespace pg::particle { + PathGenerator::PathGenerator(const ct::Curve& controlPoints, const ct::Point& position, float positionVariation) + : Generator(position, positionVariation), 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)); + } + } +} \ No newline at end of file diff --git a/ParticleGenerator/src/Particle/generator/PathGenerator.hpp b/ParticleGenerator/src/Particle/generator/PathGenerator.hpp new file mode 100644 index 0000000000000000000000000000000000000000..80dcadc3c5c17dea3bb64ccd481a967d0ec0b84a --- /dev/null +++ b/ParticleGenerator/src/Particle/generator/PathGenerator.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include "Generator.hpp" +#include "../Path.hpp" + +namespace pg::interface { + class PathGenerator; +} + +namespace pg::particle { + class PathGenerator : public Generator<Path> { + private: + ct::Curve m_controlPoints; + float m_u, m_spacing, m_increment, m_limitor; + + public: + PathGenerator(const ct::Curve& controlPoints, const ct::Point& position = ct::Point(), float positionVariation = 0.0); + + inline const ct::Curve& getControlPoint() const {return this->m_controlPoints;} + inline float getParameter() const {return this->m_u;} + inline float getSpacing() const {return this->m_spacing;} + inline float getParameterIncrement() const {return this->m_increment;} + inline float getParameterLifeLimitor() const {return this->m_limitor;} + + inline void setControlPoint(const ct::Curve& points) {this->m_controlPoints = points;} + inline void setDefaultParameterValue(float u) {this->m_u = u;} + inline void setParameterIncrement(float inc) {this->m_increment = inc;} + inline void setParameterLifeLimitor(float limitor) {this->m_limitor = limitor;} + + friend class pg::interface::PathGenerator; + }; +} \ No newline at end of file diff --git a/ParticleGenerator/src/Particle/generator/PathMultyGenerator.cpp b/ParticleGenerator/src/Particle/generator/PathMultyGenerator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8a129d6bce745cfdffba61a15d51910c04d5f256 --- /dev/null +++ b/ParticleGenerator/src/Particle/generator/PathMultyGenerator.cpp @@ -0,0 +1,65 @@ +#include "PathMultyGenerator.hpp" + +#include <random> + +#define GLM_ENABLE_EXPERIMENTAL +#include <glm/gtx/rotate_vector.hpp> + +namespace pg::particle { + PathMultyGenerator::PathMultyGenerator(const ct::Curve& controlPoints, const ct::Point& position, float positionVariation) + : PathGenerator(controlPoints, position, positionVariation), _generators() {} + + std::vector<std::unique_ptr<Path>> PathMultyGenerator::generate(size_t count, size_t birth) const { + std::random_device device; + std::mt19937 randomEngine(device()); + + using ureal_dist = std::uniform_real_distribution<double>; + using uint_dist = std::uniform_int_distribution<>; + + ureal_dist positionGenerator(-this->getPositionVariation(), this->getPositionVariation()); + uint_dist generatorIndex(0, static_cast<int>(this->_generators.size()-1)); + + std::vector<std::unique_ptr<Path>> particles; + particles.reserve(count); + + std::vector<ct::Point> realCtrlPoint; + for(auto & point : this->getControlPoint()) { + glm::dvec3 glmPoint = point; + + glmPoint = glm::rotateZ<double>(glmPoint, glm::radians<double>(this->m_rotation.z)); + glmPoint = glm::rotateY<double>(glmPoint, glm::radians<double>(this->m_rotation.y)); + glmPoint = glm::rotateX<double>(glmPoint, glm::radians<double>(this->m_rotation.x)); + + realCtrlPoint.push_back(glmPoint + ct::Point(m_position)); + } + + double u_space = 0.0; + std::vector<std::string> names; + for(auto&[name, generator] : this->_generators) { + names.push_back(name); + } + + for (unsigned int i = 0; i < count; ++i) { + glm::dvec3 positionVariation(0.0); + + positionVariation.x = positionGenerator(randomEngine); + positionVariation.y = positionGenerator(randomEngine); + positionVariation.z = positionGenerator(randomEngine); + + ct::CurveGenerator * generator = this->_generators.at(names.at(generatorIndex(randomEngine))).get(); + + Path * particle = new Path(birth, generator, realCtrlPoint, this->getParameter() + u_space, this->getParameterIncrement()); + particle->setPositionVariation(positionVariation); + particle->setParameterLifeLimitor(this->getParameterLifeLimitor()); + + u_space += this->getSpacing(); + if(u_space > 1.0) { + u_space = 0.0; + } + + particles.push_back(std::unique_ptr<Path>(particle)); + } + + return particles; + } +} \ No newline at end of file diff --git a/ParticleGenerator/src/Particle/generator/PathMultyGenerator.hpp b/ParticleGenerator/src/Particle/generator/PathMultyGenerator.hpp new file mode 100644 index 0000000000000000000000000000000000000000..52001c5b5a38dc1e8f479fc8846b8279f010ff23 --- /dev/null +++ b/ParticleGenerator/src/Particle/generator/PathMultyGenerator.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "PathGenerator.hpp" +#include "../Path.hpp" + +#include <map> +#include <memory> + +namespace pg::particle { + class PathMultyGenerator : public PathGenerator { + private: + std::map<std::string, std::unique_ptr<ct::CurveGenerator>> _generators; + + public: + PathMultyGenerator(const ct::Curve& controlPoints, const ct::Point& position = ct::Point(), float positionVariation = 0.0); + + inline void add(const std::string & name, ct::CurveGenerator * generator) {this->_generators.insert(std::pair<std::string, ct::CurveGenerator *>(name, generator));} + + inline const std::map<std::string, std::unique_ptr<ct::CurveGenerator>> & getGenerators() const {return this->_generators;} + + virtual std::vector<std::unique_ptr<Path>> generate(size_t count, size_t birth = 0) const; + }; +} \ No newline at end of file diff --git a/ParticleGenerator/src/Particle/generator/PathUniqueGenerator.cpp b/ParticleGenerator/src/Particle/generator/PathUniqueGenerator.cpp index e19cda1dabf62274d674c8a2d2e9b57b56806e1c..6669aea4eab84d47473ea1087f959bda7fbfc510 100644 --- a/ParticleGenerator/src/Particle/generator/PathUniqueGenerator.cpp +++ b/ParticleGenerator/src/Particle/generator/PathUniqueGenerator.cpp @@ -7,10 +7,8 @@ namespace pg::particle { PathUniqueGenerator::PathUniqueGenerator(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)); - } + : PathGenerator(controlPoints, position, positionVariation), m_generator(generator) { + } std::vector<std::unique_ptr<Path>> PathUniqueGenerator::generate(size_t count, size_t birth) const { @@ -24,7 +22,7 @@ namespace pg::particle { particles.reserve(count); std::vector<ct::Point> realCtrlPoint; - for(auto & point : m_controlPoints) { + for(auto & point : this->getControlPoint()) { glm::dvec3 glmPoint = point; glmPoint = glm::rotateZ<double>(glmPoint, glm::radians<double>(this->m_rotation.z)); @@ -34,7 +32,7 @@ namespace pg::particle { realCtrlPoint.push_back(glmPoint + ct::Point(m_position)); } - double u_space = 0.0; + float u_space = 0.0; for (unsigned int i = 0; i < count; ++i) { glm::dvec3 positionVariation(0.0); @@ -43,11 +41,11 @@ namespace pg::particle { positionVariation.y = positionGenerator(randomEngine); positionVariation.z = positionGenerator(randomEngine); - Path * particle = new Path(birth, m_generator, realCtrlPoint, m_u + u_space, m_increment); + Path * particle = new Path(birth, m_generator, realCtrlPoint, this->getParameter() + this->getSpacing(), this->getParameterIncrement()); particle->setPositionVariation(positionVariation); - particle->setParameterLifeLimitor(this->m_limitor); + particle->setParameterLifeLimitor(this->getParameterLifeLimitor()); - u_space += m_spacing; + u_space += this->getSpacing(); if(u_space > 1.0) { u_space = 0.0; } diff --git a/ParticleGenerator/src/Particle/generator/PathUniqueGenerator.hpp b/ParticleGenerator/src/Particle/generator/PathUniqueGenerator.hpp index a6abb2168c0f8db1748f6c98880a89c90f15a0e3..0026dbc89375d64d7bc65e84bd5e941a3d27a78e 100644 --- a/ParticleGenerator/src/Particle/generator/PathUniqueGenerator.hpp +++ b/ParticleGenerator/src/Particle/generator/PathUniqueGenerator.hpp @@ -1,39 +1,23 @@ #pragma once -#include "Generator.hpp" +#include "PathGenerator.hpp" #include "../Path.hpp" -#include <set> - namespace pg::interface { class PathUniqueGenerator; } namespace pg::particle { - class PathUniqueGenerator : public Generator<Path> { + class PathUniqueGenerator : public PathGenerator { private: - ct::Curve m_controlPoints; ct::CurveGenerator * m_generator; - float m_u, m_spacing, m_increment, m_limitor; public: PathUniqueGenerator(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;} - inline float getParameter() const {return this->m_u;} - inline float getSpacing() const {return this->m_spacing;} - inline float getParameterIncrement() const {return this->m_increment;} - inline float getParameterLifeLimitor() const {return this->m_limitor;} - inline void setGenerator(ct::CurveGenerator * genertor) {this->m_generator = genertor;} - inline void setControlPoint(const ct::Curve& points) {this->m_controlPoints = points;} - inline void setDefaultParameterValue(float u) {this->m_u = u;} - inline void setParameterIncrement(float inc) {this->m_increment = inc;} - inline void setParameterLifeLimitor(float limitor) {this->m_limitor = limitor;} virtual std::vector<std::unique_ptr<Path>> generate(size_t count, size_t birth = 0) const; - - friend class interface::PathUniqueGenerator; }; } \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scenes/MultyPath.cpp b/ParticleGenerator/src/Scene/Scenes/MultyPath.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a924f2cc81f80be224aa282c9a6cef08b4192fde --- /dev/null +++ b/ParticleGenerator/src/Scene/Scenes/MultyPath.cpp @@ -0,0 +1,143 @@ +#include "MultyPath.hpp" + +#include <chrono> +#include <glm/gtc/matrix_transform.hpp> + +#include <CurveTools/CPU/BezierGenerator.hpp> +#include <CurveTools/CPU/CatmullRomGenerator.hpp> +#include <CurveTools/CPU/LinearGenerator.hpp> + +namespace pg::scene { + MultyPath::MultyPath(const ct::Curve & ctrlpoint) + : SceneParticle(1024), + _ubo(0), + _program(), + _texture(), + _generator(ctrlpoint), + _trajectory(&this->_generator) { + this->_generator.add("Bezier", new ct::BezierGenerator()); + this->_generator.add("Catmull-Rom", new ct::CatmullRomGenerator()); + this->_generator.add("Linear", new ct::LinearGenerator()); + } + + void MultyPath::initialize() { + this->_billboard.initialize(); + this->_trajectory.initialize(); + if(!this->_program.usable()) { + pg::Source vertices("res/shaders/scene/Billboard.vert", pg::Source::Categorie::VERTEX); + pg::Source fragment("res/shaders/scene/Billboard.frag", pg::Source::Categorie::FRAGMENT); + + this->_program << vertices; + this->_program << fragment; + + this->_program.link(); + + vertices.release(); + fragment.release(); + } + + pg::error::OpenGLError::check(); + + glCreateBuffers(1, &this->_ubo); + glBindBuffer(GL_UNIFORM_BUFFER, this->_ubo); + glBufferData(GL_UNIFORM_BUFFER, 1024 * sizeof(glm::mat4), nullptr, GL_DYNAMIC_DRAW); + + GLuint uniforme_index = glGetUniformBlockIndex(this->_program.id(), "uModels_t"); + glBindBufferBase(GL_UNIFORM_BUFFER, uniforme_index, this->_ubo); + + pg::error::OpenGLError::check(); + + this->_texture.load("res/textures/smoke1.png"); + + pg::error::OpenGLError::check(); + + this->_generator.setPosition({0.f, 0.f, 0.f}); + this->_generator.setPositionVariation(0.5f); + this->_generator.setParameterIncrement(0.01f); + this->_generator.setParameterLifeLimitor(1.0f); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glClearColor(0.25f, 0.f, 0.15f, 1.0f); + } + + void MultyPath::update(double current_time) { + static auto start = std::chrono::high_resolution_clock::now(); + auto end = std::chrono::high_resolution_clock::now(); + + if(!this->isFreezeEnable()) { + 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()) { + this->spawn(this->getSpawnCount(), current_time); + } + } + + if(duration_cast<std::chrono::milliseconds>(end - start).count() >= 10) { + for(auto& particle : this->_particles) { + particle->update(0.0); + } + } + } + } + + void MultyPath::render(const Camera & camera, double current_time) { + const glm::mat4 VIEW_MATRIX = camera.getViewMatrix(); + const glm::mat4 PROJECTION_MATRIX = camera.getViewFrustum().getProjectionMatrix(); + + this->_trajectory.render(camera, current_time); + pg::error::OpenGLError::check(); + + std::vector<glm::mat4> models; + + for(auto & particle : this->_particles) { + glm::mat4 model = glm::mat4(1.0); + model = glm::translate(model, glm::vec3(particle->getPosition())); + models.push_back(model); + } + + pg::error::OpenGLError::check(); + + glBindBuffer(GL_UNIFORM_BUFFER, this->_ubo); + glBufferSubData(GL_UNIFORM_BUFFER, 0, models.size() * sizeof(glm::mat4), models.data()); + + pg::error::OpenGLError::check(); + + this->_program.use(); + + this->_program.setUniform("uView", VIEW_MATRIX); + this->_program.setUniform("uProj", PROJECTION_MATRIX); + this->_program.setUniform("uSlot", 0); + this->_program.setUniform("uColor", glm::vec4(1.f)); + + pg::error::OpenGLError::check(); + + this->_texture.bind(); + if(this->isRenderEnable()) { + this->_billboard.draw(this->_particles.size()); + } + + pg::error::OpenGLError::check(); + } + + void MultyPath::destroy() { + glDeleteBuffers(1, &this->_ubo); + this->_billboard.destroy(); + this->_particles.clear(); + + pg::error::OpenGLError::check(); + } + + void MultyPath::changeParticletexture(const std::string & Multypath) { + this->_texture.load(Multypath); + } + + void MultyPath::spawn(int count, double current_time) { + if((count + this->_particles.size()) <= this->getMaxParticles()) { + 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())); + } + + } +} \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scenes/MultyPath.hpp b/ParticleGenerator/src/Scene/Scenes/MultyPath.hpp new file mode 100644 index 0000000000000000000000000000000000000000..35793423a424cc6d3d8ce1268ef936086e477df5 --- /dev/null +++ b/ParticleGenerator/src/Scene/Scenes/MultyPath.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include "../Scene.hpp" + +#include "../../Renderer/Renderer.hpp" +#include "../../Particle/generator/PathMultyGenerator.hpp" +#include "../../Mesh/Billboard.hpp" +#include "TrajectoryMulty.hpp" + +namespace pg::scene { + class MultyPath : public SceneParticle { + private: + GLuint _ubo; + Program _program; + Billboard _billboard; + TrajectoryMulty _trajectory; + Material _texture; + particle::PathMultyGenerator _generator; + + public: + MultyPath(const ct::Curve &); + virtual ~MultyPath() = default; + + virtual void initialize(); + virtual void render(const Camera &, double); + virtual void update(double); + virtual void destroy(); + + inline const Program & getProgram() const {return this->_program;} + inline const Material & getTexture() const {return this->_texture;} + inline const particle::PathMultyGenerator & getGenerator() const {return this->_generator;} + + void changeParticletexture(const std::string &); + + virtual std::string name() const {return "Multy Path Scene";} + + virtual void spawn(int, double); + }; +} \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.cpp b/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c4b13b1f1ffbfa46471646c5d4949290105a35a5 --- /dev/null +++ b/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.cpp @@ -0,0 +1,100 @@ +#include "TrajectoryMulty.hpp" + +namespace pg::scene { + TrajectoryMulty::TrajectoryMulty(particle::PathMultyGenerator * generator, double increment, const std::vector<glm::vec4> & colors) + : _generators(generator), + _colors(colors), + _vao(), + _vbo(this->_vao, {layout::POSITION, layout::COLOR}), + _increment(increment), + _pointSize(8.f), + _lineSize(1.f), + _controlLine(false) {} + + void TrajectoryMulty::initialize() { + this->update(0.0); + if(!this->_program.usable()) { + Source vert("res/shaders/scene/Trajectory.vert", Source::Categorie::VERTEX); + Source frag("res/shaders/scene/Trajectory.frag", Source::Categorie::FRAGMENT); + + this->_program << vert; + this->_program << frag; + + this->_program.link(); + + vert.release(); + frag.release(); + } + } + + void TrajectoryMulty::update(double) { + std::vector<float> traj; + + for(auto & point : this->_generators->getControlPoint()) { + traj.push_back(static_cast<float>(point.x)); + traj.push_back(static_cast<float>(point.y)); + traj.push_back(static_cast<float>(point.z)); + + traj.push_back(1.0f); + traj.push_back(1.0f); + traj.push_back(1.0f); + } + + std::vector<double> ps; + double degre_max = 1.f; + for(auto &[name, generator] : this->_generators->getGenerators()) { + uint16_t degree = generator->getDegree(); + if(degree > degre_max) { + degre_max = degree; + } + } + + for(double i = 0.f; i < degre_max; i += this->_increment) { + ps.push_back(i); + } + + size_t color_nb = this->_colors.size(); + size_t i = 0; + for(auto &[name, generator] : this->_generators->getGenerators()) { + ct::Curve curve = generator->generate(this->_generators->getControlPoint(), ps); + + size_t index = i%color_nb; + for(auto & point : curve) { + traj.push_back(static_cast<float>(point.x)); + traj.push_back(static_cast<float>(point.y)); + traj.push_back(static_cast<float>(point.z)); + + traj.push_back(this->_colors.at(index).r); + traj.push_back(this->_colors.at(index).g); + traj.push_back(this->_colors.at(index).b); + } + ++i; + } + + + this->_vbo.set(traj); + } + + void TrajectoryMulty::render(const Camera & camera, double current_time) { + glEnable(GL_LINE_SMOOTH); + glLineWidth(this->_lineSize); + this->_vao.bind(); + + glEnable(GL_PROGRAM_POINT_SIZE); + this->_program.use(); + this->_program.setUniform("uProj", camera.getViewFrustum().getProjectionMatrix()); + this->_program.setUniform("uView", camera.getViewMatrix()); + this->_program.setUniform("uColor", glm::vec4(1.f)); + this->_program.setUniform("uPointSize", this->_pointSize); + + GLsizei raw = static_cast<GLsizei>(this->_generators->getControlPoint().size()); + GLsizei total = static_cast<GLsizei>(this->_vbo.vertices()); + + glDrawArrays(GL_LINE_STRIP, raw, total - raw); + glDrawArrays(this->_controlLine ? GL_LINE_STRIP : GL_POINTS, 0, static_cast<GLsizei>(this->_generators->getControlPoint().size())); + } + + void TrajectoryMulty::destroy() { + + } +} \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.hpp b/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0d65a9e18d52c745900e673c1febc748e0a84be2 --- /dev/null +++ b/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include "../Scene.hpp" + +#include <glm/vec4.hpp> + +#include "../../Renderer/Renderer.hpp" +#include "../../Particle/generator/PathMultyGenerator.hpp" + +namespace pg::scene { + class TrajectoryMulty : public Scene { + private: + particle::PathMultyGenerator * _generators; + std::vector<glm::vec4> _colors; + VertexArray _vao; + VerticeBuffer _vbo; + Program _program; + double _increment; + + float _pointSize; + float _lineSize; + bool _controlLine; + + public: + TrajectoryMulty(particle::PathMultyGenerator *, double = 0.01, const std::vector<glm::vec4> & colors = {{1.f, 0.f, 0.f, 1.f}, {0.f, 1.f, 0.f, 1.f}, {0.f, 1.f, 0.f, 1.f}}); + + void initialize(); + void render(const Camera &, double); + void update(double); + void destroy(); + + }; +} \ No newline at end of file diff --git a/ParticleGenerator/src/main.cpp b/ParticleGenerator/src/main.cpp index 2e5fbd422c3b123d0ba408d061f4b346d7be2ebe..87505251309600816c7e06ffa943522cf4460279 100644 --- a/ParticleGenerator/src/main.cpp +++ b/ParticleGenerator/src/main.cpp @@ -12,6 +12,7 @@ #include "Scene/Scenes/MeshGenerator.hpp" #include "Scene/Scenes/Grid.hpp" #include "Scene/Scenes/PhysicSprite.hpp" +#include "Scene/Scenes/MultyPath.hpp" #include "Interface/Manager.hpp" @@ -68,8 +69,10 @@ int main(int argc, const char * argv[]) { } ct::Curve ctrlPoints { - { 10.f, 0.f, 0.f}, - {-10.f, 0.f, 0.f} + { 10.f, 0.f, 0.f}, + {-10.f, 0.f, 0.f}, + {-10.f, 10.f, 0.f}, + { 10.f, 10.f, 0.f} }; ct::BezierGenerator bezier(static_cast<unsigned int>(ctrlPoints.size())); @@ -78,6 +81,7 @@ int main(int argc, const char * argv[]) { pg::scene::PhysicSprite physicSprite; pg::scene::MeshGenerator meshGenerator; pg::scene::Path path(&bezier, ctrlPoints); + pg::scene::MultyPath multyPath(ctrlPoints); pg::Manager manager(window); pg::interface::Manager imanager(window, manager); @@ -86,6 +90,7 @@ int main(int argc, const char * argv[]) { manager.add(&physic); manager.add(&physicSprite); manager.add(&meshGenerator); + manager.add(&multyPath); while(window.isOpen()) { double current_time = glfwGetTime();