From 5247c47e2b5f0c6df15679075eb3b375a7608b24 Mon Sep 17 00:00:00 2001 From: bobarna <barnabas.borcsok@gmail.com> Date: Wed, 3 Mar 2021 11:34:12 +0100 Subject: [PATCH] particle class and other stuff --- src/application.cpp | 1 - src/application.h | 1 + src/scene.cpp | 1 + src/scene.h | 1 - src/sph/sph_particle.cpp | 74 ++++++++++++++++- src/sph/sph_particle.h | 168 ++++++++++++++++++++++++++++++--------- src/sph/sph_system.cpp | 1 + src/sph/sph_system.h | 15 ++++ 8 files changed, 222 insertions(+), 40 deletions(-) create mode 100644 src/sph/sph_system.cpp create mode 100644 src/sph/sph_system.h diff --git a/src/application.cpp b/src/application.cpp index c32a513..a2e6d47 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -110,5 +110,4 @@ void Application::run() { glLoadIdentity(); //load identity matrix camera->glSetupCamera(); scene->render(); - } diff --git a/src/application.h b/src/application.h index 0e57061..45b638f 100644 --- a/src/application.h +++ b/src/application.h @@ -32,6 +32,7 @@ class Application { double time_since_last_frame; std::shared_ptr<Camera> camera = std::make_shared<Camera>(); + // TODO //boolean flag, indicates whether a screen capture event should be performed //on the next display event. diff --git a/src/scene.cpp b/src/scene.cpp index 4838952..84960c6 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -9,6 +9,7 @@ Scene::~Scene() { } void Scene::update(double dt) { + sph_simulaton return; } diff --git a/src/scene.h b/src/scene.h index d1a07d8..8841a87 100644 --- a/src/scene.h +++ b/src/scene.h @@ -10,7 +10,6 @@ class Scene { bool render; bool use_emitter; - std::shared_ptr<Scene> scene = std::make_shared<Scene>(); public: Scene(); ~Scene(); diff --git a/src/sph/sph_particle.cpp b/src/sph/sph_particle.cpp index c83c664..0a26eb2 100644 --- a/src/sph/sph_particle.cpp +++ b/src/sph/sph_particle.cpp @@ -1,3 +1,75 @@ #include "scene.h" -using namespace sph::Particl +using namespace sph::Particle; + +namespace sph { + Particle::Particle(): + radius(1), //TODO + radius_sqr(1*1), //TODO + m(1), + rho(1), + p(0), + fixed(false) + {} + + Particle::~Particle(){} + + // will need these for hashing + Particle::point_type min() const { + return Particle::point_type(x - Particle::point_type(radius)); + } + + Particle::point_type max() const { + return Particle::point_type(x + Particle::point_type(radius)); + } + + // checks if two particles (actually two positions) are within an + // allowed radius. + bool check(const point_type& candidate_pos) const{ + Particle::point_type diff(pos - candidate_pos); + return radius_sqrt >= diff*diff; + } + // Position + const point_type& position() const; + point_type& position(); + + //Old Position + const point_type& old_pos() const { return old_pos; } + point_type& old_pos() { return old_pos; } + + // Velocity + const vector &velocity() const { return v; } + vector &velocity() { return v; } + + // Acceleration + const vector &acceleration() const { return a; } + vector &acceleration() { return a; } + + // Force + const vector &force() const { return f; } + vector &force() { return f; } + + // Mass + const float &mass() const { return m; } + float &mass() { return m; } + + // Density + const float &density() const { return rho; } + float &density() { return rho; } + + // Pressure + const float &pressure() const { return p; } + float &pressure() { return p; } + + // Normal vector of the surface + const vector &normal() const { return n; } + vector &normal() { return n; } + + // Fixed flag of the particle + const bool &fixed() const { return fixed; } + bool &fixed() { return fixed; } + + // Radius of the particle + const float &radius() const { return radius; } + +} diff --git a/src/sph/sph_particle.h b/src/sph/sph_particle.h index ee0ad85..8e37c3b 100644 --- a/src/sph/sph_particle.h +++ b/src/sph/sph_particle.h @@ -1,44 +1,138 @@ -#ifndef MADID_SCENE_H -#define MADID_SCENE_H +#ifndef MADID_SPH_PARTICLE +#define MADID_SPH_PARTICLE #include <glm/glm.hpp> namespace sph { - class Particle { - public: - typedef glm::vec3 vector; - typedef vector point_type; - - Particle(); - private: - float radius; // radius of the particle - float radius_sqr; // squared radius of the particle - point_type pos; // position of the particle - point_type old_pos; // old position of the particle - vector v; // current velocity - vector a; // current acceleration - vector f; // current sum of external forces acting on the particle - vector n; // surface normal if close to/on the surface, else 0 - float m; // mass (constant) - float rho; // density (varies) - float p; // pressure (varies) - bool fixed; // Is this particled fixed (locked)? - public: - // will need these for hashing - point_type min() const; - point_type max() const; - - // checks if two particles (actually two positions) are within an - // allowed radius. - bool check(const point_type& candidate) const; - - // get position (read only) - const point_type& position() const; - // get position - point_type& position(); - - - } +class Particle { + public: + typedef glm::vec3 vector; + typedef vector point_type; + + Particle(); + private: + float radius; // radius of the particle + float radius_sqr; // squared radius of the particle + point_type pos; // position of the particle + point_type old_pos; // old position of the particle + vector v; // current velocity + vector a; // current acceleration + vector f; // current sum of external forces acting on the particle + vector n; // surface normal if close to/on the surface, else 0 + float m; // mass (constant) + float rho; // density (varies) + float p; // pressure (varies) + bool fixed; // Is this particled fixed (locked)? + public: + // will need these for hashing + point_type min() const; + point_type max() const; + + // checks if two particles (actually two positions) are within an + // allowed radius. + bool check(const point_type& candidate) const; + + // get position (read only) + const point_type& position() const; + // get position + point_type& position(); + + /** Old Position (read only). + * @return const reference to the old position vector. + */ + const point_type& old_pos() const; + + /** Old Position. + * @return reference to the old position vector. + */ + point_type& old_pos(); + + /** Velocity (read only). + * @return const reference to the velocity vector. + */ + const vector &velocity() const; + + /** Velocity. + * @return reference to the velocity vector. + */ + vector &velocity(); + + /** Acceleration (read only). + * @return const reference to the acceleration vector. + */ + const vector &acceleration() const; + + /** Acceleration. + * @return reference to the acceleration vector. + */ + vector &acceleration(); + + /** Force (read only). + * @return const reference to the external force vector. + */ + const vector &force() const; + + /** Force. + * @return reference to the external force vector. + */ + vector &force(); + + /** Mass (read only). + * @return const reference to the mass scalar. + */ + const float &mass() const; + + /** Mass. + * @return reference to the mass scalar. + */ + float &mass(); + + /** Density (read only). + * @return const reference to the density value. + */ + const float &density() const; + + /** Density. + * @return reference to the density value. + */ + float &density(); + + /** Pressure (read only). + * @return const reference to the pressure value. + */ + const float &pressure() const; + + /** Pressure. + * @return reference to the pressure value. + */ + float &pressure(); + + /** Normal (read only). + * @return const reference to the surface normal. + */ + const vector &normal() const; + + /** Normal. + * @return reference to the surface normal. + */ + vector &normal(); + + /** Fixed (read only). + * @return const reference to the surface normal. + */ + const bool &fixed() const; + + /** Fixed. + * @return reference to the surface normal. + */ + bool &fixed(); + + /** Fixed. + * @return reference to the surface normal. + */ + const float &radius() const; + +} } #endif diff --git a/src/sph/sph_system.cpp b/src/sph/sph_system.cpp new file mode 100644 index 0000000..5b4056c --- /dev/null +++ b/src/sph/sph_system.cpp @@ -0,0 +1 @@ +#include "sph_system.h" diff --git a/src/sph/sph_system.h b/src/sph/sph_system.h new file mode 100644 index 0000000..b11b730 --- /dev/null +++ b/src/sph/sph_system.h @@ -0,0 +1,15 @@ +#ifndef MADID_SPH_SYSTEM +#define MADID_SPH_SYSTEM + +#include <glm/glm.hpp> +#include "sph_particle.h" + +namespace sph { + class System { + // particle container + // collision system + // l + } +} + +#endif -- GitLab