aboutsummaryrefslogtreecommitdiff
path: root/09-september/tomcat/particles/particles.h
blob: 8404ff4663865d3ceda13404bdf3f812a20bc746 (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
#ifndef PARTICLES_H
#define PARTICLES_H

#include "../renderer/renderer_types.h"
#include "../math/vector.h"

#define MAX_PARTICLES_PER_SYSTEM 10000
#define MAX_PARTICLES_SYSTEMS 10

typedef struct _Particle
{
    Vec3 position;
    Vec3 velocity;

    Vec2 tex_offset; /* Used for animating */

    GLfloat weight; /* How does the gravity affect the particle (In theory it should be a vector)*/
    GLfloat life_length;
    GLfloat rotation;
    GLfloat scale;
    GLfloat distance_to_camera; /* Used for sorting the systems */

    GLfloat elapsed_time;
} Particle;

typedef struct _ParticleSystem
{
    Vec3 position;

    GLint emit_rate;
    GLfloat speed;
    GLfloat weight;
    GLfloat life_length;

    bool additive; /* Additive vs alpha blending */

    Texture *texture;
    Particle particles[MAX_PARTICLES_PER_SYSTEM];
    int num_particles;

} ParticleSystem;

typedef struct
{
    ParticleSystem *systems[MAX_PARTICLES_SYSTEMS];
    int num_systems;
} ParticleManager;

extern ParticleManager particles;

extern void Particles_Init();

extern ParticleSystem *Particles_AddSystem();
extern void Particles_RemoveSystem(ParticleSystem *system);
/* Used for manual emission */
extern void Particles_EmitParticle(ParticleSystem *system, Particle *p);
/* Removes a particle if it "dies" */
extern void Particles_Update(const Vec3 *camera_position);
/* We need to delete all dynamically allocated particles that still remains */
extern void Particles_Shutdown();

#endif // PARTICLES_H