Brenta Engine 1.1
Loading...
Searching...
No Matches
particles.hpp
1/*
2 * MIT License
3 *
4 * Copyright (c) 2024 Giovanni Santini
5
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 */
26
27#pragma once
28
29#define MAX_PARTICLES 1000
30
31#include "camera.hpp"
32#include "vao.hpp"
33
34#include <glad/glad.h> /* OpenGL driver */
35#include <glm/glm.hpp>
36#include <glm/gtc/matrix_transform.hpp>
37#include <glm/gtc/type_ptr.hpp>
38#include <string>
39#include <vector>
40
41namespace brenta
42{
43
54{
55 public:
67 glm::vec3 starting_spread;
83 float scale;
98 int atlas;
115
139 glm::vec3 starting_spread, float starting_timeToLive,
140 int num_particles, float spawn_rate, float scale,
141 std::string atlas_path, int atlas_width, int atlas_height,
142 int atlas_index, camera *cam);
147
151 class builder;
152
158 void update_particles(float deltaTime);
162 void render_particles();
163
164 private:
165 camera *cam;
166 void check_opengl_error(const std::string &functionName);
167};
168
173{
174 private:
175 glm::vec3 starting_position = glm::vec3(0.0f, 0.0f, 0.0f);
176 glm::vec3 starting_velocity = glm::vec3(0.0f, 0.0f, 0.0f);
177 glm::vec3 starting_spread = glm::vec3(0.0f, 0.0f, 0.0f);
178 float starting_time_to_live = 1.0f;
179 int num_particles = MAX_PARTICLES;
180 float spawn_rate = 0.01f;
181 float scale = 1.0f;
182 std::string atlas_path = "";
183 int atlas_width = 8;
184 int atlas_height = 8;
185 int atlas_index = 0;
186 camera *cam = nullptr;
187
188 public:
189 builder &set_starting_position(glm::vec3 starting_position);
190 builder &set_starting_velocity(glm::vec3 starting_velocity);
191 builder &set_starting_spread(glm::vec3 starting_spread);
192 builder &set_starting_time_to_live(float starting_time_to_live);
193 builder &set_num_particles(int num_particles);
194 builder &set_spawn_rate(float spawn_rate);
195 builder &set_scale(float scale);
196 builder &set_atlas_path(std::string atlas_path);
197 builder &set_atlas_width(int atlas_width);
198 builder &set_atlas_height(int atlas_height);
199 builder &set_atlas_index(int atlas_index);
200 builder &set_camera(camera *cam);
201
202 particle_emitter build();
203};
204
205} // namespace brenta
The Camera class.
Definition camera.hpp:148
Builder pattern for ParticleEmitter.
ParticleEmitter class.
Definition particles.hpp:54
int current
Current fbo index.
Definition particles.hpp:94
void render_particles()
Render the particles.
glm::vec3 starting_velocity
Starting velocity of a new particle.
Definition particles.hpp:63
types::vao vao
Vertex array object.
int atlas
Atlas texture.
Definition particles.hpp:98
~particle_emitter()
Destroy the ParticleEmitter object.
float starting_time_to_live
Time to live of a new particle.
Definition particles.hpp:71
particle_emitter()
Empty constructor.
Definition particles.cpp:40
types::buffer fbo[2]
Feddback buffer objects.
Definition particles.hpp:90
float scale
Scale of particles.
Definition particles.hpp:83
void update_particles(float deltaTime)
Update the particles.
float spawn_rate
Spawn rate of particles.
Definition particles.hpp:79
int atlas_index
Atlas index.
glm::vec3 starting_spread
Starting spread of a new particle.
Definition particles.hpp:67
glm::vec3 starting_position
Starting position of a new particle.
Definition particles.hpp:59
int num_particles
Number of particles.
Definition particles.hpp:75
int atlas_width
Atlas width.
int atlas_height
Atlas height.
Buffer wrapper around OpenGL buffer objects.
Definition buffer.hpp:50
Vertex Array Object (VAO)
Definition vao.hpp:45