-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlame.h
62 lines (48 loc) · 1.55 KB
/
Flame.h
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 PARTICLE_GENERATOR_H
#define PARTICLE_GENERATOR_H
#include <vector>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "tools/shader.h"
#include "tools/camera.h"
#include "tools/model.h"
#include "tools/Gshader.h"
#include <iostream>
// Represents a single particle and its state
struct Particle {
glm::vec2 Position, Velocity;
glm::vec4 Color;
GLfloat Life;
Particle() : Position(0.0f), Velocity(0.0f), Color(1.0f), Life(0.0f) { }
};
// ParticleGenerator acts as a container for rendering a large number of
// particles by repeatedly spawning and updating particles and killing
// them after a given amount of time.
class ParticleGenerator
{
public:
// Constructor
ParticleGenerator(Shader shader, Texture2D texture, GLuint amount);
// Update all particles
void Update(GLfloat dt, GameObject &object, GLuint newParticles, glm::vec2 offset = glm::vec2(0.0f, 0.0f));
// Render all particles
void Draw();
private:
// State
std::vector<Particle> particles;
GLuint amount;
// Render state
Shader shader;
Texture2D texture;
GLuint VAO;
// Initializes buffer and vertex attributes
void init();
// Returns the first Particle index that's currently unused e.g. Life <= 0.0f or 0 if no particle is currently inactive
GLuint firstUnusedParticle();
// Respawns particle
void respawnParticle(Particle &particle, GameObject &object, glm::vec2 offset = glm::vec2(0.0f, 0.0f));
};
#endif