diff --git a/CurveTools/src/main.cu b/CurveTools/src/main.cu index aa0c319d7a3d9c78581d873cdbad1335474d771e..7f486028ab6ad310025f7bb3bf6d30edb6b286ec 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 857dd7793fa281face64e343a2a5561b0a2e628f..45a8953599b8ae2927ceb638ffa6dd824a8131ba 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 0000000000000000000000000000000000000000..ea75c60148635aa319922bded8144a2f01c31670 --- /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 0000000000000000000000000000000000000000..d8aa6a99e53e9ae8ac32d80c77d567a88570186d --- /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 6f712d1ad71f0c45630d7c0618dc5963f4d895a1..aa38e0ae1c1077d9873dc20acae74e0d43af6245 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 22a18f76338202c8b099f7d743588acca15bac09..1ef335e3b43bb8dfe933db2bea95313deb72ffb9 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 1a0f75a977214ef561d0307d1a0809e6f00466e7..7b1fb2fb4ddb7c63b3a9b225e3f9fb1abd45cc07 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 0000000000000000000000000000000000000000..3d0845e5574661945642a2d5e75da1988a7ed349 --- /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 0000000000000000000000000000000000000000..2b7641f6258721f7f5bd78b14109f902c6728e08 --- /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 0f874123906c40d96f8ea480d2475aa8305754a4..312ca00c762c250e4bbffac5699d4a30129f8ed7 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 e6d48935d43a2c98e1e8400559d2f47a51d26183..d60ced35bf1f2cf5731f3f55aca35e0c69b14e82 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 fa55cb0a0076a10faa17cdcc7ed32f70aaef7e26..165a4ff5093d69e36120bc9dd929baec1875e794 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 048bb5d934ee25d4ee150d3fe22ee779f2c2bd3f..8e808ba2aea80b476c58a6e4aa02ce1b5732ad73 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 b7616f4a502be75a9a695e119fd45ed71879850a..c7120740630bef3c0ed296750847bda9c82ec490 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);