From e6c5bf442c11f189e7e0c73f541e9b34228c9006 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 21:41:11 +0200 Subject: [PATCH] Add interface for multy path scene --- ParticleGenerator/res/config/imgui.ini | 6 +-- .../src/Interface/Generator/PathGenerator.hpp | 2 +- .../Generator/PathMultyGenerator.cpp | 6 +-- .../Generator/PathMultyGenerator.hpp | 2 +- .../src/Interface/Scene/MultyPath.cpp | 15 ++------ .../src/Interface/Scene/TrajectoryMulty.cpp | 38 +++++++++++-------- .../src/Particle/generator/PathGenerator.hpp | 4 ++ .../Particle/generator/PathMultyGenerator.hpp | 6 +++ .../src/Scene/Scenes/MultyPath.cpp | 3 +- .../src/Scene/Scenes/MultyPath.hpp | 3 ++ .../src/Scene/Scenes/TrajectoryMulty.cpp | 11 +++++- .../src/Scene/Scenes/TrajectoryMulty.hpp | 3 ++ 12 files changed, 60 insertions(+), 39 deletions(-) diff --git a/ParticleGenerator/res/config/imgui.ini b/ParticleGenerator/res/config/imgui.ini index 1e8440f..2689187 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=1021,19 +Pos=1032,14 Size=550,680 [Window][Particle Generator] -Pos=60,60 -Size=553,820 +Pos=-1,11 +Size=823,650 diff --git a/ParticleGenerator/src/Interface/Generator/PathGenerator.hpp b/ParticleGenerator/src/Interface/Generator/PathGenerator.hpp index 01c6f58..dc19281 100644 --- a/ParticleGenerator/src/Interface/Generator/PathGenerator.hpp +++ b/ParticleGenerator/src/Interface/Generator/PathGenerator.hpp @@ -10,7 +10,7 @@ namespace pg::particle { } namespace pg::interface { - class PathGenerator : public Generator<particle::PathGenerator> { + class PathGenerator : virtual public Generator<particle::PathGenerator> { private: scene::Trajectory * _trajectory; diff --git a/ParticleGenerator/src/Interface/Generator/PathMultyGenerator.cpp b/ParticleGenerator/src/Interface/Generator/PathMultyGenerator.cpp index 5b78d60..ecebe17 100644 --- a/ParticleGenerator/src/Interface/Generator/PathMultyGenerator.cpp +++ b/ParticleGenerator/src/Interface/Generator/PathMultyGenerator.cpp @@ -14,7 +14,7 @@ namespace pg::interface { _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("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); @@ -78,8 +78,8 @@ namespace pg::interface { } } } - }*/ - ImGui::Text("Path Multy Generator : %i", this->parent()); + } + ImGui::SeparatorText("Trajectory"); 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 index eaa79d9..b0a29ab 100644 --- a/ParticleGenerator/src/Interface/Generator/PathMultyGenerator.hpp +++ b/ParticleGenerator/src/Interface/Generator/PathMultyGenerator.hpp @@ -10,7 +10,7 @@ namespace pg::particle { } namespace pg::interface { - class PathMultyGenerator : public Generator<particle::PathMultyGenerator> { + class PathMultyGenerator : virtual public Generator<particle::PathMultyGenerator> { private: scene::TrajectoryMulty * _trajectory; diff --git a/ParticleGenerator/src/Interface/Scene/MultyPath.cpp b/ParticleGenerator/src/Interface/Scene/MultyPath.cpp index 7da70e4..13ec321 100644 --- a/ParticleGenerator/src/Interface/Scene/MultyPath.cpp +++ b/ParticleGenerator/src/Interface/Scene/MultyPath.cpp @@ -12,13 +12,13 @@ namespace pg::interface { void MultyPath::draw(double current_time) { SceneParticle::draw(current_time); - /*ImGui::SeparatorText("Texture"); + 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); + std::string path = tinyfd_openFileDialog("Image Browser", "", 1, imagePatterns, "Image File", false); + this->parent()->changeParticletexture(path); } ImGui::SameLine(); ImGui::ColorEdit4("Color", &this->parent()->_color[0]); @@ -26,14 +26,5 @@ namespace pg::interface { 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/TrajectoryMulty.cpp b/ParticleGenerator/src/Interface/Scene/TrajectoryMulty.cpp index 6b358a3..523ee43 100644 --- a/ParticleGenerator/src/Interface/Scene/TrajectoryMulty.cpp +++ b/ParticleGenerator/src/Interface/Scene/TrajectoryMulty.cpp @@ -9,32 +9,38 @@ namespace pg::interface { : 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); - } - }*/ + ImGui::Checkbox("Enable Control Point", &this->parent()->_enableControl); + ImGui::Checkbox("Enable Curve Line", &this->parent()->_enableLine); + ImGui::Separator(); size_t color_nb = this->parent()->_colors.size(); size_t i = 0; + ImGui::Columns(2); for(auto &[name, generator] : this->parent()->_generators->getGenerators()) { - size_t index = i%color_nb; - ImGui::Text("%s : ", name.c_str()); - ImGui::SameLine(); + ImGui::Text("%s", name.c_str()); + } + + ImGui::NextColumn(); + + for(auto &[name, generator] : this->parent()->_generators->getGenerators()) { + size_t index = i%color_nb; if(ImGui::ColorEdit4("", &this->parent()->_colors.at(index)[0])) { this->parent()->update(current_time); } ++i; } - ImGui::Text("Trajectory Multy : %i", this->parent()); + + ImGui::Columns(); + + 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/Particle/generator/PathGenerator.hpp b/ParticleGenerator/src/Particle/generator/PathGenerator.hpp index 80dcadc..a34f968 100644 --- a/ParticleGenerator/src/Particle/generator/PathGenerator.hpp +++ b/ParticleGenerator/src/Particle/generator/PathGenerator.hpp @@ -5,6 +5,8 @@ namespace pg::interface { class PathGenerator; + class PathMultyGenerator; + class PathUniqueGenerator; } namespace pg::particle { @@ -28,5 +30,7 @@ namespace pg::particle { inline void setParameterLifeLimitor(float limitor) {this->m_limitor = limitor;} friend class pg::interface::PathGenerator; + friend class pg::interface::PathMultyGenerator; + friend class pg::interface::PathUniqueGenerator; }; } \ No newline at end of file diff --git a/ParticleGenerator/src/Particle/generator/PathMultyGenerator.hpp b/ParticleGenerator/src/Particle/generator/PathMultyGenerator.hpp index 52001c5..326d698 100644 --- a/ParticleGenerator/src/Particle/generator/PathMultyGenerator.hpp +++ b/ParticleGenerator/src/Particle/generator/PathMultyGenerator.hpp @@ -6,6 +6,10 @@ #include <map> #include <memory> +namespace pg::interface { + class PathMultyGenerator; +}; + namespace pg::particle { class PathMultyGenerator : public PathGenerator { private: @@ -19,5 +23,7 @@ namespace pg::particle { 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; + + friend class pg::interface::PathMultyGenerator; }; } \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scenes/MultyPath.cpp b/ParticleGenerator/src/Scene/Scenes/MultyPath.cpp index 63cb5e1..cc920a0 100644 --- a/ParticleGenerator/src/Scene/Scenes/MultyPath.cpp +++ b/ParticleGenerator/src/Scene/Scenes/MultyPath.cpp @@ -15,6 +15,7 @@ namespace pg::scene { _texture(), _generator(ctrlpoint), _trajectory(&this->_generator), + _color(1.f), _interface(this, &this->_generator, &this->_trajectory) { this->_generator.add("Bezier", new ct::BezierGenerator()); this->_generator.add("Catmull-Rom", new ct::CatmullRomGenerator()); @@ -108,7 +109,7 @@ namespace pg::scene { 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)); + this->_program.setUniform("uColor", this->_color); pg::error::OpenGLError::check(); diff --git a/ParticleGenerator/src/Scene/Scenes/MultyPath.hpp b/ParticleGenerator/src/Scene/Scenes/MultyPath.hpp index 7dd1d93..37ec50d 100644 --- a/ParticleGenerator/src/Scene/Scenes/MultyPath.hpp +++ b/ParticleGenerator/src/Scene/Scenes/MultyPath.hpp @@ -18,6 +18,7 @@ namespace pg::scene { TrajectoryMulty _trajectory; Material _texture; particle::PathMultyGenerator _generator; + glm::vec4 _color; interface::MultyPath _interface; @@ -40,5 +41,7 @@ namespace pg::scene { virtual std::optional<interface::Interface *> interface() {return std::optional<interface::Interface *>(&this->_interface);} virtual void spawn(int, double); + + friend class interface::MultyPath; }; } \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.cpp b/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.cpp index 6118211..1fcba54 100644 --- a/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.cpp +++ b/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.cpp @@ -10,6 +10,8 @@ namespace pg::scene { _pointSize(8.f), _lineSize(1.f), _controlLine(false), + _enableControl(true), + _enableLine(true), _enableRender(true), _interface(this) {} @@ -104,8 +106,13 @@ namespace pg::scene { 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())); + if(this->_enableLine) { + glDrawArrays(GL_LINES, raw, total - raw); + } + + if(this->_enableControl) { + glDrawArrays(this->_controlLine ? GL_LINE_STRIP : GL_POINTS, 0, static_cast<GLsizei>(this->_generators->getControlPoint().size())); + } } } diff --git a/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.hpp b/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.hpp index b371627..0c02470 100644 --- a/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.hpp +++ b/ParticleGenerator/src/Scene/Scenes/TrajectoryMulty.hpp @@ -22,7 +22,10 @@ namespace pg::scene { float _pointSize; float _lineSize; bool _controlLine; + bool _enableControl; + bool _enableLine; bool _enableRender; + interface::TrajectoryMulty _interface; -- GitLab