diff options
author | Sebastian Park <SebPark03@gmail.com> | 2024-05-10 04:09:10 -0400 |
---|---|---|
committer | Sebastian Park <SebPark03@gmail.com> | 2024-05-10 04:09:10 -0400 |
commit | 487b0874e1fbb891e5ecf5721bd05814b0c0572d (patch) | |
tree | 99f394d3776f3094294097e262d711cd1a5acc89 /src/particlesystem.h | |
parent | ee06bfd66ebc0d0d9d88bb9cb69b7cb350e3cfe2 (diff) | |
parent | b4ca8b708587c540233284beae8d42ff43092580 (diff) |
Merge branch 'main' of https://github.com/Seb-Park/ocean-simulation
Diffstat (limited to 'src/particlesystem.h')
-rw-r--r-- | src/particlesystem.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/particlesystem.h b/src/particlesystem.h new file mode 100644 index 0000000..d3b0b8f --- /dev/null +++ b/src/particlesystem.h @@ -0,0 +1,84 @@ + +#ifndef PARTICLESYSTEM_H +#define PARTICLESYSTEM_H + +#include "ocean/ocean_alt.h" +#include <iostream> +#define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT +#define EIGEN_DONT_VECTORIZE +#include "graphics/shader.h" +#include "graphics/camera.h" + +#include <Eigen/Core> +#include <Eigen/Dense> +#include <Eigen/Sparse> +#include <Eigen/Geometry> + +struct Particle{ + Eigen::Vector3f pos = Eigen::Vector3f(0,0,0); + Eigen::Vector3f vel = Eigen::Vector3f(0,2000,0); + + Eigen::Vector4f color = Eigen::Vector4f(1,1,1,1); + float life = 1.f; + +}; + +class particlesystem +{ +public: + particlesystem(); + + void update(double deltaTime); + void draw(Shader *skybox_shader, Camera m_camera); + void draw(Shader *shader, Camera m_camera, std::vector<Eigen::Vector3f> verts, Eigen::Matrix4f model); + + void init(std::vector<OceanSpray> verts); + + void setVerts(std::vector<OceanSpray> verts){ + //std::cout << "VERTS SIZE:" << verts.size() << std::endl; + m_verts = verts; + + } + + + +private: + int m_amount = 500; + int m_new_amount = 100; // new particles per frame + int lastUsedIndex = 0; + Eigen::Vector3f gravity = Eigen::Vector3f(0,-9.81f,0); + float factor = 40.f; // velocity multiplier + + + + void respawn_particle(Particle &p, OceanSpray new_pos); + int getUnusedParticleIndex(); + Eigen::Vector3f getRandomInitialVel(); + + + + + float d = 2.f; + std::vector<float> m_vertices = { + -d, d, + d,d, + -d, -d, + d, d, + d, -d, + -d, -d + }; + + GLuint VAO, VBO; // holds quad shape + + + + + + + std::vector<Particle> m_particles; + + std::vector<OceanSpray> m_verts; + +}; + +#endif // PARTICLESYSTEM_H |