summaryrefslogtreecommitdiff
path: root/src/particlesystem.h
blob: 26cb3f4b0e55e776bd4e87d7eb66ce6790647d0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#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 *shader, Camera  m_camera, GLuint texture);

    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 = 50.f;
    std::vector<float> m_vertices = {
        -d, d, 0,1,
        -d, -d, 0, 0,
        d,d, 1,1,
        //
        d,d, 1,1,
        -d, -d, 0, 0,

        d, -d, 1, 0
    };

    GLuint VAO, VBO; // holds quad shape






    std::vector<Particle> m_particles;

    std::vector<OceanSpray> m_verts;

};

#endif // PARTICLESYSTEM_H