diff --git a/ParticleGenerator/old/Global.cpp.old b/ParticleGenerator/old/Global.cpp.old deleted file mode 100644 index c18e4c4f63ff10cb97793d2db13e1796d43af13c..0000000000000000000000000000000000000000 --- a/ParticleGenerator/old/Global.cpp.old +++ /dev/null @@ -1,58 +0,0 @@ -#include "Global.hpp" - -#include <imgui.h> -#include <imgui_impl_glfw.h> -#include <imgui_impl_opengl3.h> - -#include "../Scene/Manager.hpp" - -namespace pg::interface { - Global::Global(Window & window, Manager & manager, const std::string & title) - : _title(title), _manager(manager), _historical() { - if(this->_title.empty()) { - this->_title = window.title(); - } - - ImGui::CreateContext(); - ImGui::GetIO().IniFilename = "config/imgui.ini"; - - ImGui_ImplGlfw_InitForOpenGL(window.address(), true); - ImGui_ImplOpenGL3_Init("#version 330 core"); - } - - Global::~Global() { - ImGui::GetIO().IniFilename = ""; - - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImGui::DestroyContext(); - } - - void Global::render(double current_time) { - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); - - this->_historical.count(current_time); - - if(ImGui::Begin(this->_title.c_str())) { - if(ImGui::BeginTabBar("")) { - if(ImGui::BeginTabItem("Scene")) { - //this->_manager.interface().render(current_time); - ImGui::EndTabItem(); - } - - if(ImGui::BeginTabItem("Performance")) { - this->_historical.render(current_time); - ImGui::EndTabItem(); - } - ImGui::EndTabBar(); - - } - ImGui::End(); - } - - ImGui::Render(); - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - } -} \ No newline at end of file diff --git a/ParticleGenerator/old/Global.hpp.old b/ParticleGenerator/old/Global.hpp.old deleted file mode 100644 index 3460f4216f387a690251ec885da3954b1e4a0554..0000000000000000000000000000000000000000 --- a/ParticleGenerator/old/Global.hpp.old +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "Interface.hpp" - -#include "../Scene/Manager.hpp" -#include "../System/Window.hpp" -#include "../System/FrameHistorical.hpp" - -namespace pg::interface { - class Global : public Interface { - private: - std::string _title; - - Manager & _manager; - FrameHistorical _historical; - - public: - Global(Window &, Manager &, const std::string & = ""); - ~Global(); - - virtual void render(double); - inline std::string title() const {return "Global Interface";} - }; -} \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scenes/Mesh.cpp b/ParticleGenerator/old/Mesh.cpp similarity index 100% rename from ParticleGenerator/src/Scene/Scenes/Mesh.cpp rename to ParticleGenerator/old/Mesh.cpp diff --git a/ParticleGenerator/src/Scene/Scenes/Mesh.hpp b/ParticleGenerator/old/Mesh.hpp similarity index 100% rename from ParticleGenerator/src/Scene/Scenes/Mesh.hpp rename to ParticleGenerator/old/Mesh.hpp diff --git a/ParticleGenerator/src/Interface/Scene/MeshScene.cpp b/ParticleGenerator/old/MeshScene.cpp similarity index 100% rename from ParticleGenerator/src/Interface/Scene/MeshScene.cpp rename to ParticleGenerator/old/MeshScene.cpp diff --git a/ParticleGenerator/src/Interface/Scene/MeshScene.hpp b/ParticleGenerator/old/MeshScene.hpp similarity index 97% rename from ParticleGenerator/src/Interface/Scene/MeshScene.hpp rename to ParticleGenerator/old/MeshScene.hpp index 7613ade336fb1df51a2e08ef5b1e8aa355f9f005..7725b1c9cb29b71e7e33804a79c10d4765fc2fd8 100644 --- a/ParticleGenerator/src/Interface/Scene/MeshScene.hpp +++ b/ParticleGenerator/old/MeshScene.hpp @@ -11,7 +11,7 @@ namespace pg::scene { } namespace pg::interface { - class MeshScene : public Interface { + class MeshScene : public { private: scene::Mesh * _scene; Interface * _current; diff --git a/ParticleGenerator/old/SceneManager.cpp.old b/ParticleGenerator/old/SceneManager.cpp.old deleted file mode 100644 index b458f0fa0c7eaffa33c411ec3bd1a4862416a169..0000000000000000000000000000000000000000 --- a/ParticleGenerator/old/SceneManager.cpp.old +++ /dev/null @@ -1,31 +0,0 @@ -#include "SceneManager.hpp" - -#include <imgui.h> - -#include "../Scene/Manager.hpp" - -namespace pg::interface { - SceneManager::SceneManager(Manager * manager) - : _manager(manager) {} - - void SceneManager::render(double current_time) { - if(!this->_manager->scenes().empty()) { - std::string name = this->_manager->current() == nullptr ? this->_manager->scenes().front()->name() : this->_manager->current()->name(); - if(ImGui::BeginCombo("Current Scene", name.c_str())) { - for(auto & scene : this->_manager->_scenes) { - bool is_selected = (scene == this->_manager->current()); - if(ImGui::Selectable(scene->name().c_str(), is_selected)) { - this->_manager->changeScene(*scene); - } - } - ImGui::EndCombo(); - } - ImGui::Separator(); - } - - scene::Scene * current = this->_manager->current(); - if(current != nullptr && current->interface() != nullptr) { - current->interface()->render(current_time); - } - } -} \ No newline at end of file diff --git a/ParticleGenerator/old/SceneManager.hpp.old b/ParticleGenerator/old/SceneManager.hpp.old deleted file mode 100644 index 74afd686a1dbf488977438befd4958c4c13db107..0000000000000000000000000000000000000000 --- a/ParticleGenerator/old/SceneManager.hpp.old +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "Interface.hpp" - -namespace pg { - class Manager; -} - -namespace pg::interface { - class SceneManager : public Interface { - private: - Manager * _manager; - - public: - SceneManager(Manager *); - - virtual void render(double = 0.0); - inline std::string title() const {return "Scene Manager Interface";} - }; -} \ No newline at end of file diff --git a/ParticleGenerator/res/config/imgui.ini b/ParticleGenerator/res/config/imgui.ini index 18995efe87ec47f0e8d5646debd4463175ab3d00..d77fdd2fdb04df3ca2151c685f2be3249fbb6f12 100644 --- a/ParticleGenerator/res/config/imgui.ini +++ b/ParticleGenerator/res/config/imgui.ini @@ -3,6 +3,6 @@ Pos=60,60 Size=400,400 [Window][Particle Generator] -Pos=83,81 -Size=864,632 +Pos=60,60 +Size=533,291 diff --git a/ParticleGenerator/res/shaders/system/Trajectory.frag b/ParticleGenerator/res/shaders/scene/Trajectory.frag similarity index 52% rename from ParticleGenerator/res/shaders/system/Trajectory.frag rename to ParticleGenerator/res/shaders/scene/Trajectory.frag index ea75c60148635aa319922bded8144a2f01c31670..645ebad270181c44a274d6f6f3066f81e713537e 100644 --- a/ParticleGenerator/res/shaders/system/Trajectory.frag +++ b/ParticleGenerator/res/shaders/scene/Trajectory.frag @@ -3,6 +3,8 @@ out vec4 FragColor; in vec3 zCol; +uniform vec4 uColor; + void main() { - FragColor = vec4(zCol, 1.0); + FragColor = vec4(zCol, 1.0) * uColor; } \ No newline at end of file diff --git a/ParticleGenerator/res/shaders/system/Trajectory.vert b/ParticleGenerator/res/shaders/scene/Trajectory.vert similarity index 80% rename from ParticleGenerator/res/shaders/system/Trajectory.vert rename to ParticleGenerator/res/shaders/scene/Trajectory.vert index d8aa6a99e53e9ae8ac32d80c77d567a88570186d..74358655b122580d97bb52c25d191858148aace2 100644 --- a/ParticleGenerator/res/shaders/system/Trajectory.vert +++ b/ParticleGenerator/res/shaders/scene/Trajectory.vert @@ -6,9 +6,10 @@ out vec3 zCol; uniform mat4 uProj; uniform mat4 uView; +uniform float uPointSize; void main() { gl_Position = uProj * uView * vec4(aPos, 1.0); - gl_PointSize = 8.0; + gl_PointSize = uPointSize; zCol = aCol; } \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Generator/PathGenerator.cpp b/ParticleGenerator/src/Interface/Generator/PathGenerator.cpp index f8f5d81ddfaad5301095dc8ed078373b9c7fb9a4..7b542eca33928fe23174c9efb7bb55bab275b8ef 100644 --- a/ParticleGenerator/src/Interface/Generator/PathGenerator.cpp +++ b/ParticleGenerator/src/Interface/Generator/PathGenerator.cpp @@ -7,11 +7,14 @@ #include "../../Particle/generator/PathParticleGenerator.hpp" namespace pg::interface { - PathGenerator::PathGenerator(PathParticleGenerator * generator, Trajectory * trajectory) - : _generator(generator), _trajectory(trajectory), _next(0.f, 0.f, 0.f), _index(0) {} + PathGenerator::PathGenerator(PathParticleGenerator * parent, scene::Trajectory * trajectory) + : Generator(parent), + _trajectory(trajectory), + _next(0.f, 0.f, 0.f), + _index(0) {} - void PathGenerator::render(double) { - if(ImGui::CollapsingHeader("Generator Information")) { + void PathGenerator::draw(double) { + /*if(ImGui::CollapsingHeader("Generator Information")) { ImGui::Text("Physic generator at %f / %f / %f (x, y, z) - variation : %f.", this->_generator->m_position.x, this->_generator->m_position.y, this->_generator->m_position.z, this->_generator->m_positionVariation); ImGui::Separator(); ImGui::Text("Default u : %f", this->_generator->m_u); @@ -79,6 +82,8 @@ namespace pg::interface { } } } - } + }*/ + + ImGui::Text("Path Generator : %i", this->parent()); } } diff --git a/ParticleGenerator/src/Interface/Generator/PathGenerator.hpp b/ParticleGenerator/src/Interface/Generator/PathGenerator.hpp index e54ae83d70fe129ca68af1d1248f1d1b293d1b06..d1f480fe3eeb76ba56ddcb1fd1b0b91ef5791db8 100644 --- a/ParticleGenerator/src/Interface/Generator/PathGenerator.hpp +++ b/ParticleGenerator/src/Interface/Generator/PathGenerator.hpp @@ -1,7 +1,7 @@ #pragma once #include "../Interface.hpp" -#include "../../Mesh/Trajectory.hpp" +#include "../../Scene/Scenes/Trajectory.hpp" #include <glm/vec3.hpp> @@ -10,19 +10,18 @@ namespace pg { } namespace pg::interface { - class PathGenerator : public Interface { + class PathGenerator : public Generator<pg::PathParticleGenerator> { private: - PathParticleGenerator * _generator; - Trajectory * _trajectory; + scene::Trajectory * _trajectory; + glm::vec3 _next; int _index; public: - PathGenerator(PathParticleGenerator *, Trajectory * = nullptr); - - inline PathParticleGenerator * getGenerator() const {return this->_generator;} + PathGenerator(PathParticleGenerator *, scene::Trajectory * = nullptr); + virtual ~PathGenerator() = default; - virtual void render(double); - inline std::string title() const {return "Path Generator Interface";} + 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 b1e18a8c38eff54d0632c4f5fc061bd1a5eaf0db..1749e46b5f3d85f830387eebe65a5803a609fa82 100644 --- a/ParticleGenerator/src/Interface/Generator/PhysicGenerator.cpp +++ b/ParticleGenerator/src/Interface/Generator/PhysicGenerator.cpp @@ -7,11 +7,11 @@ #include "../../Particle/generator/PhysicsParticleGenerator.hpp" namespace pg::interface { - PhysicGenerator::PhysicGenerator(PhysicsParticleGenerator * generator) - : _generator(generator) {} + PhysicGenerator::PhysicGenerator(pg::PhysicsParticleGenerator * parent) + : Generator(parent) {} - void PhysicGenerator::render(double) { - if(this->_generator == nullptr) { + void PhysicGenerator::draw(double) { + /*if(this->_generator == nullptr) { return; } @@ -54,6 +54,7 @@ namespace pg::interface { ImGui::PopID(); ImGui::SeparatorText("Friction"); ImGui::DragFloat3("Variation", &this->_generator->m_frictionVariation[0], 0.0001f, 0.f, 0.f, "%.4f"); - } + }*/ + ImGui::Text("Physic Generator : %i", this->parent()); } } diff --git a/ParticleGenerator/src/Interface/Generator/PhysicGenerator.hpp b/ParticleGenerator/src/Interface/Generator/PhysicGenerator.hpp index ff3c5c5b8ae6cedd098798d46c7130a4b4687689..4ec81519d83b74c48712a3093ed9455e36a8f1a6 100644 --- a/ParticleGenerator/src/Interface/Generator/PhysicGenerator.hpp +++ b/ParticleGenerator/src/Interface/Generator/PhysicGenerator.hpp @@ -7,17 +7,11 @@ namespace pg { } namespace pg::interface { - class PhysicGenerator : public Interface { - private: - PhysicsParticleGenerator * _generator; - + class PhysicGenerator : public Generator<pg::PhysicsParticleGenerator> { public: - PhysicGenerator(PhysicsParticleGenerator *); - - inline PhysicsParticleGenerator * getGenerator() const {return this->_generator;} - inline void setGenerator(PhysicsParticleGenerator * generator) {this->_generator = generator;} + PhysicGenerator(pg::PhysicsParticleGenerator *); - virtual void render(double); + virtual void draw(double = 0.0); inline std::string title() const {return "Physic Generator Interface";} }; } \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Interface.hpp b/ParticleGenerator/src/Interface/Interface.hpp index b5a11b2d6254ce0bb1882a2d6695ac2f4465e222..2c94bf6feddd55f5e1836a5777c889593a641c2e 100644 --- a/ParticleGenerator/src/Interface/Interface.hpp +++ b/ParticleGenerator/src/Interface/Interface.hpp @@ -1,11 +1,46 @@ #pragma once #include <string> +#include <glm/vec4.hpp> + +namespace pg::scene { + class Scene; +} namespace pg::interface { + using Color = glm::vec4; class Interface { public: - virtual void render(double = 0.0) = 0; + Interface() = default; + virtual ~Interface() = default; + + virtual void draw(double = 0.0) = 0; virtual std::string title() const = 0; }; + + template <typename T> + class Scene : virtual public Interface { + private: + T * _parent; + + public: + Scene() = delete; + Scene(T * parent) : _parent(parent) {} + virtual ~Scene() = default; + + inline T * parent() const {return this->_parent;} + }; + + template <typename T> + class Generator : virtual public Interface { + private: + T * _parent; + + public: + Generator() = delete; + Generator(T * parent) : _parent(parent) {} + virtual ~Generator() = default; + + inline T * parent() const {return this->_parent;} + }; } \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Manager.cpp b/ParticleGenerator/src/Interface/Manager.cpp index 0fcb4841b7d3636f5e27b089f520c73773ad23fc..11bbdd73b51d5e47d446c112bb7338888ba36ec1 100644 --- a/ParticleGenerator/src/Interface/Manager.cpp +++ b/ParticleGenerator/src/Interface/Manager.cpp @@ -32,7 +32,6 @@ namespace pg::interface { this->_historical.count(current_time); if(ImGui::Begin(this->_title.c_str())) { - auto current = this->_manager.current(); if(ImGui::BeginTabBar("")) { if(ImGui::BeginTabItem("Scene")) { @@ -51,14 +50,14 @@ namespace pg::interface { } if(current.has_value() && (*current)->interface().has_value()) { - (*(*current)->interface())->render(current_time); + (*(*current)->interface())->draw(current_time); } ImGui::EndTabItem(); } if(ImGui::BeginTabItem("Performance")) { - this->_historical.render(current_time); + this->_historical.draw(current_time); ImGui::EndTabItem(); } ImGui::EndTabBar(); diff --git a/ParticleGenerator/src/Interface/Scene/MeshGenerator.cpp b/ParticleGenerator/src/Interface/Scene/MeshGenerator.cpp index 3c13649751f8c803847481f5abea8cf8ad036c8e..b42950a9c222b941efd4cd1625a1f0aa2c75b785 100644 --- a/ParticleGenerator/src/Interface/Scene/MeshGenerator.cpp +++ b/ParticleGenerator/src/Interface/Scene/MeshGenerator.cpp @@ -5,20 +5,11 @@ #include "../../tfd/tinyfiledialogs.h" namespace pg::interface { - MeshGenerator::MeshGenerator(scene::MeshGenerator * scene, size_t max) - : _scene(scene), - _interface(nullptr), - _max(max), - _spawnFrequence(2500), - _spawnCount(1), - _lifetime(2), - _enableRender(true), - _enableSpawn(true) { + MeshGenerator::MeshGenerator(scene::MeshGenerator * parent) + : Scene(parent), SceneParticle(parent), _interface(nullptr) {} - } - - void MeshGenerator::render(double current_time) { - ImGui::Text("Particles Number : %i / %i.", this->_scene->_particles.size(), this->_max); + void MeshGenerator::draw(double current_time) { + /*ImGui::Text("Particles Number : %i / %i.", this->_scene->_particles.size(), this->_max); ImGui::SameLine(); if(ImGui::Button("Spawn")) { this->_scene->spawn(1, current_time); @@ -74,6 +65,10 @@ namespace pg::interface { } } - this->_interface.render(current_time); + this->_interface.render(current_time);*/ + + SceneParticle::draw(current_time); + this->_interface.draw(current_time); + ImGui::Text("Mesh Generator : %i", this->parent()); } } \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Scene/MeshGenerator.hpp b/ParticleGenerator/src/Interface/Scene/MeshGenerator.hpp index e0ddd63914ba136a90d8ec7a47326ddcce2e0de7..6a84e52c003d75d1457fa3882be765c00745f62c 100644 --- a/ParticleGenerator/src/Interface/Scene/MeshGenerator.hpp +++ b/ParticleGenerator/src/Interface/Scene/MeshGenerator.hpp @@ -1,6 +1,8 @@ #pragma once #include "../Interface.hpp" +#include "SceneParticle.hpp" + #include "../Generator/PhysicGenerator.hpp" namespace pg::scene { @@ -8,32 +10,15 @@ namespace pg::scene { } namespace pg::interface { - class MeshGenerator : public Interface { + class MeshGenerator : public Scene<scene::MeshGenerator>, public SceneParticle { private: - scene::MeshGenerator * _scene; PhysicGenerator _interface; - - size_t _max; - int _spawnFrequence; - int _spawnCount; - int _lifetime; - - bool _enableRender; - bool _enableSpawn; public: - MeshGenerator(scene::MeshGenerator *, size_t max = 1024); - - inline size_t getMaxParticle() const {return this->_max;} - - inline int getSpawnFrequence() const {return this->_spawnFrequence;} - inline int getSpawnCount() const {return this->_spawnCount;} - inline int getLifeTime() const {return this->_lifetime;} - - inline bool isRenderEnable() {return this->_enableRender;} - inline bool isSpawnEnable() {return this->_enableSpawn;} + MeshGenerator(scene::MeshGenerator *); + virtual ~MeshGenerator() = default; - virtual void render(double); - inline std::string title() const {return "Mesh Generator Scene Interface";} + void draw(double = 0.0) override; + inline std::string title() const override final {return "Mesh Generator Scene Interface";} }; } \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Scene/PathScene.cpp b/ParticleGenerator/src/Interface/Scene/Path.cpp similarity index 70% rename from ParticleGenerator/src/Interface/Scene/PathScene.cpp rename to ParticleGenerator/src/Interface/Scene/Path.cpp index b305e15edcf30fc37dff7c484dd79c0e78980ff2..c533e32d8155f9888218a071e634d9caae874c8a 100644 --- a/ParticleGenerator/src/Interface/Scene/PathScene.cpp +++ b/ParticleGenerator/src/Interface/Scene/Path.cpp @@ -1,4 +1,4 @@ -#include "PathScene.hpp" +#include "Path.hpp" #include <imgui.h> @@ -6,19 +6,11 @@ #include "../../tfd/tinyfiledialogs.h" namespace pg::interface { - PathScene::PathScene(scene::Path * scene) - : _scene(scene), - _interface(&scene->_generator, &scene->_trajectory), - _max(1024), - _spawnFrequence(500), - _spawnCount(5), - _lifetime(5), - _color(1.f, 1.f, 1.f, 1.f), - _enableRender(true), - _enableSpawning(true) {} - - void PathScene::render(double current_time) { - ImGui::Text("Particles Number : %i / %i.", this->_scene->_particles.size(), this->_max); + Path::Path(scene::Path * parent, pg::PathParticleGenerator * generator) + : Scene(parent), SceneParticle(parent), _interface(generator) {} + + void Path::draw(double current_time) { + /*ImGui::Text("Particles Number : %i / %i.", this->_scene->_particles.size(), this->_max); ImGui::Checkbox("Enable Rendering", &this->_enableRender); ImGui::Separator(); ImGui::Checkbox("Enable Spawning", &this->_enableSpawning); @@ -50,6 +42,13 @@ namespace pg::interface { } } - this->_interface.render(current_time); + this->_interface.render(current_time);*/ + SceneParticle::draw(current_time); + this->_interface.draw(current_time); + auto tinterface = this->parent()->_trajectory.interface(); + if(tinterface.has_value()) { + (*tinterface)->draw(current_time); + } + ImGui::Text("Path Scene : %i", this->parent()); } } \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Scene/Path.hpp b/ParticleGenerator/src/Interface/Scene/Path.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c66c3cb4cb17ec23abab89d91089fc3762a424ec --- /dev/null +++ b/ParticleGenerator/src/Interface/Scene/Path.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include "../Interface.hpp" +#include "SceneParticle.hpp" +#include "../Generator/PathGenerator.hpp" + +#include <glm/vec4.hpp> + + +namespace pg::scene { + class Path; +} + +namespace pg::interface { + class Path : public Scene<scene::Path>, public SceneParticle { + private: + PathGenerator _interface; + + public: + Path(scene::Path *, pg::PathParticleGenerator *); + virtual ~Path() = 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/PathScene.hpp b/ParticleGenerator/src/Interface/Scene/PathScene.hpp deleted file mode 100644 index 0ccf7eef2e6a3994f266ed8169e2fbea7d0e8cf1..0000000000000000000000000000000000000000 --- a/ParticleGenerator/src/Interface/Scene/PathScene.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -#include "../Interface.hpp" -#include "../Generator/PathGenerator.hpp" - -#include <glm/vec4.hpp> - - -namespace pg::scene { - class Path; -} - -namespace pg::interface { - class PathScene : public Interface { - private: - scene::Path * _scene; - PathGenerator _interface; - - int _max; - int _spawnFrequence; - int _spawnCount; - int _lifetime; - - glm::vec4 _color; - - bool _enableRender; - bool _enableSpawning; - - public: - PathScene(scene::Path *); - - inline int getMaxParticle() const {return this->_max;} - inline int getSpawnFrequence() const {return this->_spawnFrequence;} - inline int getSpawnCount() const {return this->_spawnCount;} - inline int getLifeTime() const {return this->_lifetime;} - - inline const glm::vec4 & getColor() const {return this->_color;} - - inline bool isRenderEnable() {return this->_enableRender;} - inline bool isSpawningEnable() {return this->_enableSpawning;} - - inline void setSpawnFrequence(int freq) {this->_spawnFrequence = freq;} - inline void setSpawnCount(int count) {this->_spawnCount = count;} - inline void setGlobalColor(const glm::vec4 & color) {this->_color = color;} - inline void setRenderEnable(bool state) {this->_enableRender = state;} - inline void setEnableSpawning(bool state) {this->_enableSpawning = state;} - - virtual void render(double); - inline std::string title() const {return "Path Scene ";} - }; -} \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Scene/PhysicScene.cpp b/ParticleGenerator/src/Interface/Scene/Physic.cpp similarity index 75% rename from ParticleGenerator/src/Interface/Scene/PhysicScene.cpp rename to ParticleGenerator/src/Interface/Scene/Physic.cpp index b5d822f9b994f23e2de684d38b9f0ce58dccfe82..69d28e69d5d6e0744df745e9421f14557b8754df 100644 --- a/ParticleGenerator/src/Interface/Scene/PhysicScene.cpp +++ b/ParticleGenerator/src/Interface/Scene/Physic.cpp @@ -1,4 +1,4 @@ -#include "PhysicScene.hpp" +#include "Physic.hpp" #include <imgui.h> #include "../../tfd/tinyfiledialogs.h" @@ -8,19 +8,11 @@ #include <iostream> namespace pg::interface { - PhysicScene::PhysicScene(scene::Physic * scene) - : _scene(scene), - _generator(&scene->_generator), - _max(1024), - _spawnFrequence(500), - _spawnCount(5), - _lifetime(5), - _color(1.f, 1.f, 1.f, 1.f), - _enableRender(true), - _enableSpawning(true) {} - - void PhysicScene::render(double current_time) { - ImGui::Text("Particles Number : %i / %i.", this->_scene->_particles.size(), this->_max); + Physic::Physic(scene::Physic * parent, pg::PhysicsParticleGenerator * generator) + : Scene(parent), SceneParticle(parent), _interface(generator) {} + + void Physic::draw(double current_time) { + /*ImGui::Text("Particles Number : %i / %i.", this->_scene->_particles.size(), this->_max); //ImGui::Text("Frame Per Second : %f.", this->_fps); ImGui::Checkbox("Enable Rendering", &this->_enableRender); ImGui::Separator(); @@ -53,6 +45,9 @@ namespace pg::interface { } } - this->_generator.render(current_time); + this->_generator.render(current_time);*/ + SceneParticle::draw(current_time); + this->_interface.draw(current_time); + ImGui::Text("Phsyic Interface : %i", this->parent()); } } \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Scene/Physic.hpp b/ParticleGenerator/src/Interface/Scene/Physic.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9db411c8a79d4f5c10f83bcbce17322b3b752274 --- /dev/null +++ b/ParticleGenerator/src/Interface/Scene/Physic.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include "../Interface.hpp" +#include "SceneParticle.hpp" +#include "../Generator/PhysicGenerator.hpp" +#include "../../Particle/generator/PhysicsParticleGenerator.hpp" + +#include <glm/vec4.hpp> + +namespace pg::scene { + class Physic; +} + +namespace pg::interface { + class Physic : public Scene<scene::Physic>, public SceneParticle { + private: + PhysicGenerator _interface; + + public: + Physic(scene::Physic *, pg::PhysicsParticleGenerator *); + virtual ~Physic() = default; + + virtual void draw(double); + inline std::string title() const override final {return "Physic Scene Interface";} + }; +} \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Scene/PhysicScene.hpp b/ParticleGenerator/src/Interface/Scene/PhysicScene.hpp deleted file mode 100644 index ad4b40d19e1be9ce8725e1988f50ef0c9a90064d..0000000000000000000000000000000000000000 --- a/ParticleGenerator/src/Interface/Scene/PhysicScene.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include "../Interface.hpp" -#include "../Generator/PhysicGenerator.hpp" - -#include <glm/vec4.hpp> - -namespace pg::scene { - class Physic; -} - -namespace pg::interface { - class PhysicScene : public Interface { - private: - scene::Physic * _scene; - PhysicGenerator _generator; - - int _max; - int _spawnFrequence; - int _spawnCount; - int _lifetime; - - glm::vec4 _color; - - bool _enableRender; - bool _enableSpawning; - - public: - PhysicScene(scene::Physic *); - - inline int getMaxParticle() const {return this->_max;} - inline int getSpawnFrequence() const {return this->_spawnFrequence;} - inline int getSpawnCount() const {return this->_spawnCount;} - inline int getLifeTime() const {return this->_lifetime;} - - inline const glm::vec4 & getColor() const {return this->_color;} - - inline bool isRenderEnable() {return this->_enableRender;} - inline bool isSpawningEnable() {return this->_enableSpawning;} - - inline void setSpawnFrequence(int freq) {this->_spawnFrequence = freq;} - inline void setSpawnCount(int count) {this->_spawnCount = count;} - inline void setGlobalColor(const glm::vec4 & color) {this->_color = color;} - inline void setRenderEnable(bool state) {this->_enableRender = state;} - inline void setEnableSpawning(bool state) {this->_enableSpawning = state;} - - virtual void render(double); - inline std::string title() const {return "Physic Scene ";} - }; -} \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Scene/SceneParticle.cpp b/ParticleGenerator/src/Interface/Scene/SceneParticle.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a1f43e23b26f3c0f46933331cb3083426ffb2a65 --- /dev/null +++ b/ParticleGenerator/src/Interface/Scene/SceneParticle.cpp @@ -0,0 +1,12 @@ +#include "SceneParticle.hpp" + +#include <imgui.h> + +namespace pg::interface { + SceneParticle::SceneParticle(scene::SceneParticle * scene) + : _scene(scene) {} + + void SceneParticle::draw(double) { + ImGui::Text("Scene Particle Interface !"); + } +} \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Scene/SceneParticle.hpp b/ParticleGenerator/src/Interface/Scene/SceneParticle.hpp new file mode 100644 index 0000000000000000000000000000000000000000..10f24bc49ca02f636d98a4f215e90496c317bf5a --- /dev/null +++ b/ParticleGenerator/src/Interface/Scene/SceneParticle.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include "../Interface.hpp" + +namespace pg::scene { + class SceneParticle; +} + +namespace pg::interface { + class SceneParticle : virtual public Interface { + private: + const scene::SceneParticle * _scene; + + public: + SceneParticle(scene::SceneParticle *); + virtual ~SceneParticle() = default; + + virtual void draw(double = 0.0); + }; +} \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Scene/Trajectory.cpp b/ParticleGenerator/src/Interface/Scene/Trajectory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..18ff7771bb155fbb092b28764311081b71fe6773 --- /dev/null +++ b/ParticleGenerator/src/Interface/Scene/Trajectory.cpp @@ -0,0 +1,12 @@ +#include "Trajectory.hpp" + +#include <imgui.h> + +namespace pg::interface { + Trajectory::Trajectory(scene::Trajectory * parent) + : Scene(parent) {} + + void Trajectory::draw(double) { + ImGui::Text("Trajectory Interface : %i", this->parent()); + } +} \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Scene/Trajectory.hpp b/ParticleGenerator/src/Interface/Scene/Trajectory.hpp new file mode 100644 index 0000000000000000000000000000000000000000..946bcff09340141abaa079d0fad056cd229b65bc --- /dev/null +++ b/ParticleGenerator/src/Interface/Scene/Trajectory.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include "../Interface.hpp" + +namespace pg::scene { + class Trajectory; +} + +namespace pg::interface { + class Trajectory : public Scene<scene::Trajectory> { + public: + Trajectory(scene::Trajectory *); + + virtual void draw(double = 0.0); + inline std::string title() const override final {return "Trajectory Interface";} + }; +} \ No newline at end of file diff --git a/ParticleGenerator/src/Mesh/Trajectory.hpp b/ParticleGenerator/src/Mesh/Trajectory.hpp deleted file mode 100644 index 2b7641f6258721f7f5bd78b14109f902c6728e08..0000000000000000000000000000000000000000 --- a/ParticleGenerator/src/Mesh/Trajectory.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "../Renderer/Renderer.hpp" -#include "../Particle/generator/PathParticleGenerator.hpp" - -namespace pg { - class Trajectory { - private: - PathParticleGenerator * _generator; - VertexArray _vao; - VerticeBuffer _vbo; - Program _program; - double _increment; - - public: - Trajectory(PathParticleGenerator *, double = 0.01f); - - void initialize(); - void draw(const Camera &, double); - void update(); - void destroy(); - }; -} \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Manager.hpp b/ParticleGenerator/src/Scene/Manager.hpp index 4e05e8bdcfa013c196168fe8d9fa1c60e29501c7..1b836b44c0b1bb9c768279a547ac9f134cd8441c 100644 --- a/ParticleGenerator/src/Scene/Manager.hpp +++ b/ParticleGenerator/src/Scene/Manager.hpp @@ -4,7 +4,7 @@ #include <memory> #include "Renderer.hpp" -#include "Scenes/Scene.hpp" +#include "Scene.hpp" #include "../Renderer/Camera/Camera.hpp" diff --git a/ParticleGenerator/src/Scene/Scene.cpp b/ParticleGenerator/src/Scene/Scene.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ba88cc6bde14e996e993b5b0b55ff38a46d33e10 --- /dev/null +++ b/ParticleGenerator/src/Scene/Scene.cpp @@ -0,0 +1,6 @@ +#include "Scene.hpp" + +namespace pg::scene { + SceneParticle::SceneParticle(size_t max) + : Scene(), _max(max), _spawn(1), _frequence(500), _lifetime(5), _enableRender(true), _enableSpawn(true) {} +} \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scene.hpp b/ParticleGenerator/src/Scene/Scene.hpp new file mode 100644 index 0000000000000000000000000000000000000000..60f161fd42bf9d67ac6acd67e04d8452dc87440a --- /dev/null +++ b/ParticleGenerator/src/Scene/Scene.hpp @@ -0,0 +1,63 @@ +#pragma once + +#include <string> +#include <optional> +#include <memory> + +#include "../Interface/Interface.hpp" +#include "../Interface/Scene/SceneParticle.hpp" +#include "../Renderer/Camera/Camera.hpp" +#include "../Particle/Particle.hpp" + +namespace pg::scene { + class Scene { + public: + Scene() = default; + virtual ~Scene() = default; + + virtual std::string name() const {return "Scene";} + virtual std::optional<interface::Interface *> interface() {return std::optional<interface::Interface *>();} + + virtual void initialize() = 0; + virtual void update(double) = 0; + virtual void render(const Camera &, double) = 0; + virtual void destroy() = 0; + }; + + using ParticleContainer = std::vector<std::unique_ptr<pg::Particle>>; + + class SceneParticle : public Scene { + private: + const size_t _max; + size_t _spawn; + unsigned int _frequence; + unsigned int _lifetime; + bool _enableRender; + bool _enableSpawn; + + protected: + ParticleContainer _particles; + + public: + SceneParticle(size_t max); + virtual ~SceneParticle() = default; + + inline const ParticleContainer & getParticles() const {return this->_particles;} + inline size_t getMaxParticles() const {return this->_max;} + inline size_t getSpawnCount() const {return this->_spawn;} + inline unsigned int getSpawnFrequence() const {return this->_frequence;} + inline unsigned int getLifetime() const {return this->_lifetime;} + inline bool isRenderEnable() {return this->_enableRender;} + inline bool isSpawnEnable() {return this->_enableSpawn;} + + inline void setSpawnCount(size_t sc) {this->_spawn = sc;} + inline void setSpawnFrequence(unsigned int sf) {this->_frequence = sf;} + inline void setLifetime(unsigned int lt) {this->_lifetime = lt;} + inline void enableRender(bool state) {this->_enableRender = state;} + inline void enableSpawn(bool state) {this->_enableSpawn = state;} + + virtual void spawn(size_t, double) = 0; + + friend class interface::SceneParticle; + }; +} \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scenes/Grid.hpp b/ParticleGenerator/src/Scene/Scenes/Grid.hpp index faa1e52c44bbec0299ff964ce4e592e66f17813a..68c84d3018833ac4844d6f529e943c7a4a0b9ad6 100644 --- a/ParticleGenerator/src/Scene/Scenes/Grid.hpp +++ b/ParticleGenerator/src/Scene/Scenes/Grid.hpp @@ -1,6 +1,6 @@ #pragma once -#include "Scene.hpp" +#include "../Scene.hpp" #include "../../Renderer/Renderer.hpp" #include "../../Mesh/Model.hpp" @@ -25,6 +25,5 @@ namespace pg::scene void destroy() override; std::string name() const override; - std::optional<interface::Interface *> interface() override {return std::optional<interface::Interface *>();} }; } \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scenes/MeshGenerator.cpp b/ParticleGenerator/src/Scene/Scenes/MeshGenerator.cpp index 434f9ba9347dfd1d722b2df910aaa3c2734cef12..360ca05036ce17e13fccafced61911c8df35d790 100644 --- a/ParticleGenerator/src/Scene/Scenes/MeshGenerator.cpp +++ b/ParticleGenerator/src/Scene/Scenes/MeshGenerator.cpp @@ -8,7 +8,8 @@ namespace pg::scene { MeshGenerator::MeshGenerator() - : _mesh(), + : SceneParticle(16384), + _mesh(), _meshProgram(), _meshPosition(0.f), _meshRotation(0.f), @@ -18,7 +19,7 @@ namespace pg::scene { _billboardTexture(), _billboardProgram(), _ubo(0), - _interface(this, 16394) {} + _interface(this) {} void MeshGenerator::initialize() { if(!this->_mesh.isGenerated()) { @@ -64,18 +65,18 @@ namespace pg::scene { glBindBuffer(GL_UNIFORM_BUFFER, 0); } - this->_particles.reserve(this->_interface.getMaxParticle()); + this->_particles.reserve(2048); } void MeshGenerator::update(double current_time) { static auto start = std::chrono::high_resolution_clock::now(); auto end = std::chrono::high_resolution_clock::now(); - pg::Particle::purge(this->_particles, static_cast<size_t>(current_time), this->_interface.getLifeTime()); - if(duration_cast<std::chrono::milliseconds>(end - start).count() >= this->_interface.getSpawnFrequence()) { + pg::Particle::purge(this->_particles, static_cast<size_t>(current_time), 3); + if(duration_cast<std::chrono::milliseconds>(end - start).count() >= 3000) { start = std::chrono::high_resolution_clock::now(); - if(this->_interface.isSpawnEnable()) { - this->spawn(this->_interface.getSpawnCount(), current_time); + if(true) { + this->spawn(1, current_time); } } @@ -134,7 +135,7 @@ namespace pg::scene { pg::error::OpenGLError::check(); - if(this->_interface.isRenderEnable()) { + if(true) { this->_billboard.draw(this->_particles.size()); } @@ -180,7 +181,7 @@ namespace pg::scene { void MeshGenerator::spawn(size_t count, double current_time) { for(auto & generator : this->_generators) { - if((count + this->_particles.size()) <= this->_interface.getMaxParticle()) { + if((count + this->_particles.size()) <= 2048) { std::vector<std::unique_ptr<pg::Particle>> newParticles = generator.generate(count, static_cast<size_t>(current_time)); this->_particles.insert(this->_particles.begin(), std::make_move_iterator(newParticles.begin()), std::make_move_iterator(newParticles.end())); } diff --git a/ParticleGenerator/src/Scene/Scenes/MeshGenerator.hpp b/ParticleGenerator/src/Scene/Scenes/MeshGenerator.hpp index 58609cfab987e98418f1d27d304cfca2a591817c..c53003d824e854174c85b9c2144a6057591bd01d 100644 --- a/ParticleGenerator/src/Scene/Scenes/MeshGenerator.hpp +++ b/ParticleGenerator/src/Scene/Scenes/MeshGenerator.hpp @@ -1,6 +1,6 @@ #pragma once -#include "Scene.hpp" +#include "../Scene.hpp" #include <vector> #include <memory> @@ -12,7 +12,7 @@ #include "../../Interface/Scene/MeshGenerator.hpp" namespace pg::scene { - class MeshGenerator : public Scene { + class MeshGenerator : public SceneParticle { private: Mesh _mesh; Program _meshProgram; diff --git a/ParticleGenerator/src/Scene/Scenes/Path.cpp b/ParticleGenerator/src/Scene/Scenes/Path.cpp index 165a4ff5093d69e36120bc9dd929baec1875e794..787d4e345baa6947a3422cd5efb89ae957b17c1e 100644 --- a/ParticleGenerator/src/Scene/Scenes/Path.cpp +++ b/ParticleGenerator/src/Scene/Scenes/Path.cpp @@ -5,13 +5,14 @@ namespace pg::scene { Path::Path(ct::CurveGenerator * generator, const ct::Curve & ctrlpoint) - : _ubo(0), - _program(), - _texture(), - _generator(generator, ctrlpoint), - _trajectory(&this->_generator), - _particles(), - _interface(this) {} + : SceneParticle(1024), + _ubo(0), + _program(), + _texture(), + _generator(generator, ctrlpoint), + _trajectory(&this->_generator), + _particles(), + _interface(this, &this->_generator) {} void Path::initialize() { this->_billboard.initialize(); @@ -58,11 +59,11 @@ namespace pg::scene { static auto start = std::chrono::high_resolution_clock::now(); auto end = std::chrono::high_resolution_clock::now(); - pg::Particle::purge(this->_particles, static_cast<size_t>(current_time), this->_interface.getLifeTime()); - if(duration_cast<std::chrono::milliseconds>(end - start).count() >= this->_interface.getSpawnFrequence()) { + pg::Particle::purge(this->_particles, static_cast<size_t>(current_time), 5); + if(duration_cast<std::chrono::milliseconds>(end - start).count() >= 500) { start = std::chrono::high_resolution_clock::now(); - if((this->_interface.getSpawnCount() + this->_particles.size()) <= this->_interface.getMaxParticle() && this->_interface.isSpawningEnable()) { - std::vector<std::unique_ptr<pg::Particle>> newParticles = this->_generator.generate(this->_interface.getSpawnCount(), static_cast<size_t>(current_time)); + if((5 + this->_particles.size() <= 1024) && true) { + std::vector<std::unique_ptr<pg::Particle>> newParticles = this->_generator.generate(5, static_cast<size_t>(current_time)); this->_particles.insert(this->_particles.begin(), std::make_move_iterator(newParticles.begin()), std::make_move_iterator(newParticles.end())); } } @@ -78,7 +79,7 @@ namespace pg::scene { const glm::mat4 VIEW_MATRIX = camera.getViewMatrix(); const glm::mat4 PROJECTION_MATRIX = camera.getViewFrustum().getProjectionMatrix(); - this->_trajectory.draw(camera, current_time); + this->_trajectory.render(camera, current_time); std::vector<glm::mat4> models; @@ -100,12 +101,12 @@ namespace pg::scene { this->_program.setUniform("uView", VIEW_MATRIX); this->_program.setUniform("uProj", PROJECTION_MATRIX); this->_program.setUniform("uSlot", 0); - this->_program.setUniform("uColor", this->_interface.getColor()); + this->_program.setUniform("uColor", glm::vec4(1.f)); pg::error::OpenGLError::check(); this->_texture.bind(); - if(this->_interface.isRenderEnable()) { + if(true) { this->_billboard.draw(this->_particles.size()); } @@ -123,4 +124,8 @@ namespace pg::scene { void Path::changeParticletexture(const std::string & path) { this->_texture.load(path); } + + void Path::spawn(size_t count, double current_time) { + + } } \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scenes/Path.hpp b/ParticleGenerator/src/Scene/Scenes/Path.hpp index f89c30ce0f492e251ddb070b55ea5f03d23ea5d7..4105bdf6494eccbe030f152d9a8a5d4cce736bff 100644 --- a/ParticleGenerator/src/Scene/Scenes/Path.hpp +++ b/ParticleGenerator/src/Scene/Scenes/Path.hpp @@ -1,17 +1,16 @@ #pragma once -#include "Scene.hpp" +#include "../Scene.hpp" +#include "Trajectory.hpp" #include "../../Renderer/Renderer.hpp" #include "../../Particle/generator/PathParticleGenerator.hpp" -#include "../../Interface/Scene/PathScene.hpp" +#include "../../Interface/Scene/Path.hpp" #include "../../Mesh/Billboard.hpp" -#include "../../Mesh/Trajectory.hpp" - #include "../../System/Window.hpp" namespace pg::scene { - class Path : public Scene { + class Path : public SceneParticle { private: GLuint _ubo; @@ -22,7 +21,7 @@ namespace pg::scene { PathParticleGenerator _generator; std::vector<std::unique_ptr<Particle>> _particles; - interface::PathScene _interface; + interface::Path _interface; public: Path(ct::CurveGenerator *, const ct::Curve &); @@ -42,6 +41,8 @@ namespace pg::scene { virtual std::string name() const {return "Path Scene";} virtual std::optional<interface::Interface *> interface() {return std::optional<interface::Interface *>(&this->_interface);} - friend class pg::interface::PathScene; + virtual void spawn(size_t, double); + + friend class pg::interface::Path; }; } \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scenes/Physic.cpp b/ParticleGenerator/src/Scene/Scenes/Physic.cpp index e1be3d0946f1271c22616cbf4d791395d835ac8b..68babd395d38c1fcf41102256670bdf47459d8e1 100644 --- a/ParticleGenerator/src/Scene/Scenes/Physic.cpp +++ b/ParticleGenerator/src/Scene/Scenes/Physic.cpp @@ -5,12 +5,13 @@ namespace pg::scene { Physic::Physic() - : _ubo(0), + : SceneParticle(1024), + _ubo(0), _program(), _texture(), _generator(), _particles(), - _interface(this) {} + _interface(this, &this->_generator) {} void Physic::initialize() { this->_billboards.initialize(); @@ -54,11 +55,11 @@ namespace pg::scene { static auto start = std::chrono::high_resolution_clock::now(); auto end = std::chrono::high_resolution_clock::now(); - pg::Particle::purge(this->_particles, static_cast<size_t>(current_time), this->_interface.getLifeTime()); - if(duration_cast<std::chrono::milliseconds>(end - start).count() >= this->_interface.getSpawnFrequence()) { + pg::Particle::purge(this->_particles, static_cast<size_t>(current_time), 5); + if(duration_cast<std::chrono::milliseconds>(end - start).count() >= 500) { start = std::chrono::high_resolution_clock::now(); - if((this->_interface.getSpawnCount() + this->_particles.size()) <= this->_interface.getMaxParticle() && this->_interface.isSpawningEnable()) { - std::vector<std::unique_ptr<pg::Particle>> newParticles = this->_generator.generate(this->_interface.getSpawnCount(), static_cast<size_t>(current_time)); + if((5 + this->_particles.size()) <= 1024 && true) { + std::vector<std::unique_ptr<pg::Particle>> newParticles = this->_generator.generate(5, static_cast<size_t>(current_time)); this->_particles.insert(this->_particles.begin(), std::make_move_iterator(newParticles.begin()), std::make_move_iterator(newParticles.end())); } } @@ -95,11 +96,11 @@ namespace pg::scene { this->_program.setUniform("uView", VIEW_MATRIX); this->_program.setUniform("uProj", PROJECTION_MATRIX); this->_program.setUniform("uSlot", 0); - this->_program.setUniform("uColor", this->_interface.getColor()); + this->_program.setUniform("uColor", glm::vec4(1.f)); pg::error::OpenGLError::check(); - if(this->_interface.isRenderEnable()) { + if(true) { this->_billboards.draw(this->_particles.size()); } @@ -117,4 +118,8 @@ namespace pg::scene { void Physic::changeParticletexture(const std::string & path) { this->_texture.load(path); } + + void Physic::spawn(size_t count, double current_time) { + + } } \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scenes/Physic.hpp b/ParticleGenerator/src/Scene/Scenes/Physic.hpp index 419c40a5fa7dce39a2bb8391b19899cb185df3ed..aaaac8fd11bea1510a4c31bd5e742b3e2cc95899 100644 --- a/ParticleGenerator/src/Scene/Scenes/Physic.hpp +++ b/ParticleGenerator/src/Scene/Scenes/Physic.hpp @@ -1,16 +1,16 @@ #pragma once -#include "Scene.hpp" +#include "../Scene.hpp" #include "../../Renderer/Renderer.hpp" #include "../../Particle/generator/PhysicsParticleGenerator.hpp" -#include "../../Interface/Scene/PhysicScene.hpp" +#include "../../Interface/Scene/Physic.hpp" #include "../../Mesh/Billboard.hpp" #include "../../System/Window.hpp" namespace pg::scene { - class Physic : public Scene { + class Physic : public SceneParticle { private: GLuint _ubo; Program _program; @@ -19,7 +19,7 @@ namespace pg::scene { PhysicsParticleGenerator _generator; std::vector<std::unique_ptr<Particle>> _particles; - interface::PhysicScene _interface; + interface::Physic _interface; public: Physic(); @@ -39,8 +39,8 @@ namespace pg::scene { virtual void update(double); virtual void destroy(); - + virtual void spawn(size_t, double); - friend class pg::interface::PhysicScene; + friend class pg::interface::Physic; }; } \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scenes/Scene.hpp b/ParticleGenerator/src/Scene/Scenes/Scene.hpp deleted file mode 100644 index a9f08bd4b60eb265d6ae8ae7b25bff1c1bbe3735..0000000000000000000000000000000000000000 --- a/ParticleGenerator/src/Scene/Scenes/Scene.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include <string> -#include <optional> - -#include "../../Interface/Interface.hpp" -#include "../../Renderer/Camera/Camera.hpp" - -namespace pg::scene { - class Scene { - public: - Scene() = default; - virtual ~Scene() = default; - - virtual std::string name() const {return "Scene";} - virtual std::optional<interface::Interface *> interface() = 0;// const {return std::optional<interface::Interface *>();} - - virtual void initialize() = 0; - virtual void update(double) = 0; - virtual void render(const Camera &, double) = 0; - virtual void destroy() = 0; - }; -} \ No newline at end of file diff --git a/ParticleGenerator/src/Mesh/Trajectory.cpp b/ParticleGenerator/src/Scene/Scenes/Trajectory.cpp similarity index 66% rename from ParticleGenerator/src/Mesh/Trajectory.cpp rename to ParticleGenerator/src/Scene/Scenes/Trajectory.cpp index e8f0d3adc1ecb17d1f4fbfc10f8d858f110349cc..9d1c0b86c317aac5ffce69cb4134b8026dc133f9 100644 --- a/ParticleGenerator/src/Mesh/Trajectory.cpp +++ b/ParticleGenerator/src/Scene/Scenes/Trajectory.cpp @@ -3,15 +3,21 @@ #include <CurveTools/CPU/CurveSampler.hpp> -namespace pg { +namespace pg::scene { Trajectory::Trajectory(PathParticleGenerator * generator, double increment) - : _generator(generator), _vbo(this->_vao, {layout::POSITION, layout::COLOR}), _increment(increment) {} + : _generator(generator), + _vbo(this->_vao, {layout::POSITION, layout::COLOR}), + _increment(increment), + _color(0.15f, 0.25f, 1.f, 1.f), + _pointSize(8.f), + _controlLine(false), + _interface(this) {} void Trajectory::initialize() { - this->update(); + this->update(0.0); if(!this->_program.usable()) { - Source vert("res/shaders/system/Trajectory.vert", Source::Categorie::VERTEX); - Source frag("res/shaders/system/Trajectory.frag", Source::Categorie::FRAGMENT); + 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; @@ -23,16 +29,16 @@ namespace pg { } } - void Trajectory::update() { + void Trajectory::update(double) { std::vector<float> traj; for(auto & point : this->_generator->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.f); - traj.push_back(0.f); - traj.push_back(0.f); + traj.push_back(0.75f); + traj.push_back(0.75f); + traj.push_back(0.75f); } std::vector<double> ps; @@ -47,15 +53,15 @@ namespace pg { traj.push_back(static_cast<float>(point.y)); traj.push_back(static_cast<float>(point.z)); - traj.push_back(0.f); traj.push_back(1.f); - traj.push_back(0.f); + traj.push_back(1.f); + traj.push_back(1.f); } this->_vbo.set(traj); } - void Trajectory::draw(const Camera & camera, double current_time) { + void Trajectory::render(const Camera & camera, double current_time) { glEnable(GL_LINE_SMOOTH); this->_vao.bind(); @@ -63,11 +69,13 @@ namespace pg { 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_POINTS, 0, static_cast<GLsizei>(this->_generator->getControlPoint().size())); + glDrawArrays(this->_controlLine ? GL_LINE_STRIP : GL_POINTS, 0, static_cast<GLsizei>(this->_generator->getControlPoint().size())); glDrawArrays(GL_LINE_STRIP, raw, total - raw); } diff --git a/ParticleGenerator/src/Scene/Scenes/Trajectory.hpp b/ParticleGenerator/src/Scene/Scenes/Trajectory.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8783be090908b4806272a025e7e5b7ed4bb37668 --- /dev/null +++ b/ParticleGenerator/src/Scene/Scenes/Trajectory.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include "../../Renderer/Renderer.hpp" +#include "../../Particle/generator/PathParticleGenerator.hpp" +#include "../../Interface/Scene/Trajectory.hpp" +#include "../Scene.hpp" + +namespace pg::scene { + class Trajectory : public Scene { + private: + PathParticleGenerator * _generator; + VertexArray _vao; + VerticeBuffer _vbo; + Program _program; + double _increment; + + glm::vec4 _color; + float _pointSize; + bool _controlLine; + + interface::Trajectory _interface; + + public: + Trajectory(PathParticleGenerator *, double = 0.01f); + + inline PathParticleGenerator * 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;} + + 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::Trajectory; + }; +} \ No newline at end of file diff --git a/ParticleGenerator/src/System/FrameHistorical.cpp b/ParticleGenerator/src/System/FrameHistorical.cpp index 551833a0ccec5772a5c1c4506f3eb5103b605435..7636911fcc83e64c4fd55b4f36f32f4a7753286b 100644 --- a/ParticleGenerator/src/System/FrameHistorical.cpp +++ b/ParticleGenerator/src/System/FrameHistorical.cpp @@ -10,7 +10,7 @@ namespace pg::interface { } } - void FrameHistorical::render(double current_time) { + void FrameHistorical::draw(double current_time) { if(this->isUpdated()) { this->_frames.push_back(static_cast<float>(this->getFramePerSecond())); if(this->_frames.size() > 100) { diff --git a/ParticleGenerator/src/System/FrameHistorical.hpp b/ParticleGenerator/src/System/FrameHistorical.hpp index 625d0ff011fd4970657c0d28581d326f7a77a01d..e830e289caec31e9e7e35d9d8d566a50a8b1299b 100644 --- a/ParticleGenerator/src/System/FrameHistorical.hpp +++ b/ParticleGenerator/src/System/FrameHistorical.hpp @@ -13,7 +13,7 @@ namespace pg::interface { public: FrameHistorical(); - virtual void render(double); + virtual void draw(double); virtual std::string title() const {return "Frame Historical";} }; } \ No newline at end of file diff --git a/ParticleGenerator/src/main.cpp b/ParticleGenerator/src/main.cpp index efa5244124d7661edc63d16de62e7d20af156fd8..806a76da55b4e97833415e2c284ac97e44ec6599 100644 --- a/ParticleGenerator/src/main.cpp +++ b/ParticleGenerator/src/main.cpp @@ -9,7 +9,6 @@ #include "Scene/Scenes/Physic.hpp" #include "Scene/Scenes/Path.hpp" -#include "Scene/Scenes/Mesh.hpp" #include "Scene/Scenes/MeshGenerator.hpp" #include "Scene/Scenes/Grid.hpp" @@ -77,7 +76,6 @@ int main(int argc, const char * argv[]) { pg::scene::Physic physic; pg::scene::MeshGenerator meshGenerator; pg::scene::Path path(&bezier, ctrlPoints); - pg::scene::Mesh mesh(&bezier, ctrlPoints); pg::Manager manager(window); pg::interface::Manager imanager(window, manager); @@ -85,7 +83,6 @@ int main(int argc, const char * argv[]) { manager.add(&path); manager.add(&physic); manager.add(&meshGenerator); - manager.add(&mesh); while(window.isOpen()) { double current_time = glfwGetTime();