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

Correct multiple trajectory

parent 615ef657
No related branches found
No related tags found
No related merge requests found
Showing
with 310 additions and 56 deletions
......@@ -3,10 +3,10 @@ Pos=60,60
Size=400,400
[Window][Dear ImGui Demo]
Pos=1131,67
Pos=1021,19
Size=550,680
[Window][Particle Generator]
Pos=65,78
Size=455,596
Pos=60,60
Size=553,820
......@@ -6,10 +6,11 @@ out vec3 zCol;
uniform mat4 uProj;
uniform mat4 uView;
uniform mat4 uModel;
uniform float uPointSize;
void main() {
gl_Position = uProj * uView * vec4(aPos, 1.0);
gl_Position = uProj * uView * uModel * vec4(aPos, 1.0);
gl_PointSize = uPointSize;
zCol = aCol;
}
\ No newline at end of file
ParticleGenerator/res/textures/gray.png

138 B

#pragma once
#include "PathMultyGenerator.hpp"
#include <imgui.h>
#include "../../Particle/generator/PathMultyGenerator.hpp"
namespace pg::interface {
PathMultyGenerator::PathMultyGenerator(particle::PathMultyGenerator * parent, scene::TrajectoryMulty * trajectory)
: Generator(parent),
_trajectory(trajectory),
_next(0.f, 0.f, 0.f),
_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("Default u : %f", this->parent()->m_u);
ImGui::Text("u increment : %f", this->parent()->m_increment);
ImGui::Text("Spacing : %f", this->parent()->m_spacing);
ImGui::Text("Life Limitor : %f", this->parent()->m_limitor);
if(ImGui::CollapsingHeader("Generator Position")) {
ImGui::DragFloat3("Generator Position (x, y, z)", &this->parent()->m_position[0], 0.1f);
ImGui::SliderFloat3("Generator Roation (x, y, z)", &this->parent()->m_rotation[0], -360.f, 360.f);
ImGui::DragFloat("Position Variation", &this->parent()->m_positionVariation, 0.001f, 0.f, 0.f, "%.4f");
}
if(ImGui::CollapsingHeader("Parameter")) {
ImGui::InputFloat("Parameter Default Value", &this->parent()->m_u, 0.1f, 0.5f);
ImGui::DragFloat("Parameter Increment Value", &this->parent()->m_increment, 0.01f);
ImGui::DragFloat("Spacing", &this->parent()->m_spacing, 0.001f);
ImGui::InputFloat("Life Limitor", &this->parent()->m_limitor, 1.0f, 2.0f);
}
if(ImGui::CollapsingHeader("Control Points")) {
for(size_t i = 0; i < this->parent()->m_controlPoints.size(); ++i) {
glm::vec3 current = static_cast<glm::vec3>(this->parent()->m_controlPoints[i]);
ImGui::Text("%i : %f / %f / %f.", i, current.x, current.y, current.z);
}
ImGui::InputFloat3("", &this->_next[0]);
ImGui::InputInt("Index", &this->_index, 1, 2);
if(this->_index < 0) {
ImGui::TextColored(ImVec4(0.75f, 0.f, 0.f, 1.f), "Negative index !");
}
else {
if(this->_index > this->parent()->getControlPoint().size()) {
ImGui::TextColored(ImVec4(1.f, 1.f, 0.f, 1.f), "Index out of range, new point will be at the back !");
}
if(ImGui::Button("Push Point")) {
if(this->_index > this->parent()->getControlPoint().size()) {
this->parent()->m_controlPoints.push_back(static_cast<ct::Point>(this->_next));
}
else {
this->parent()->m_controlPoints.insert(this->parent()->m_controlPoints.begin() + this->_index, static_cast<ct::Point>(this->_next));
}
if(this->_trajectory != nullptr) {
this->_trajectory->update(current_time);
}
}
ImGui::SameLine();
if(ImGui::Button("Pop Point")) {
if(this->_index > this->parent()->getControlPoint().size()) {
this->parent()->m_controlPoints.pop_back();
}
else {
this->parent()->m_controlPoints.erase(this->parent()->m_controlPoints.begin() + this->_index);
}
if(this->_trajectory != nullptr) {
this->_trajectory->update(current_time);
}
}
}
}*/
ImGui::Text("Path Multy Generator : %i", this->parent());
if(this->_trajectory->interface().has_value()) {
(*this->_trajectory->interface())->draw(current_time);
}
}
}
#pragma once
#include "../Interface.hpp"
#include "../../Scene/Scenes/TrajectoryMulty.hpp"
#include <glm/vec3.hpp>
namespace pg::particle {
class PathMultyGenerator;
}
namespace pg::interface {
class PathMultyGenerator : public Generator<particle::PathMultyGenerator> {
private:
scene::TrajectoryMulty * _trajectory;
glm::vec3 _next;
int _index;
public:
PathMultyGenerator(particle::PathMultyGenerator *, scene::TrajectoryMulty * = nullptr);
virtual ~PathMultyGenerator() = default;
void draw(double) override;
virtual inline std::string title() const {return "Path Generator Interface";}
};
}
\ No newline at end of file
......@@ -43,16 +43,18 @@ namespace pg::interface {
if(ImGui::CollapsingHeader("Variation")) {
ImGui::SeparatorText("Velocity");
ImGui::DragFloat3("Upper Boundary (x, y, z)", &this->parent()->m_velocityVariation.upper[0], 0.0001f, 0.f, 0.f, "%.4f");
ImGui::DragFloat3("Lower Boundary (x, y, z)", &this->parent()->m_velocityVariation.lower[0], 0.0001f, 0.f, 0.f, "%.4f");
ImGui::DragFloatRange2("x", &this->parent()->m_velocityVariation.lower.x, &this->parent()->m_velocityVariation.upper.x, 0.0001f, 0.f, 0.f, "%.4f");
ImGui::DragFloatRange2("y", &this->parent()->m_velocityVariation.lower.y, &this->parent()->m_velocityVariation.upper.y, 0.0001f, 0.f, 0.f, "%.4f");
ImGui::DragFloatRange2("z", &this->parent()->m_velocityVariation.lower.z, &this->parent()->m_velocityVariation.upper.z, 0.0001f, 0.f, 0.f, "%.4f");
ImGui::SeparatorText("Acceleration");
ImGui::PushID(1);
ImGui::DragFloat3("Upper Boundary (x, y, z)", &this->parent()->m_accelerationVariation.upper[0], 0.0001f, 0.f, 0.f, "%.4f");
ImGui::DragFloat3("Lower Boundary (x, y, z)", &this->parent()->m_accelerationVariation.lower[0], 0.0001f, 0.f, 0.f, "%.4f");
ImGui::DragFloatRange2("x", &this->parent()->m_accelerationVariation.lower.x, &this->parent()->m_accelerationVariation.upper.x, 0.0001f, 0.f, 0.f, "%.4f");
ImGui::DragFloatRange2("y", &this->parent()->m_accelerationVariation.lower.y, &this->parent()->m_accelerationVariation.upper.y, 0.0001f, 0.f, 0.f, "%.4f");
ImGui::DragFloatRange2("z", &this->parent()->m_accelerationVariation.lower.z, &this->parent()->m_accelerationVariation.upper.z, 0.0001f, 0.f, 0.f, "%.4f");
ImGui::PopID();
ImGui::SeparatorText("Friction");
ImGui::DragFloat3("Variation", &this->parent()->m_frictionVariation[0], 0.0001f, 0.f, 0.f, "%.4f");
ImGui::DragFloat3("x y z", &this->parent()->m_frictionVariation[0], 0.001f, 0.f, 0.f, "%.4f");
}
ImGui::Text("Physic Generator : %i", this->parent());
}
}
#include "MultyPath.hpp"
#include <imgui.h>
#include "../../Scene/Scenes/MultyPath.hpp"
#include "../../tfd/tinyfiledialogs.h"
namespace pg::interface {
MultyPath::MultyPath(scene::MultyPath * parent, particle::PathMultyGenerator * generator, scene::TrajectoryMulty * trajectory)
: Scene(parent), SceneParticle(parent), _interface(generator, trajectory) {}
void MultyPath::draw(double current_time) {
SceneParticle::draw(current_time);
/*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);
}
ImGui::SameLine();
ImGui::ColorEdit4("Color", &this->parent()->_color[0]);
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
#pragma once
#include "../Interface.hpp"
#include "SceneParticle.hpp"
#include "../Generator/PathMultyGenerator.hpp"
#include "../../Particle/generator/PathMultyGenerator.hpp"
#include "../../Scene/Scenes/TrajectoryMulty.hpp"
#include <glm/vec4.hpp>
namespace pg::scene {
class MultyPath;
}
namespace pg::interface {
class MultyPath : public Scene<scene::MultyPath>, public SceneParticle {
private:
PathMultyGenerator _interface;
public:
MultyPath(scene::MultyPath *, particle::PathMultyGenerator *, pg::scene::TrajectoryMulty * = nullptr);
virtual ~MultyPath() = default;
virtual void draw(double);
inline std::string title() const override final {return "Path Scene Interface";}
};
}
\ No newline at end of file
......@@ -8,10 +8,22 @@ namespace pg::interface {
Trajectory::Trajectory(scene::Trajectory * parent)
: Scene(parent) {}
void Trajectory::draw(double) {
void Trajectory::draw(double current_time) {
ImGui::ColorEdit4("Curve Color", &this->parent()->_color[0]);
ImGui::SliderFloat("Point Size", &this->parent()->_pointSize, 1.f, 512.f);
ImGui::SliderFloat("Line Size", &this->parent()->_lineSize, 1.f, 512.f);
ImGui::Checkbox("Show Control Line", &this->parent()->_controlLine);
ImGui::Checkbox("Enable Render", &this->parent()->_enableRender);
ImGui::Separator();
ImGui::Checkbox("Enable Control Line", &this->parent()->_controlLine);
ImGui::Checkbox("Enable Control Point", &this->parent()->_enableControl);
ImGui::Checkbox("Enable Curve Line", &this->parent()->_enableLine);
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
#include "TrajectoryMulty.hpp"
#include <imgui.h>
#include "../../Scene/Scenes/TrajectoryMulty.hpp"
namespace pg::interface {
TrajectoryMulty::TrajectoryMulty(scene::TrajectoryMulty * parent)
: 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);
}
}*/
size_t color_nb = this->parent()->_colors.size();
size_t i = 0;
for(auto &[name, generator] : this->parent()->_generators->getGenerators()) {
size_t index = i%color_nb;
ImGui::Text("%s : ", name.c_str());
ImGui::SameLine();
if(ImGui::ColorEdit4("", &this->parent()->_colors.at(index)[0])) {
this->parent()->update(current_time);
}
++i;
}
ImGui::Text("Trajectory Multy : %i", this->parent());
}
}
\ No newline at end of file
#pragma once
#include "../Interface.hpp"
namespace pg::scene {
class TrajectoryMulty;
}
namespace pg::interface {
class TrajectoryMulty : public Scene<scene::TrajectoryMulty> {
public:
TrajectoryMulty(scene::TrajectoryMulty *);
virtual void draw(double = 0.0);
inline std::string title() const override final {return "Trajectory Multy Interface";}
};
}
\ No newline at end of file
......@@ -7,5 +7,5 @@ namespace pg::particle {
: Particle(0, position) {}
Particle::Particle(size_t born, const ct::Point& position)
: m_position(position), m_born(born) {}
: m_born(born) {}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@
#include <CurveTools/CPU/CurveGenerator.hpp>
#include <glm/mat4x4.hpp>
#include <glm/gtc/matrix_transform.hpp>
namespace pg::particle
{
......@@ -13,27 +14,25 @@ namespace pg::particle
{
private:
size_t m_born;
ct::Point m_position;
glm::mat4 m_model;
public:
glm::mat4 _model = glm::mat4(1.f);
Particle(const ct::Point& position = ct::Point());
Particle(size_t born, const ct::Point& position = ct::Point());
virtual ~Particle() = default;
inline size_t getBorn() const {return this->m_born;}
inline ct::Point getPosition() const {return this->m_position;}
inline const glm::mat4 & getModel() const {return this->m_model;}
inline bool isDead(size_t current_time, size_t max_time) const {return (current_time - this->m_born) > max_time;}
inline void setBorn(size_t born) {this->m_born = born;}
inline void setPosition(const ct::Point& position) {this->m_position = position;}
inline void setModel(const glm::mat4 & model) {this->m_model = model;}
inline void translate(const ct::Point& position) {this->m_position += position;}
inline void translate(const ct::Point& position) {this->m_model = glm::translate(m_model, glm::vec3(position));}
virtual void update(double = 0.0) = 0;
inline friend bool operator==(const Particle & p1, const Particle & p2) {return p1.m_position == p2.m_position && p1.m_born == p2.m_born;}
inline friend bool operator==(const Particle & p1, const Particle & p2) {return p1.m_model == p2.m_model && p1.m_born == p2.m_born;}
inline friend bool operator!=(const Particle & p1, const Particle & p2) {return !(p1 == p2);}
inline friend bool operator>(const Particle & p1, const Particle & p2) {return p1.m_born > p2.m_born;}
......
......@@ -2,12 +2,15 @@
#include <iostream>
#include <glm/mat4x4.hpp>
namespace pg::particle {
Path::Path(ct::CurveGenerator* generator, const ct::Curve& path, double u, double inc)
: Particle(), m_generator(generator), m_ctrlPoints(path), m_positionVariation(), m_u(u), m_increment(inc), m_limitor(0.0)
{
if(!path.empty()) {
this->setPosition(this->m_ctrlPoints.at(0));
this->setModel(glm::mat4(1.f));
this->translate(this->m_ctrlPoints.at(0));
}
}
......@@ -26,6 +29,7 @@ namespace pg::particle {
return;
}
this->setPosition(this->m_generator->operator()(this->m_ctrlPoints, this->m_u) + this->m_positionVariation);
this->setModel(glm::mat4(1.f));
this->translate(this->m_generator->generate(this->m_ctrlPoints, this->m_u) + this->m_positionVariation);
}
}
......@@ -12,8 +12,6 @@ namespace pg::particle {
void Physics::update(double t) {
m_acceleration -= static_cast<glm::dvec3>(m_friction) * m_velocity;
m_velocity += m_acceleration;
//this->translate(this->m_velocity);
this->_model = glm::translate(this->_model, glm::vec3(this->m_velocity));
this->translate(this->m_velocity);
}
}
\ No newline at end of file
......@@ -14,20 +14,28 @@ namespace pg::particle {
float m_positionVariation;
glm::vec3 m_position;
glm::vec3 m_rotation;
glm::mat4 m_model;
public:
glm::mat4 _model = glm::mat4(1.f);
Generator(const glm::vec3& position = glm::vec3(0.f), float positionVariation = 0.0)
: m_position(position), m_positionVariation(positionVariation), m_rotation(0.0) {}
: m_position(position), m_positionVariation(positionVariation), m_rotation(0.0), m_model(1.f) {}
inline float getPositionVariation() const {return this->m_positionVariation;}
inline glm::vec3 getPosition() const {return this->m_position;}
inline glm::vec3 getRotation() const {return this->m_rotation;}
inline glm::mat4 getModel() const {return this->m_model;}
inline void setPositionVariation(float positionVariation) {this->m_positionVariation = positionVariation;}
inline void setPosition(const glm::vec3& position) {this->m_position = position;}
inline void setRotation(const glm::vec3& rotation) {this->m_rotation = rotation;}
inline void setModel(const glm::mat4 & model) {this->m_model = model;}
inline void translate(const glm::vec3 & position) {this->m_model = glm::translate(this->m_model, position);}
inline void rotate(const glm::vec3 & rotation) {
this->m_model = glm::rotate(this->m_model, glm::radians(rotation.z), {0.f, 0.f, 1.f});
this->m_model = glm::rotate(this->m_model, glm::radians(rotation.y), {0.f, 1.f, 0.f});
this->m_model = glm::rotate(this->m_model, glm::radians(rotation.x), {1.f, 0.f, 0.f});
}
virtual std::vector<std::unique_ptr<T>> generate(size_t count, size_t birth = 0) const = 0;
inline std::vector<std::unique_ptr<T>> operator()(size_t count, size_t birth = 0) const {return this->generate(count, birth);}
......
......@@ -45,8 +45,6 @@ namespace pg::particle
for (size_t i = 0; i < count; ++i) {
Physics * particle = new Physics(birth, this->getPosition());
//particle->translate({p(randomEngine), p(randomEngine), p(randomEngine)});
glm::vec3 velocityVariation = {vx(randomEngine), vy(randomEngine), vz(randomEngine)};
glm::vec3 accelerationVariation = {ax(randomEngine), ay(randomEngine), az(randomEngine)};
glm::vec3 frictionVariation = {fx(randomEngine), fy(randomEngine), fz(randomEngine)};
......@@ -71,8 +69,8 @@ namespace pg::particle
particle->setAcceleration(realAcceleration);
particle->setFriction(realFriction);
particle->_model = this->_model;
particle->_model = glm::translate(particle->_model, {p(randomEngine), p(randomEngine), p(randomEngine)});
particle->setModel(this->getModel());
particle->translate(this->m_position + glm::vec3(p(randomEngine), p(randomEngine), p(randomEngine)));
particles.push_back(std::unique_ptr<Physics>(particle));
}
......
......@@ -124,10 +124,8 @@ namespace pg::scene {
while(particle_accumulator < this->_particles.size()) {
std::vector<glm::mat4> models;
for(size_t i = 0; i < this->_particles.size() && i < 1024; i++) {
//glm::mat4 model = glm::mat4(1.0);
if(i + particle_accumulator < this->_particles.size()) {
//model = glm::translate(model, glm::vec3(this->_particles[particle_accumulator + i]->getPosition()));
models.push_back(this->_particles[particle_accumulator + i]->_model);
models.push_back(this->_particles[particle_accumulator + i]->getModel());
}
}
......@@ -192,16 +190,9 @@ namespace pg::scene {
void MeshGenerator::spawn(int count, double current_time) {
for(auto & generator : this->_generators) {
//? #####
generator._model = glm::mat4(1.f);
generator._model = glm::rotate(generator._model, glm::radians(this->_meshRotation.z), {0.f, 0.f, 1.f});
generator._model = glm::rotate(generator._model, glm::radians(this->_meshRotation.y), {0.f, 1.f, 0.f});
generator._model = glm::rotate(generator._model, glm::radians(this->_meshRotation.x), {1.f, 0.f, 0.f});
generator._model = glm::translate(generator._model, generator.getPosition() + this->_meshPosition);
//? #####
generator.setModel(glm::mat4(1.f));
generator.rotate(this->_meshRotation);
generator.translate(generator.getPosition() + this->_meshPosition);
if((count + this->_particles.size()) <= this->getMaxParticles()) {
std::vector<std::unique_ptr<particle::Physics>> newParticles = generator.generate(count, static_cast<size_t>(current_time));
......
......@@ -42,7 +42,7 @@ namespace pg::scene {
frag.release();
}
this->_meshParticleTexture.load("res/textures/smoke1.png");
this->_meshParticleTexture.load("res/textures/gray.png");
if(!this->_meshParticleProgram.usable()) {
Source vert("res/shaders/scene/Texture-Fat.vert", Source::Categorie::VERTEX);
......@@ -95,6 +95,7 @@ namespace pg::scene {
}
void MeshGeneratorModel::render(const Camera & camera, double current_time) {
glEnable(GL_DEPTH_TEST);
const glm::mat4 VIEW_MATRIX = camera.getViewMatrix();
const glm::mat4 PROJECTION_MATRIX = camera.getViewFrustum().getProjectionMatrix();
......@@ -120,10 +121,8 @@ namespace pg::scene {
while(particle_accumulator < this->_particles.size()) {
std::vector<glm::mat4> models;
for(size_t i = 0; i < this->_particles.size() && i < 1024; i++) {
glm::mat4 model = glm::mat4(1.0);
if(i + particle_accumulator < this->_particles.size()) {
model = glm::translate(model, glm::vec3(this->_particles[particle_accumulator + i]->getPosition()));
models.push_back(model);
models.push_back(this->_particles[particle_accumulator + i]->getModel());
}
}
......@@ -151,7 +150,7 @@ namespace pg::scene {
particle_accumulator += 1024;
}
// --------
glDisable(GL_DEPTH_TEST);
}
void MeshGeneratorModel::destroy() {
......@@ -193,6 +192,10 @@ namespace pg::scene {
void MeshGeneratorModel::spawn(int count, double current_time) {
for(auto & generator : this->_generators) {
generator.setModel(glm::mat4(1.f));
generator.rotate(this->_meshRotation);
generator.translate(generator.getPosition() + this->_meshPosition);
if((count + this->_particles.size()) <= this->getMaxParticles()) {
std::vector<std::unique_ptr<particle::Physics>> 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()));
......
......@@ -14,7 +14,8 @@ namespace pg::scene {
_program(),
_texture(),
_generator(ctrlpoint),
_trajectory(&this->_generator) {
_trajectory(&this->_generator),
_interface(this, &this->_generator, &this->_trajectory) {
this->_generator.add("Bezier", new ct::BezierGenerator());
this->_generator.add("Catmull-Rom", new ct::CatmullRomGenerator());
this->_generator.add("Linear", new ct::LinearGenerator());
......@@ -92,9 +93,7 @@ namespace pg::scene {
std::vector<glm::mat4> models;
for(auto & particle : this->_particles) {
glm::mat4 model = glm::mat4(1.0);
model = glm::translate(model, glm::vec3(particle->getPosition()));
models.push_back(model);
models.push_back(particle->getModel());
}
pg::error::OpenGLError::check();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment