Skip to content
Snippets Groups Projects
Commit d9095f70 authored by BATON Theau's avatar BATON Theau
Browse files

Add path curve trajecory viewer

parent 6cc24f1e
No related branches found
No related tags found
No related merge requests found
Showing
with 158 additions and 33 deletions
......@@ -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);
Point p1(-10.0, 0.0, 0.0);
Point p2(10.0, 1.0, 1.0);
BezierGenerator CRG(2);
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;
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) {
......
......@@ -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
......
#version 330 core
out vec4 FragColor;
in vec3 zCol;
void main() {
FragColor = vec4(zCol, 1.0);
}
\ No newline at end of file
#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
......@@ -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();
}
}
}
}
......
#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;}
......
......@@ -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),
......
#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
#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
......@@ -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;}
......
......@@ -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
......
......@@ -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) {
......
......@@ -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;
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment