YourGameLib
Loading...
Searching...
No Matches
particles.h
Go to the documentation of this file.
1/*
2Copyright (c) 2019-2024 Alexander Scholz
3
4This software is provided 'as-is', without any express or implied
5warranty. In no event will the authors be held liable for any damages
6arising from the use of this software.
7
8Permission is granted to anyone to use this software for any purpose,
9including commercial applications, and to alter it and redistribute it
10freely, subject to the following restrictions:
11
121. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
162. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
183. This notice may not be removed or altered from any source distribution.
19*/
20#ifndef YOURGAME_PARTICLES_H
21#define YOURGAME_PARTICLES_H
22
23#include <vector>
24#include <random>
25#include <ctime>
26#include <glm/glm.hpp>
27
28namespace yourgame
29{
30 namespace math
31 {
39 {
40 public:
47 struct Config
48 {
49 size_t count = 100;
50 unsigned int seed = static_cast<unsigned int>(std::time(nullptr));
51 bool scatterOnInit = true;
52 bool scatterOnSpawn = false;
53 bool respawn = true;
54 glm::vec3 origin = {0.0f, 0.0f, 0.0f};
55 glm::vec3 emitterA = {0.0f, 0.0f, 0.0f};
56 glm::vec3 emitterB = {0.0f, 0.0f, 0.0f};
57 glm::vec3 emitterC = {0.0f, 0.0f, 0.0f};
58 glm::vec3 baseDirection = {0.0f, 1.0f, 0.0f};
59 glm::vec3 noisDirection = {0.2f, 0.2f, 0.2f};
60 float baseVelocity = 1.5f;
61 float noisVelocity = 0.2f;
62 float baseLifetime = 3.0f;
63 float noisLifetime = 0.4f;
64 };
65
66 Particles(const Config cfg);
67
72 virtual void tick(float dt);
73 void reset();
75 std::vector<glm::vec4> m_positionData;
76 std::vector<float> m_progressData;
77
78 private:
79 struct Part
80 {
81 glm::vec3 pos;
82 glm::vec3 move;
83 float lifetime;
84 float totalLifeInv;
85 float progress;
86 };
87 std::default_random_engine m_rndgen;
88 std::uniform_real_distribution<float> m_unirnd;
89 std::vector<Part> m_parts;
90 Part spawn();
91 float rnd1();
92 };
93 } // namespace math
94} // namespace yourgame
95
96#endif
Definition particles.h:39
std::vector< float > m_progressData
Definition particles.h:76
std::vector< glm::vec4 > m_positionData
Definition particles.h:75
void reset()
Definition particles.cpp:61
Config m_cfg
Definition particles.h:74
virtual void tick(float dt)
ticks the particle system
Definition particles.cpp:34
Definition audio.h:27
Particle system configuration.
Definition particles.h:48
float baseLifetime
base lifetime of particles
Definition particles.h:62
glm::vec3 emitterC
third vector that forms a volume inside particles are spawned
Definition particles.h:57
float baseVelocity
base velocity of particles
Definition particles.h:60
glm::vec3 emitterB
second vector that forms a volume inside particles are spawned
Definition particles.h:56
bool respawn
if true, particles are respawned after their lifetime ends
Definition particles.h:53
glm::vec3 emitterA
first vector that forms a volume inside particles are spawned
Definition particles.h:55
bool scatterOnSpawn
if true, particles are scattered when they are respawned
Definition particles.h:52
size_t count
number of particles
Definition particles.h:49
float noisVelocity
uniform noise for velocity
Definition particles.h:61
unsigned int seed
seed for random generator
Definition particles.h:50
float noisLifetime
uniform noise for lifetime
Definition particles.h:63
glm::vec3 origin
origin of the system
Definition particles.h:54
glm::vec3 baseDirection
base direction of particles
Definition particles.h:58
bool scatterOnInit
if true, particles are scattered in the volume when system is initialized
Definition particles.h:51
glm::vec3 noisDirection
uniform noise for direction
Definition particles.h:59