From a9f3fa0880a8f5f416c167540f3fe7aeb66127e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9au?= <theau.baton@etu.univ-amu.fr> Date: Sun, 26 May 2024 20:03:08 +0200 Subject: [PATCH] Correct multiple trajectory --- ParticleGenerator/res/config/imgui.ini | 6 +- .../res/shaders/scene/Trajectory.vert | 3 +- ParticleGenerator/res/textures/gray.png | Bin 0 -> 138 bytes .../Generator/PathMultyGenerator.cpp | 87 ++++++++++++++++++ .../Generator/PathMultyGenerator.hpp | 27 ++++++ .../Interface/Generator/PhysicGenerator.cpp | 14 +-- .../src/Interface/Scene/MultyPath.cpp | 39 ++++++++ .../src/Interface/Scene/MultyPath.hpp | 29 ++++++ .../src/Interface/Scene/Trajectory.cpp | 20 +++- .../src/Interface/Scene/TrajectoryMulty.cpp | 40 ++++++++ .../src/Interface/Scene/TrajectoryMulty.hpp | 17 ++++ ParticleGenerator/src/Particle/Particle.cpp | 2 +- ParticleGenerator/src/Particle/Particle.hpp | 13 ++- ParticleGenerator/src/Particle/Path.cpp | 8 +- ParticleGenerator/src/Particle/Physics.cpp | 4 +- .../src/Particle/generator/Generator.hpp | 14 ++- .../Particle/generator/PhysicsGenerator.cpp | 6 +- .../src/Scene/Scenes/MeshGenerator.cpp | 17 +--- .../src/Scene/Scenes/MeshGeneratorModel.cpp | 13 ++- .../src/Scene/Scenes/MultyPath.cpp | 7 +- .../src/Scene/Scenes/MultyPath.hpp | 5 + ParticleGenerator/src/Scene/Scenes/Path.cpp | 14 ++- ParticleGenerator/src/Scene/Scenes/Physic.cpp | 4 +- .../src/Scene/Scenes/PhysicSprite.cpp | 5 +- .../src/Scene/Scenes/Trajectory.cpp | 44 +++++---- .../src/Scene/Scenes/Trajectory.hpp | 6 +- .../src/Scene/Scenes/TrajectoryMulty.cpp | 57 +++++++----- .../src/Scene/Scenes/TrajectoryMulty.hpp | 10 +- 28 files changed, 406 insertions(+), 105 deletions(-) create mode 100644 ParticleGenerator/res/textures/gray.png create mode 100644 ParticleGenerator/src/Interface/Generator/PathMultyGenerator.cpp create mode 100644 ParticleGenerator/src/Interface/Generator/PathMultyGenerator.hpp create mode 100644 ParticleGenerator/src/Interface/Scene/MultyPath.cpp create mode 100644 ParticleGenerator/src/Interface/Scene/MultyPath.hpp create mode 100644 ParticleGenerator/src/Interface/Scene/TrajectoryMulty.cpp create mode 100644 ParticleGenerator/src/Interface/Scene/TrajectoryMulty.hpp diff --git a/ParticleGenerator/res/config/imgui.ini b/ParticleGenerator/res/config/imgui.ini index 95c0d99..1e8440f 100644 --- a/ParticleGenerator/res/config/imgui.ini +++ b/ParticleGenerator/res/config/imgui.ini @@ -3,10 +3,10 @@ Pos=60,60 Size=400,400 [Window][Dear ImGui Demo] -Pos=1131,67 +Pos=1021,19 Size=550,680 [Window][Particle Generator] -Pos=65,78 -Size=455,596 +Pos=60,60 +Size=553,820 diff --git a/ParticleGenerator/res/shaders/scene/Trajectory.vert b/ParticleGenerator/res/shaders/scene/Trajectory.vert index 7435865..00d79b8 100644 --- a/ParticleGenerator/res/shaders/scene/Trajectory.vert +++ b/ParticleGenerator/res/shaders/scene/Trajectory.vert @@ -6,10 +6,11 @@ out vec3 zCol; uniform mat4 uProj; uniform mat4 uView; +uniform mat4 uModel; uniform float uPointSize; void main() { - gl_Position = uProj * uView * vec4(aPos, 1.0); + gl_Position = uProj * uView * uModel * vec4(aPos, 1.0); gl_PointSize = uPointSize; zCol = aCol; } \ No newline at end of file diff --git a/ParticleGenerator/res/textures/gray.png b/ParticleGenerator/res/textures/gray.png new file mode 100644 index 0000000000000000000000000000000000000000..9b9f364e0a2fb2ba238172b5dfa4613fea957c96 GIT binary patch literal 138 zcmeAS@N?(olHy`uVBq!ia0y~yU{C;I7G?$phQ^Te;|vT8jKx9jP7LeL$-HD>U|>mi z^mSxl*x1kgCy|wbfq^-|C&aa?s%o~(O(q5g2F?PH$YKTtzQZ8Qcszea3IhX!fTxRN mh{pM33D(67>In%93``0Pj2w^s?=dhiFnGH9xvX<aXaWG}>>ud> literal 0 HcmV?d00001 diff --git a/ParticleGenerator/src/Interface/Generator/PathMultyGenerator.cpp b/ParticleGenerator/src/Interface/Generator/PathMultyGenerator.cpp new file mode 100644 index 0000000..5b78d60 --- /dev/null +++ b/ParticleGenerator/src/Interface/Generator/PathMultyGenerator.cpp @@ -0,0 +1,87 @@ +#pragma once + +#include "PathMultyGenerator.hpp" + +#include <imgui.h> + +#include "../../Particle/generator/PathMultyGenerator.hpp" + +namespace pg::interface { + PathMultyGenerator::PathMultyGenerator(particle::PathMultyGenerator * parent, scene::TrajectoryMulty * trajectory) + : Generator(parent), + _trajectory(trajectory), + _next(0.f, 0.f, 0.f), + _index(0) {} + + void PathMultyGenerator::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); + ImGui::Text("Spacing : %f", this->parent()->m_spacing); + ImGui::Text("Life Limitor : %f", this->parent()->m_limitor); + + if(ImGui::CollapsingHeader("Generator Position")) { + ImGui::DragFloat3("Generator Position (x, y, z)", &this->parent()->m_position[0], 0.1f); + ImGui::SliderFloat3("Generator Roation (x, y, z)", &this->parent()->m_rotation[0], -360.f, 360.f); + ImGui::DragFloat("Position Variation", &this->parent()->m_positionVariation, 0.001f, 0.f, 0.f, "%.4f"); + } + + if(ImGui::CollapsingHeader("Parameter")) { + ImGui::InputFloat("Parameter Default Value", &this->parent()->m_u, 0.1f, 0.5f); + ImGui::DragFloat("Parameter Increment Value", &this->parent()->m_increment, 0.01f); + ImGui::DragFloat("Spacing", &this->parent()->m_spacing, 0.001f); + ImGui::InputFloat("Life Limitor", &this->parent()->m_limitor, 1.0f, 2.0f); + } + + if(ImGui::CollapsingHeader("Control Points")) { + for(size_t i = 0; i < this->parent()->m_controlPoints.size(); ++i) { + glm::vec3 current = static_cast<glm::vec3>(this->parent()->m_controlPoints[i]); + ImGui::Text("%i : %f / %f / %f.", i, current.x, current.y, current.z); + } + + ImGui::InputFloat3("", &this->_next[0]); + ImGui::InputInt("Index", &this->_index, 1, 2); + + if(this->_index < 0) { + ImGui::TextColored(ImVec4(0.75f, 0.f, 0.f, 1.f), "Negative index !"); + } + else { + if(this->_index > this->parent()->getControlPoint().size()) { + ImGui::TextColored(ImVec4(1.f, 1.f, 0.f, 1.f), "Index out of range, new point will be at the back !"); + } + + if(ImGui::Button("Push Point")) { + if(this->_index > this->parent()->getControlPoint().size()) { + this->parent()->m_controlPoints.push_back(static_cast<ct::Point>(this->_next)); + } + else { + this->parent()->m_controlPoints.insert(this->parent()->m_controlPoints.begin() + this->_index, static_cast<ct::Point>(this->_next)); + } + + if(this->_trajectory != nullptr) { + this->_trajectory->update(current_time); + } + } + + ImGui::SameLine(); + + if(ImGui::Button("Pop Point")) { + if(this->_index > this->parent()->getControlPoint().size()) { + this->parent()->m_controlPoints.pop_back(); + } + else { + this->parent()->m_controlPoints.erase(this->parent()->m_controlPoints.begin() + this->_index); + } + + if(this->_trajectory != nullptr) { + this->_trajectory->update(current_time); + } + } + } + }*/ + ImGui::Text("Path Multy Generator : %i", this->parent()); + if(this->_trajectory->interface().has_value()) { + (*this->_trajectory->interface())->draw(current_time); + } + } +} diff --git a/ParticleGenerator/src/Interface/Generator/PathMultyGenerator.hpp b/ParticleGenerator/src/Interface/Generator/PathMultyGenerator.hpp new file mode 100644 index 0000000..eaa79d9 --- /dev/null +++ b/ParticleGenerator/src/Interface/Generator/PathMultyGenerator.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include "../Interface.hpp" +#include "../../Scene/Scenes/TrajectoryMulty.hpp" + +#include <glm/vec3.hpp> + +namespace pg::particle { + class PathMultyGenerator; +} + +namespace pg::interface { + class PathMultyGenerator : public Generator<particle::PathMultyGenerator> { + private: + scene::TrajectoryMulty * _trajectory; + + glm::vec3 _next; + int _index; + + public: + PathMultyGenerator(particle::PathMultyGenerator *, scene::TrajectoryMulty * = nullptr); + virtual ~PathMultyGenerator() = default; + + void draw(double) override; + virtual inline std::string title() const {return "Path Generator Interface";} + }; +} \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Generator/PhysicGenerator.cpp b/ParticleGenerator/src/Interface/Generator/PhysicGenerator.cpp index 3f704e5..6fa7f4c 100644 --- a/ParticleGenerator/src/Interface/Generator/PhysicGenerator.cpp +++ b/ParticleGenerator/src/Interface/Generator/PhysicGenerator.cpp @@ -43,16 +43,18 @@ namespace pg::interface { if(ImGui::CollapsingHeader("Variation")) { ImGui::SeparatorText("Velocity"); - ImGui::DragFloat3("Upper Boundary (x, y, z)", &this->parent()->m_velocityVariation.upper[0], 0.0001f, 0.f, 0.f, "%.4f"); - ImGui::DragFloat3("Lower Boundary (x, y, z)", &this->parent()->m_velocityVariation.lower[0], 0.0001f, 0.f, 0.f, "%.4f"); + ImGui::DragFloatRange2("x", &this->parent()->m_velocityVariation.lower.x, &this->parent()->m_velocityVariation.upper.x, 0.0001f, 0.f, 0.f, "%.4f"); + ImGui::DragFloatRange2("y", &this->parent()->m_velocityVariation.lower.y, &this->parent()->m_velocityVariation.upper.y, 0.0001f, 0.f, 0.f, "%.4f"); + ImGui::DragFloatRange2("z", &this->parent()->m_velocityVariation.lower.z, &this->parent()->m_velocityVariation.upper.z, 0.0001f, 0.f, 0.f, "%.4f"); + ImGui::SeparatorText("Acceleration"); ImGui::PushID(1); - ImGui::DragFloat3("Upper Boundary (x, y, z)", &this->parent()->m_accelerationVariation.upper[0], 0.0001f, 0.f, 0.f, "%.4f"); - ImGui::DragFloat3("Lower Boundary (x, y, z)", &this->parent()->m_accelerationVariation.lower[0], 0.0001f, 0.f, 0.f, "%.4f"); + ImGui::DragFloatRange2("x", &this->parent()->m_accelerationVariation.lower.x, &this->parent()->m_accelerationVariation.upper.x, 0.0001f, 0.f, 0.f, "%.4f"); + ImGui::DragFloatRange2("y", &this->parent()->m_accelerationVariation.lower.y, &this->parent()->m_accelerationVariation.upper.y, 0.0001f, 0.f, 0.f, "%.4f"); + ImGui::DragFloatRange2("z", &this->parent()->m_accelerationVariation.lower.z, &this->parent()->m_accelerationVariation.upper.z, 0.0001f, 0.f, 0.f, "%.4f"); ImGui::PopID(); ImGui::SeparatorText("Friction"); - ImGui::DragFloat3("Variation", &this->parent()->m_frictionVariation[0], 0.0001f, 0.f, 0.f, "%.4f"); + ImGui::DragFloat3("x y z", &this->parent()->m_frictionVariation[0], 0.001f, 0.f, 0.f, "%.4f"); } - ImGui::Text("Physic Generator : %i", this->parent()); } } diff --git a/ParticleGenerator/src/Interface/Scene/MultyPath.cpp b/ParticleGenerator/src/Interface/Scene/MultyPath.cpp new file mode 100644 index 0000000..7da70e4 --- /dev/null +++ b/ParticleGenerator/src/Interface/Scene/MultyPath.cpp @@ -0,0 +1,39 @@ +#include "MultyPath.hpp" + +#include <imgui.h> + +#include "../../Scene/Scenes/MultyPath.hpp" +#include "../../tfd/tinyfiledialogs.h" + +namespace pg::interface { + MultyPath::MultyPath(scene::MultyPath * parent, particle::PathMultyGenerator * generator, scene::TrajectoryMulty * trajectory) + : Scene(parent), SceneParticle(parent), _interface(generator, trajectory) {} + + void MultyPath::draw(double current_time) { + SceneParticle::draw(current_time); + + /*ImGui::SeparatorText("Texture"); + + ImGui::Image((void*)(intptr_t)this->parent()->getTexture().identifier(), ImVec2(128, 128), ImVec2(0, 1), ImVec2(1, 0)); + if(ImGui::Button("Change Texture", ImVec2(128, 25))) { + char const * imagePatterns[1] = {"*.png"}; + std::string MultyPath = tinyfd_openFileDialog("Image Browser", "", 1, imagePatterns, "Image File", false); + this->parent()->changeParticletexture(MultyPath); + } + ImGui::SameLine(); + ImGui::ColorEdit4("Color", &this->parent()->_color[0]); + + ImGui::SeparatorText("Generator"); + + this->_interface.draw(current_time); + + ImGui::SeparatorText("Trajectory"); + + auto tinterface = this->parent()->_trajectory.interface(); + if(tinterface.has_value()) { + (*tinterface)->draw(current_time); + }*/ + + this->_interface.draw(current_time); + } +} \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Scene/MultyPath.hpp b/ParticleGenerator/src/Interface/Scene/MultyPath.hpp new file mode 100644 index 0000000..f7c3ba3 --- /dev/null +++ b/ParticleGenerator/src/Interface/Scene/MultyPath.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include "../Interface.hpp" +#include "SceneParticle.hpp" +#include "../Generator/PathMultyGenerator.hpp" +#include "../../Particle/generator/PathMultyGenerator.hpp" +#include "../../Scene/Scenes/TrajectoryMulty.hpp" + +#include <glm/vec4.hpp> + + +namespace pg::scene { + class MultyPath; +} + +namespace pg::interface { + class MultyPath : public Scene<scene::MultyPath>, public SceneParticle { + private: + PathMultyGenerator _interface; + + public: + MultyPath(scene::MultyPath *, particle::PathMultyGenerator *, pg::scene::TrajectoryMulty * = nullptr); + virtual ~MultyPath() = default; + + virtual void draw(double); + inline std::string title() const override final {return "Path Scene Interface";} + + }; +} \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Scene/Trajectory.cpp b/ParticleGenerator/src/Interface/Scene/Trajectory.cpp index 78e4fb4..5abf701 100644 --- a/ParticleGenerator/src/Interface/Scene/Trajectory.cpp +++ b/ParticleGenerator/src/Interface/Scene/Trajectory.cpp @@ -8,10 +8,22 @@ namespace pg::interface { Trajectory::Trajectory(scene::Trajectory * parent) : Scene(parent) {} - void Trajectory::draw(double) { + void Trajectory::draw(double current_time) { ImGui::ColorEdit4("Curve Color", &this->parent()->_color[0]); - ImGui::SliderFloat("Point Size", &this->parent()->_pointSize, 1.f, 512.f); - ImGui::SliderFloat("Line Size", &this->parent()->_lineSize, 1.f, 512.f); - ImGui::Checkbox("Show Control Line", &this->parent()->_controlLine); + ImGui::Checkbox("Enable Render", &this->parent()->_enableRender); + + ImGui::Separator(); + ImGui::Checkbox("Enable Control Line", &this->parent()->_controlLine); + ImGui::Checkbox("Enable Control Point", &this->parent()->_enableControl); + ImGui::Checkbox("Enable Curve Line", &this->parent()->_enableLine); + + ImGui::Separator(); + ImGui::SliderFloat("Point Size", &this->parent()->_pointSize, 1.f, 64.f); + ImGui::SliderFloat("Line Size", &this->parent()->_lineSize, 1.f, 10.f); + if(ImGui::InputDouble("Curve Precision", &this->parent()->_increment, 0.01, 0.1)) { + if(this->parent()->_increment > 0.0) { + this->parent()->update(current_time); + } + } } } \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Scene/TrajectoryMulty.cpp b/ParticleGenerator/src/Interface/Scene/TrajectoryMulty.cpp new file mode 100644 index 0000000..6b358a3 --- /dev/null +++ b/ParticleGenerator/src/Interface/Scene/TrajectoryMulty.cpp @@ -0,0 +1,40 @@ +#include "TrajectoryMulty.hpp" + +#include <imgui.h> + +#include "../../Scene/Scenes/TrajectoryMulty.hpp" + +namespace pg::interface { + TrajectoryMulty::TrajectoryMulty(scene::TrajectoryMulty * parent) + : Scene(parent) {} + + void TrajectoryMulty::draw(double current_time) { + /*ImGui::ColorEdit4("Curve Color", &this->parent()->_color[0]); + ImGui::Checkbox("Enable Render", &this->parent()->_enableRender); + + ImGui::Separator(); + ImGui::Checkbox("Enable Control Line", &this->parent()->_controlLine); + + ImGui::Separator(); + ImGui::SliderFloat("Point Size", &this->parent()->_pointSize, 1.f, 64.f); + ImGui::SliderFloat("Line Size", &this->parent()->_lineSize, 1.f, 10.f); + if(ImGui::InputDouble("Curve Precision", &this->parent()->_increment, 0.01, 0.1)) { + if(this->parent()->_increment > 0.0) { + this->parent()->update(current_time); + } + }*/ + + size_t color_nb = this->parent()->_colors.size(); + size_t i = 0; + for(auto &[name, generator] : this->parent()->_generators->getGenerators()) { + size_t index = i%color_nb; + ImGui::Text("%s : ", name.c_str()); + ImGui::SameLine(); + if(ImGui::ColorEdit4("", &this->parent()->_colors.at(index)[0])) { + this->parent()->update(current_time); + } + ++i; + } + ImGui::Text("Trajectory Multy : %i", this->parent()); + } +} \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Scene/TrajectoryMulty.hpp b/ParticleGenerator/src/Interface/Scene/TrajectoryMulty.hpp new file mode 100644 index 0000000..f5d2ce8 --- /dev/null +++ b/ParticleGenerator/src/Interface/Scene/TrajectoryMulty.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include "../Interface.hpp" + +namespace pg::scene { + class TrajectoryMulty; +} + +namespace pg::interface { + class TrajectoryMulty : public Scene<scene::TrajectoryMulty> { + public: + TrajectoryMulty(scene::TrajectoryMulty *); + + virtual void draw(double = 0.0); + inline std::string title() const override final {return "Trajectory Multy Interface";} + }; +} \ No newline at end of file diff --git a/ParticleGenerator/src/Particle/Particle.cpp b/ParticleGenerator/src/Particle/Particle.cpp index 344eb48..9a68156 100644 --- a/ParticleGenerator/src/Particle/Particle.cpp +++ b/ParticleGenerator/src/Particle/Particle.cpp @@ -7,5 +7,5 @@ namespace pg::particle { : Particle(0, position) {} Particle::Particle(size_t born, const ct::Point& position) - : m_position(position), m_born(born) {} + : m_born(born) {} } \ No newline at end of file diff --git a/ParticleGenerator/src/Particle/Particle.hpp b/ParticleGenerator/src/Particle/Particle.hpp index 54dce2f..439ce87 100644 --- a/ParticleGenerator/src/Particle/Particle.hpp +++ b/ParticleGenerator/src/Particle/Particle.hpp @@ -6,6 +6,7 @@ #include <CurveTools/CPU/CurveGenerator.hpp> #include <glm/mat4x4.hpp> +#include <glm/gtc/matrix_transform.hpp> namespace pg::particle { @@ -13,27 +14,25 @@ namespace pg::particle { private: size_t m_born; - ct::Point m_position; + glm::mat4 m_model; public: - glm::mat4 _model = glm::mat4(1.f); - Particle(const ct::Point& position = ct::Point()); Particle(size_t born, const ct::Point& position = ct::Point()); virtual ~Particle() = default; inline size_t getBorn() const {return this->m_born;} - inline ct::Point getPosition() const {return this->m_position;} + inline const glm::mat4 & getModel() const {return this->m_model;} inline bool isDead(size_t current_time, size_t max_time) const {return (current_time - this->m_born) > max_time;} inline void setBorn(size_t born) {this->m_born = born;} - inline void setPosition(const ct::Point& position) {this->m_position = position;} + inline void setModel(const glm::mat4 & model) {this->m_model = model;} - inline void translate(const ct::Point& position) {this->m_position += position;} + inline void translate(const ct::Point& position) {this->m_model = glm::translate(m_model, glm::vec3(position));} virtual void update(double = 0.0) = 0; - inline friend bool operator==(const Particle & p1, const Particle & p2) {return p1.m_position == p2.m_position && p1.m_born == p2.m_born;} + inline friend bool operator==(const Particle & p1, const Particle & p2) {return p1.m_model == p2.m_model && p1.m_born == p2.m_born;} inline friend bool operator!=(const Particle & p1, const Particle & p2) {return !(p1 == p2);} inline friend bool operator>(const Particle & p1, const Particle & p2) {return p1.m_born > p2.m_born;} diff --git a/ParticleGenerator/src/Particle/Path.cpp b/ParticleGenerator/src/Particle/Path.cpp index 35b714c..3f86e82 100644 --- a/ParticleGenerator/src/Particle/Path.cpp +++ b/ParticleGenerator/src/Particle/Path.cpp @@ -2,12 +2,15 @@ #include <iostream> +#include <glm/mat4x4.hpp> + 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()) { - this->setPosition(this->m_ctrlPoints.at(0)); + this->setModel(glm::mat4(1.f)); + this->translate(this->m_ctrlPoints.at(0)); } } @@ -26,6 +29,7 @@ namespace pg::particle { return; } - this->setPosition(this->m_generator->operator()(this->m_ctrlPoints, this->m_u) + this->m_positionVariation); + this->setModel(glm::mat4(1.f)); + this->translate(this->m_generator->generate(this->m_ctrlPoints, this->m_u) + this->m_positionVariation); } } diff --git a/ParticleGenerator/src/Particle/Physics.cpp b/ParticleGenerator/src/Particle/Physics.cpp index dd67108..253f948 100644 --- a/ParticleGenerator/src/Particle/Physics.cpp +++ b/ParticleGenerator/src/Particle/Physics.cpp @@ -12,8 +12,6 @@ namespace pg::particle { void Physics::update(double t) { m_acceleration -= static_cast<glm::dvec3>(m_friction) * m_velocity; m_velocity += m_acceleration; - - //this->translate(this->m_velocity); - this->_model = glm::translate(this->_model, glm::vec3(this->m_velocity)); + this->translate(this->m_velocity); } } \ No newline at end of file diff --git a/ParticleGenerator/src/Particle/generator/Generator.hpp b/ParticleGenerator/src/Particle/generator/Generator.hpp index 8f290d4..6416090 100644 --- a/ParticleGenerator/src/Particle/generator/Generator.hpp +++ b/ParticleGenerator/src/Particle/generator/Generator.hpp @@ -14,20 +14,28 @@ namespace pg::particle { float m_positionVariation; glm::vec3 m_position; glm::vec3 m_rotation; + glm::mat4 m_model; public: - glm::mat4 _model = glm::mat4(1.f); - Generator(const glm::vec3& position = glm::vec3(0.f), float positionVariation = 0.0) - : m_position(position), m_positionVariation(positionVariation), m_rotation(0.0) {} + : m_position(position), m_positionVariation(positionVariation), m_rotation(0.0), m_model(1.f) {} inline float getPositionVariation() const {return this->m_positionVariation;} inline glm::vec3 getPosition() const {return this->m_position;} inline glm::vec3 getRotation() const {return this->m_rotation;} + inline glm::mat4 getModel() const {return this->m_model;} inline void setPositionVariation(float positionVariation) {this->m_positionVariation = positionVariation;} inline void setPosition(const glm::vec3& position) {this->m_position = position;} inline void setRotation(const glm::vec3& rotation) {this->m_rotation = rotation;} + inline void setModel(const glm::mat4 & model) {this->m_model = model;} + + inline void translate(const glm::vec3 & position) {this->m_model = glm::translate(this->m_model, position);} + inline void rotate(const glm::vec3 & rotation) { + this->m_model = glm::rotate(this->m_model, glm::radians(rotation.z), {0.f, 0.f, 1.f}); + this->m_model = glm::rotate(this->m_model, glm::radians(rotation.y), {0.f, 1.f, 0.f}); + this->m_model = glm::rotate(this->m_model, glm::radians(rotation.x), {1.f, 0.f, 0.f}); + } 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);} diff --git a/ParticleGenerator/src/Particle/generator/PhysicsGenerator.cpp b/ParticleGenerator/src/Particle/generator/PhysicsGenerator.cpp index 6c39ba5..dd5c4fd 100644 --- a/ParticleGenerator/src/Particle/generator/PhysicsGenerator.cpp +++ b/ParticleGenerator/src/Particle/generator/PhysicsGenerator.cpp @@ -45,8 +45,6 @@ namespace pg::particle for (size_t i = 0; i < count; ++i) { Physics * particle = new Physics(birth, this->getPosition()); - //particle->translate({p(randomEngine), p(randomEngine), p(randomEngine)}); - glm::vec3 velocityVariation = {vx(randomEngine), vy(randomEngine), vz(randomEngine)}; glm::vec3 accelerationVariation = {ax(randomEngine), ay(randomEngine), az(randomEngine)}; glm::vec3 frictionVariation = {fx(randomEngine), fy(randomEngine), fz(randomEngine)}; @@ -71,8 +69,8 @@ namespace pg::particle particle->setAcceleration(realAcceleration); particle->setFriction(realFriction); - particle->_model = this->_model; - particle->_model = glm::translate(particle->_model, {p(randomEngine), p(randomEngine), p(randomEngine)}); + particle->setModel(this->getModel()); + particle->translate(this->m_position + glm::vec3(p(randomEngine), p(randomEngine), p(randomEngine))); particles.push_back(std::unique_ptr<Physics>(particle)); } diff --git a/ParticleGenerator/src/Scene/Scenes/MeshGenerator.cpp b/ParticleGenerator/src/Scene/Scenes/MeshGenerator.cpp index a01bf05..649122b 100644 --- a/ParticleGenerator/src/Scene/Scenes/MeshGenerator.cpp +++ b/ParticleGenerator/src/Scene/Scenes/MeshGenerator.cpp @@ -124,10 +124,8 @@ namespace pg::scene { while(particle_accumulator < this->_particles.size()) { std::vector<glm::mat4> models; for(size_t i = 0; i < this->_particles.size() && i < 1024; i++) { - //glm::mat4 model = glm::mat4(1.0); if(i + particle_accumulator < this->_particles.size()) { - //model = glm::translate(model, glm::vec3(this->_particles[particle_accumulator + i]->getPosition())); - models.push_back(this->_particles[particle_accumulator + i]->_model); + models.push_back(this->_particles[particle_accumulator + i]->getModel()); } } @@ -192,16 +190,9 @@ namespace pg::scene { void MeshGenerator::spawn(int count, double current_time) { for(auto & generator : this->_generators) { - //? ##### - generator._model = glm::mat4(1.f); - - generator._model = glm::rotate(generator._model, glm::radians(this->_meshRotation.z), {0.f, 0.f, 1.f}); - generator._model = glm::rotate(generator._model, glm::radians(this->_meshRotation.y), {0.f, 1.f, 0.f}); - generator._model = glm::rotate(generator._model, glm::radians(this->_meshRotation.x), {1.f, 0.f, 0.f}); - - generator._model = glm::translate(generator._model, generator.getPosition() + this->_meshPosition); - //? ##### - + generator.setModel(glm::mat4(1.f)); + generator.rotate(this->_meshRotation); + generator.translate(generator.getPosition() + this->_meshPosition); if((count + this->_particles.size()) <= this->getMaxParticles()) { std::vector<std::unique_ptr<particle::Physics>> newParticles = generator.generate(count, static_cast<size_t>(current_time)); diff --git a/ParticleGenerator/src/Scene/Scenes/MeshGeneratorModel.cpp b/ParticleGenerator/src/Scene/Scenes/MeshGeneratorModel.cpp index a3ed710..d3db9ab 100644 --- a/ParticleGenerator/src/Scene/Scenes/MeshGeneratorModel.cpp +++ b/ParticleGenerator/src/Scene/Scenes/MeshGeneratorModel.cpp @@ -42,7 +42,7 @@ namespace pg::scene { frag.release(); } - this->_meshParticleTexture.load("res/textures/smoke1.png"); + this->_meshParticleTexture.load("res/textures/gray.png"); if(!this->_meshParticleProgram.usable()) { Source vert("res/shaders/scene/Texture-Fat.vert", Source::Categorie::VERTEX); @@ -95,6 +95,7 @@ namespace pg::scene { } void MeshGeneratorModel::render(const Camera & camera, double current_time) { + glEnable(GL_DEPTH_TEST); const glm::mat4 VIEW_MATRIX = camera.getViewMatrix(); const glm::mat4 PROJECTION_MATRIX = camera.getViewFrustum().getProjectionMatrix(); @@ -120,10 +121,8 @@ namespace pg::scene { while(particle_accumulator < this->_particles.size()) { std::vector<glm::mat4> models; for(size_t i = 0; i < this->_particles.size() && i < 1024; i++) { - glm::mat4 model = glm::mat4(1.0); if(i + particle_accumulator < this->_particles.size()) { - model = glm::translate(model, glm::vec3(this->_particles[particle_accumulator + i]->getPosition())); - models.push_back(model); + models.push_back(this->_particles[particle_accumulator + i]->getModel()); } } @@ -151,7 +150,7 @@ namespace pg::scene { particle_accumulator += 1024; } - // -------- + glDisable(GL_DEPTH_TEST); } void MeshGeneratorModel::destroy() { @@ -193,6 +192,10 @@ namespace pg::scene { void MeshGeneratorModel::spawn(int count, double current_time) { for(auto & generator : this->_generators) { + generator.setModel(glm::mat4(1.f)); + generator.rotate(this->_meshRotation); + generator.translate(generator.getPosition() + this->_meshPosition); + if((count + this->_particles.size()) <= this->getMaxParticles()) { 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/MultyPath.cpp b/ParticleGenerator/src/Scene/Scenes/MultyPath.cpp index a924f2c..63cb5e1 100644 --- a/ParticleGenerator/src/Scene/Scenes/MultyPath.cpp +++ b/ParticleGenerator/src/Scene/Scenes/MultyPath.cpp @@ -14,7 +14,8 @@ namespace pg::scene { _program(), _texture(), _generator(ctrlpoint), - _trajectory(&this->_generator) { + _trajectory(&this->_generator), + _interface(this, &this->_generator, &this->_trajectory) { this->_generator.add("Bezier", new ct::BezierGenerator()); this->_generator.add("Catmull-Rom", new ct::CatmullRomGenerator()); this->_generator.add("Linear", new ct::LinearGenerator()); @@ -92,9 +93,7 @@ namespace pg::scene { 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); + models.push_back(particle->getModel()); } pg::error::OpenGLError::check(); diff --git a/ParticleGenerator/src/Scene/Scenes/MultyPath.hpp b/ParticleGenerator/src/Scene/Scenes/MultyPath.hpp index 3579342..7dd1d93 100644 --- a/ParticleGenerator/src/Scene/Scenes/MultyPath.hpp +++ b/ParticleGenerator/src/Scene/Scenes/MultyPath.hpp @@ -7,6 +7,8 @@ #include "../../Mesh/Billboard.hpp" #include "TrajectoryMulty.hpp" +#include "../../Interface/Scene/MultyPath.hpp" + namespace pg::scene { class MultyPath : public SceneParticle { private: @@ -17,6 +19,8 @@ namespace pg::scene { Material _texture; particle::PathMultyGenerator _generator; + interface::MultyPath _interface; + public: MultyPath(const ct::Curve &); virtual ~MultyPath() = default; @@ -33,6 +37,7 @@ namespace pg::scene { void changeParticletexture(const std::string &); virtual std::string name() const {return "Multy Path Scene";} + virtual std::optional<interface::Interface *> interface() {return std::optional<interface::Interface *>(&this->_interface);} virtual void spawn(int, double); }; diff --git a/ParticleGenerator/src/Scene/Scenes/Path.cpp b/ParticleGenerator/src/Scene/Scenes/Path.cpp index c16a957..26d7798 100644 --- a/ParticleGenerator/src/Scene/Scenes/Path.cpp +++ b/ParticleGenerator/src/Scene/Scenes/Path.cpp @@ -85,9 +85,7 @@ namespace pg::scene { 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); + models.push_back(particle->getModel()); } pg::error::OpenGLError::check(); @@ -127,6 +125,16 @@ namespace pg::scene { } void Path::spawn(int count, double current_time) { + //this->_generator._model = glm::mat4(1.f); + //this->_generator._model = glm::rotate(this->_generator._model, glm::radians(this->_generator.getRotation().z), {0.f, 0.f, 1.f}); + //this->_generator._model = glm::rotate(this->_generator._model, glm::radians(this->_generator.getRotation().y), {0.f, 1.f, 0.f}); + //this->_generator._model = glm::rotate(this->_generator._model, glm::radians(this->_generator.getRotation().x), {1.f, 0.f, 0.f}); + //this->_generator._model = glm::translate(this->_generator._model, this->_generator.getPosition()); + + this->_generator.setModel(glm::mat4(1.f)); + this->_generator.rotate(this->_generator.getRotation()); + this->_generator.translate(this->_generator.getPosition()); + 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())); diff --git a/ParticleGenerator/src/Scene/Scenes/Physic.cpp b/ParticleGenerator/src/Scene/Scenes/Physic.cpp index 9e08faa..132bfb3 100644 --- a/ParticleGenerator/src/Scene/Scenes/Physic.cpp +++ b/ParticleGenerator/src/Scene/Scenes/Physic.cpp @@ -79,9 +79,7 @@ namespace pg::scene { 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); + models.push_back(particle->getModel()); } pg::error::OpenGLError::check(); diff --git a/ParticleGenerator/src/Scene/Scenes/PhysicSprite.cpp b/ParticleGenerator/src/Scene/Scenes/PhysicSprite.cpp index c97ca9b..dfb35fd 100644 --- a/ParticleGenerator/src/Scene/Scenes/PhysicSprite.cpp +++ b/ParticleGenerator/src/Scene/Scenes/PhysicSprite.cpp @@ -86,10 +86,7 @@ namespace pg::scene { size_t i = 0; for(auto & particle : this->_particles) { - glm::mat4 model = glm::mat4(1.0); - model = glm::translate(model, glm::vec3(particle->getPosition())); - models.push_back(model); - + models.push_back(particle->getModel()); slots.push_back(this->_frames.at(static_cast<int>(current_time-particle->getBorn())%this->_frames.size())); } diff --git a/ParticleGenerator/src/Scene/Scenes/Trajectory.cpp b/ParticleGenerator/src/Scene/Scenes/Trajectory.cpp index 722ae7d..cdfcbd7 100644 --- a/ParticleGenerator/src/Scene/Scenes/Trajectory.cpp +++ b/ParticleGenerator/src/Scene/Scenes/Trajectory.cpp @@ -12,6 +12,9 @@ namespace pg::scene { _pointSize(8.f), _lineSize(1.f), _controlLine(false), + _enableControl(true), + _enableLine(true), + _enableRender(true), _interface(this) {} void Trajectory::initialize() { @@ -63,22 +66,31 @@ namespace pg::scene { } void Trajectory::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", this->_color); - this->_program.setUniform("uPointSize", this->_pointSize); - - GLsizei raw = static_cast<GLsizei>(this->_generator->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->_generator->getControlPoint().size())); + if(this->_enableRender) { + 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("uModel", this->_generator->getModel()); + this->_program.setUniform("uColor", this->_color); + this->_program.setUniform("uPointSize", this->_pointSize); + + + GLsizei raw = static_cast<GLsizei>(this->_generator->getControlPoint().size()); + GLsizei total = static_cast<GLsizei>(this->_vbo.vertices()); + + if(this->_enableLine) { + glDrawArrays(GL_LINE_STRIP, raw, total - raw); + } + + if(this->_enableControl) { + glDrawArrays(this->_controlLine ? GL_LINE_STRIP : GL_POINTS, 0, static_cast<GLsizei>(this->_generator->getControlPoint().size())); + } + } } void Trajectory::destroy() { diff --git a/ParticleGenerator/src/Scene/Scenes/Trajectory.hpp b/ParticleGenerator/src/Scene/Scenes/Trajectory.hpp index 8e1537e..fa846c8 100644 --- a/ParticleGenerator/src/Scene/Scenes/Trajectory.hpp +++ b/ParticleGenerator/src/Scene/Scenes/Trajectory.hpp @@ -18,17 +18,21 @@ namespace pg::scene { float _pointSize; float _lineSize; bool _controlLine; + bool _enableControl; + bool _enableLine; + bool _enableRender; interface::Trajectory _interface; public: - Trajectory(particle::PathUniqueGenerator *, double = 0.01f); + Trajectory(particle::PathUniqueGenerator *, double = 0.1f); inline particle::PathUniqueGenerator * 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;} inline bool isConrolLineEnable() const {return this->_controlLine;} + inline bool isRenderingEnable() const {return this->_enableRender;} void initialize(); void render(const Camera &, double); diff --git a/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.cpp b/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.cpp index c4b13b1..6118211 100644 --- a/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.cpp +++ b/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.cpp @@ -9,7 +9,9 @@ namespace pg::scene { _increment(increment), _pointSize(8.f), _lineSize(1.f), - _controlLine(false) {} + _controlLine(false), + _enableRender(true), + _interface(this) {} void TrajectoryMulty::initialize() { this->update(0.0); @@ -57,7 +59,7 @@ namespace pg::scene { size_t i = 0; for(auto &[name, generator] : this->_generators->getGenerators()) { ct::Curve curve = generator->generate(this->_generators->getControlPoint(), ps); - + size_t j = 0; size_t index = i%color_nb; for(auto & point : curve) { traj.push_back(static_cast<float>(point.x)); @@ -66,33 +68,46 @@ namespace pg::scene { traj.push_back(this->_colors.at(index).r); traj.push_back(this->_colors.at(index).g); - traj.push_back(this->_colors.at(index).b); + traj.push_back(this->_colors.at(index).b); + + if(j != 0 && j != ps.size()-1) { + 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); + } + ++j; } ++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())); - } + if(this->_enableRender) { + 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("uModel", glm::mat4(1.f)); + 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_LINES, raw, total - raw); + glDrawArrays(this->_controlLine ? GL_LINE_STRIP : GL_POINTS, 0, static_cast<GLsizei>(this->_generators->getControlPoint().size())); + } + } void TrajectoryMulty::destroy() { diff --git a/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.hpp b/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.hpp index 0d65a9e..b371627 100644 --- a/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.hpp +++ b/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.hpp @@ -7,6 +7,8 @@ #include "../../Renderer/Renderer.hpp" #include "../../Particle/generator/PathMultyGenerator.hpp" +#include "../../Interface/Scene/TrajectoryMulty.hpp" + namespace pg::scene { class TrajectoryMulty : public Scene { private: @@ -20,14 +22,20 @@ namespace pg::scene { float _pointSize; float _lineSize; bool _controlLine; + bool _enableRender; + + interface::TrajectoryMulty _interface; 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}}); + 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, 0.f, 1.f, 1.f}}); void initialize(); void render(const Camera &, double); void update(double); void destroy(); + virtual std::optional<interface::Interface *> interface() {return std::optional<interface::Interface *>(&this->_interface);} + + friend class interface::TrajectoryMulty; }; } \ No newline at end of file -- GitLab