From d9095f708f68510bb5bcfa30de5250495d485c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9au?= <theau.baton@etu.univ-amu.fr> Date: Wed, 22 May 2024 18:35:12 +0200 Subject: [PATCH] Add path curve trajecory viewer --- CurveTools/src/main.cu | 27 +++---- ParticleGenerator/CMakeLists.txt | 4 +- .../res/shaders/system/Trajectory.frag | 8 ++ .../res/shaders/system/Trajectory.vert | 14 ++++ .../Generator/PathGeneratorInterface.cpp | 12 ++- .../Generator/PathGeneratorInterface.hpp | 4 +- .../Interface/Scene/PathSceneInterface.cpp | 2 +- ParticleGenerator/src/Mesh/Trajectory.cpp | 76 +++++++++++++++++++ ParticleGenerator/src/Mesh/Trajectory.hpp | 23 ++++++ .../generator/PathParticleGenerator.hpp | 2 +- ParticleGenerator/src/Scene/Scenes/Mesh.cpp | 9 --- ParticleGenerator/src/Scene/Scenes/Path.cpp | 4 + ParticleGenerator/src/Scene/Scenes/Path.hpp | 2 + ParticleGenerator/src/main.cpp | 4 +- 14 files changed, 158 insertions(+), 33 deletions(-) create mode 100644 ParticleGenerator/res/shaders/system/Trajectory.frag create mode 100644 ParticleGenerator/res/shaders/system/Trajectory.vert create mode 100644 ParticleGenerator/src/Mesh/Trajectory.cpp create mode 100644 ParticleGenerator/src/Mesh/Trajectory.hpp diff --git a/CurveTools/src/main.cu b/CurveTools/src/main.cu index aa0c319..7f48602 100644 --- a/CurveTools/src/main.cu +++ b/CurveTools/src/main.cu @@ -7,15 +7,15 @@ #include "CurveTools/GPU/LinearGenerator.cuh" #include "CurveTools/GPU/SplineGenerator.cuh" #include "CurveTools/GPU/CatmullRomGenerator.cuh" -#include "CurveTools/GPU/HermiteGenerator.cuh" +#include "CurveTools/GPU/BezierGenerator.cuh" #include "CurveTools/CPU/BezierGenerator.hpp" #include "CurveTools/CPU/LinearGenerator.hpp" #include "CurveTools/CPU/BSplineGenerator.hpp" #include "CurveTools/CPU/CatmullRomGenerator.hpp" -#include "CurveTools/CPU/HermiteGenerator.hpp" - +#include "CurveTools/CPU/BezierGenerator.hpp" +#include "CurveTools/CPU/CurveSampler.hpp" int main(int argc, const char * argv[]) { @@ -24,19 +24,14 @@ int main(int argc, const char * argv[]) { { using namespace ct; - Point p1(0.0, 0.0, 0.0); - Point p2(1.0, 1.0, 1.0); - Point p3(2.0, 2.0, 2.0); - Point p4(3.0, 3.0, 3.0); - HermiteGenerator CRG; - Point result_1 = CRG({p1, p2, p3, p4}, 0.25); - Point result_2 = CRG({p1, p2, p3, p4}, 0.5); - Point result_3 = CRG({p1, p2, p3, p4}, 0.75); - - std::cout << result_1.x << "/" << result_1.y << "/" << result_1.z << std::endl; - std::cout << result_2.x << "/" << result_2.y << "/" << result_2.z << std::endl; - std::cout << result_3.x << "/" << result_3.y << "/" << result_3.z << std::endl; + Point p1(-10.0, 0.0, 0.0); + Point p2(10.0, 1.0, 1.0); + BezierGenerator CRG(2); + ct::Point result = CRG.operator()({p1, p2}, 0.01); + + + std::cout << result.x << "/" << result.y << "/" << result.z << std::endl; } std::cout << "GPU : " << std::endl; @@ -48,7 +43,7 @@ int main(int argc, const char * argv[]) { Point p2(1.0, 1.0, 1.0); Point p3(2.0, 2.0, 2.0); Point p4(3.0, 3.0, 3.0); - HermiteGenerator CRG; + BezierGenerator CRG; Curve curve = CRG({p1, p2, p3, p4}, {0.25f, 0.5f, 0.75f}); for(auto & result : curve) { diff --git a/ParticleGenerator/CMakeLists.txt b/ParticleGenerator/CMakeLists.txt index 857dd77..45a8953 100644 --- a/ParticleGenerator/CMakeLists.txt +++ b/ParticleGenerator/CMakeLists.txt @@ -33,9 +33,9 @@ option(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake") # Macros #===================================== -if(${USE_STATIC_DEPENDENCIES}) +#if(${USE_STATIC_DEPENDENCIES}) add_compile_definitions(CURVETOOLS_STATIC) -endif() +#endif() #===================================== # Source diff --git a/ParticleGenerator/res/shaders/system/Trajectory.frag b/ParticleGenerator/res/shaders/system/Trajectory.frag new file mode 100644 index 0000000..ea75c60 --- /dev/null +++ b/ParticleGenerator/res/shaders/system/Trajectory.frag @@ -0,0 +1,8 @@ +#version 330 core +out vec4 FragColor; + +in vec3 zCol; + +void main() { + FragColor = vec4(zCol, 1.0); +} \ No newline at end of file diff --git a/ParticleGenerator/res/shaders/system/Trajectory.vert b/ParticleGenerator/res/shaders/system/Trajectory.vert new file mode 100644 index 0000000..d8aa6a9 --- /dev/null +++ b/ParticleGenerator/res/shaders/system/Trajectory.vert @@ -0,0 +1,14 @@ +#version 330 core +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec3 aCol; + +out vec3 zCol; + +uniform mat4 uProj; +uniform mat4 uView; + +void main() { + gl_Position = uProj * uView * vec4(aPos, 1.0); + gl_PointSize = 8.0; + zCol = aCol; +} \ No newline at end of file diff --git a/ParticleGenerator/src/Interface/Generator/PathGeneratorInterface.cpp b/ParticleGenerator/src/Interface/Generator/PathGeneratorInterface.cpp index 6f712d1..aa38e0a 100644 --- a/ParticleGenerator/src/Interface/Generator/PathGeneratorInterface.cpp +++ b/ParticleGenerator/src/Interface/Generator/PathGeneratorInterface.cpp @@ -7,8 +7,8 @@ #include "../../Particle/generator/PathParticleGenerator.hpp" namespace pg { - PathGeneratorInterface::PathGeneratorInterface(PathParticleGenerator * generator) - : _generator(generator), _next(0.f, 0.f, 0.f), _index(0) {} + PathGeneratorInterface::PathGeneratorInterface(PathParticleGenerator * generator, Trajectory * trajectory) + : _generator(generator), _trajectory(trajectory), _next(0.f, 0.f, 0.f), _index(0) {} void PathGeneratorInterface::render(double) { if(ImGui::CollapsingHeader("Generator Information")) { @@ -58,6 +58,10 @@ namespace pg { else { this->_generator->m_controlPoints.insert(this->_generator->m_controlPoints.begin() + this->_index, static_cast<ct::Point>(this->_next)); } + + if(this->_trajectory != nullptr) { + this->_trajectory->update(); + } } ImGui::SameLine(); @@ -69,6 +73,10 @@ namespace pg { else { this->_generator->m_controlPoints.erase(this->_generator->m_controlPoints.begin() + this->_index); } + + if(this->_trajectory != nullptr) { + this->_trajectory->update(); + } } } } diff --git a/ParticleGenerator/src/Interface/Generator/PathGeneratorInterface.hpp b/ParticleGenerator/src/Interface/Generator/PathGeneratorInterface.hpp index 22a18f7..1ef335e 100644 --- a/ParticleGenerator/src/Interface/Generator/PathGeneratorInterface.hpp +++ b/ParticleGenerator/src/Interface/Generator/PathGeneratorInterface.hpp @@ -1,6 +1,7 @@ #pragma once #include "../Interface.hpp" +#include "../../Mesh/Trajectory.hpp" #include <glm/vec3.hpp> @@ -9,11 +10,12 @@ namespace pg { class PathGeneratorInterface : public Interface { private: PathParticleGenerator * _generator; + Trajectory * _trajectory; glm::vec3 _next; int _index; public: - PathGeneratorInterface(PathParticleGenerator *); + PathGeneratorInterface(PathParticleGenerator *, Trajectory * = nullptr); inline PathParticleGenerator * getGenerator() const {return this->_generator;} diff --git a/ParticleGenerator/src/Interface/Scene/PathSceneInterface.cpp b/ParticleGenerator/src/Interface/Scene/PathSceneInterface.cpp index 1a0f75a..7b1fb2f 100644 --- a/ParticleGenerator/src/Interface/Scene/PathSceneInterface.cpp +++ b/ParticleGenerator/src/Interface/Scene/PathSceneInterface.cpp @@ -8,7 +8,7 @@ namespace pg { PathSceneInterface::PathSceneInterface(scene::Path * scene) : _scene(scene), - _interface(&scene->_generator), + _interface(&scene->_generator, &scene->_trajectory), _max(1024), _spawnFrequence(500), _spawnCount(5), diff --git a/ParticleGenerator/src/Mesh/Trajectory.cpp b/ParticleGenerator/src/Mesh/Trajectory.cpp new file mode 100644 index 0000000..3d0845e --- /dev/null +++ b/ParticleGenerator/src/Mesh/Trajectory.cpp @@ -0,0 +1,76 @@ +#include "Trajectory.hpp" +#include <glm/gtc/matrix_transform.hpp> + +#include <CurveTools/CPU/CurveSampler.hpp> + +namespace pg { + Trajectory::Trajectory(PathParticleGenerator * generator, double increment) + : _generator(generator), _vbo(this->_vao, {layout::POSITION, layout::COLOR}), _increment(increment) {} + + void Trajectory::initialize() { + this->update(); + if(!this->_program.usable()) { + Source vert("res/shaders/system/Trajectory.vert", Source::Categorie::VERTEX); + Source frag("res/shaders/system/Trajectory.frag", Source::Categorie::FRAGMENT); + + this->_program << vert; + this->_program << frag; + + this->_program.link(); + + vert.release(); + frag.release(); + } + } + + void Trajectory::update() { + 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); + } + + std::vector<double> ps; + for(double i = 0.f; i < this->_generator->getGenerator()->getDegree(); i += this->_increment) { + ps.push_back(i); + } + + ct::Curve curve = ct::CurveSampler::sampleCurve(this->_generator->getControlPoint(), *this->_generator->getGenerator(), ps); + + for(auto & point : curve) { + traj.push_back(static_cast<float>(point.x)); + traj.push_back(static_cast<float>(point.y)); + traj.push_back(static_cast<float>(point.z)); + + traj.push_back(0.f); + traj.push_back(1.f); + traj.push_back(0.f); + } + + this->_vbo.set(traj); + } + + void Trajectory::draw(const Camera & camera, double current_time) { + this->_vao.bind(); + + glEnable(GL_PROGRAM_POINT_SIZE); + this->_program.use(); + this->_program.setUniform("uProj", camera.getViewFrustum().getProjectionMatrix()); + this->_program.setUniform("uView", camera.getViewMatrix()); + + GLsizei raw = static_cast<GLsizei>(this->_generator->getControlPoint().size()); + GLsizei total = this->_vbo.vertices(); + + glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(this->_generator->getControlPoint().size())); + glDrawArrays(GL_LINE_STRIP, raw, total - raw); + } + + void Trajectory::destroy() { + + } +} \ No newline at end of file diff --git a/ParticleGenerator/src/Mesh/Trajectory.hpp b/ParticleGenerator/src/Mesh/Trajectory.hpp new file mode 100644 index 0000000..2b7641f --- /dev/null +++ b/ParticleGenerator/src/Mesh/Trajectory.hpp @@ -0,0 +1,23 @@ +#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/Particle/generator/PathParticleGenerator.hpp b/ParticleGenerator/src/Particle/generator/PathParticleGenerator.hpp index 0f87412..312ca00 100644 --- a/ParticleGenerator/src/Particle/generator/PathParticleGenerator.hpp +++ b/ParticleGenerator/src/Particle/generator/PathParticleGenerator.hpp @@ -15,7 +15,7 @@ namespace pg { public: PathParticleGenerator(ct::CurveGenerator * generator, const ct::Curve& controlPoints, const ct::Point& position = ct::Point(), float positionVariation = 0.0); - inline const ct::CurveGenerator * getGenerator() const {return this->m_generator;} + inline ct::CurveGenerator * getGenerator() const {return this->m_generator;} inline const ct::Curve& getControlPoint() const {return this->m_controlPoints;} inline float getParameter() const {return this->m_u;} inline float getSpacing() const {return this->m_spacing;} diff --git a/ParticleGenerator/src/Scene/Scenes/Mesh.cpp b/ParticleGenerator/src/Scene/Scenes/Mesh.cpp index e6d4893..d60ced3 100644 --- a/ParticleGenerator/src/Scene/Scenes/Mesh.cpp +++ b/ParticleGenerator/src/Scene/Scenes/Mesh.cpp @@ -59,21 +59,12 @@ namespace pg::scene if(this->_skybox.material().isValid()) { this->_skybox.load( { -<<<<<<< Updated upstream "res/textures/skybox/snow/right.png", "res/textures/skybox/snow/left.png", "res/textures/skybox/snow/top.png", "res/textures/skybox/snow/bottom.png", "res/textures/skybox/snow/front.png", "res/textures/skybox/snow/back.png", -======= - "res/textures/skybox/sky/right.png", - "res/textures/skybox/sky/left.png", - "res/textures/skybox/sky/top.png", - "res/textures/skybox/sky/bottom.png", - "res/textures/skybox/sky/front.png", - "res/textures/skybox/sky/back.png", ->>>>>>> Stashed changes }, Texture::RGBA, false diff --git a/ParticleGenerator/src/Scene/Scenes/Path.cpp b/ParticleGenerator/src/Scene/Scenes/Path.cpp index fa55cb0..165a4ff 100644 --- a/ParticleGenerator/src/Scene/Scenes/Path.cpp +++ b/ParticleGenerator/src/Scene/Scenes/Path.cpp @@ -9,11 +9,13 @@ namespace pg::scene { _program(), _texture(), _generator(generator, ctrlpoint), + _trajectory(&this->_generator), _particles(), _interface(this) {} void Path::initialize() { this->_billboard.initialize(); + this->_trajectory.initialize(); if(!this->_program.usable()) { pg::Source vertices("res/shaders/scene/Billboard.vert", pg::Source::Categorie::VERTEX); pg::Source fragment("res/shaders/scene/Billboard.frag", pg::Source::Categorie::FRAGMENT); @@ -76,6 +78,8 @@ namespace pg::scene { const glm::mat4 VIEW_MATRIX = camera.getViewMatrix(); const glm::mat4 PROJECTION_MATRIX = camera.getViewFrustum().getProjectionMatrix(); + this->_trajectory.draw(camera, current_time); + std::vector<glm::mat4> models; for(auto & particle : this->_particles) { diff --git a/ParticleGenerator/src/Scene/Scenes/Path.hpp b/ParticleGenerator/src/Scene/Scenes/Path.hpp index 048bb5d..8e808ba 100644 --- a/ParticleGenerator/src/Scene/Scenes/Path.hpp +++ b/ParticleGenerator/src/Scene/Scenes/Path.hpp @@ -6,6 +6,7 @@ #include "../../Particle/generator/PathParticleGenerator.hpp" #include "../../Interface/Scene/PathSceneInterface.hpp" #include "../../Mesh/Billboard.hpp" +#include "../../Mesh/Trajectory.hpp" #include "../../System/Window.hpp" @@ -16,6 +17,7 @@ namespace pg::scene { Program _program; Billboard _billboard; + Trajectory _trajectory; Material _texture; PathParticleGenerator _generator; std::vector<std::unique_ptr<Particle>> _particles; diff --git a/ParticleGenerator/src/main.cpp b/ParticleGenerator/src/main.cpp index b7616f4..c712074 100644 --- a/ParticleGenerator/src/main.cpp +++ b/ParticleGenerator/src/main.cpp @@ -73,12 +73,14 @@ int main(int argc, const char * argv[]) { }); } - ct::BezierGenerator bezier; + ct::Curve ctrlPoints { { 10.f, 0.f, 0.f}, {-10.f, 0.f, 0.f} }; + ct::BezierGenerator bezier(ctrlPoints.size()); + pg::scene::Physic physicScene; pg::scene::MeshGenerator meshGeneratorScene; pg::scene::Path pathScene(&bezier, ctrlPoints); -- GitLab