Vesper 0.5.1
Vesper is short form for the Latin word for "Bat", as Vesper is designed to be small, lightweight, and easily handle things like particles and flocking behaviors in accordance with the nature of bats. \n It is meant to be a particle simulation, VFX editor, and CAN be used secondarily as a small game engine.
GitHub | Vesper Updates | Creator
Loading...
Searching...
No Matches
Vesper::ParticleSystem Class Reference

#include <ParticleSystem.h>

Classes

struct  Particle

Public Member Functions

 ParticleSystem ()
 ParticleSystem (uint32_t maxParticles)
void OnUpdate (Timestep ts)
void OnRender (OrthographicCamera &camera)
void Emit (const ParticleProps &particleProps)
void SetParticleProps (const ParticleProps &particleProps)

Private Attributes

std::vector< Particlem_ParticlePool
uint32_t m_PoolIndex = 999
ParticleProps m_Props

Class Documentation

◆ Vesper::ParticleSystem::Particle

struct Vesper::ParticleSystem::Particle
Class Members
bool Active = false
vec4 ColorBegin
vec4 ColorEnd
float LifeRemaining = 0.0f
float LifeTime = 0.0f
vec3 Position
float Rotation
float SizeBegin
float SizeEnd
vec3 Velocity

Constructor & Destructor Documentation

◆ ParticleSystem() [1/2]

Vesper::ParticleSystem::ParticleSystem ( )
13 {
14 m_PoolIndex = 999;
15 m_ParticlePool.resize(1000);
16 }
uint32_t m_PoolIndex
Definition ParticleSystem.h:48
std::vector< Particle > m_ParticlePool
Definition ParticleSystem.h:47

References m_PoolIndex.

◆ ParticleSystem() [2/2]

Vesper::ParticleSystem::ParticleSystem ( uint32_t maxParticles)
19 : m_PoolIndex(maxParticles - 1)
20 {
21 m_ParticlePool.resize(maxParticles);
22 }

References m_PoolIndex.

Member Function Documentation

◆ Emit()

void Vesper::ParticleSystem::Emit ( const ParticleProps & particleProps)
64 {
66 particle.Active = true;
67 particle.Position = particleProps.Position;
68 particle.Rotation = particleProps.Rotation + particleProps.RotationVariation * (Vesper::Random::Float1() - 0.5f);
69
70 particle.Velocity = particleProps.Velocity;
71 particle.Velocity.x += particleProps.VelocityVariation.x * (Vesper::Random::Float1() - 0.5f);
72 particle.Velocity.y += particleProps.VelocityVariation.y * (Vesper::Random::Float1() - 0.5f);
73
74 particle.ColorBegin = particleProps.ColorBegin;
75 particle.ColorEnd = particleProps.ColorEnd;
76
77 particle.SizeBegin = particleProps.SizeBegin + particleProps.SizeVariation * (Vesper::Random::Float1() - 0.5f);
78 particle.SizeEnd = particleProps.SizeEnd;
79
80 particle.LifeTime = particleProps.LifeTime + particleProps.LifetimeVariation * (Vesper::Random::Float1() - 0.5f);
81 particle.LifeRemaining = particle.LifeTime;
83 }
Definition ParticleSystem.h:37
float Float1()
Definition Random.h:76

References Vesper::ParticleSystem::Particle::Active, Vesper::Random::Float1(), Vesper::ParticleSystem::Particle::LifeRemaining, Vesper::ParticleProps::LifeTime, Vesper::ParticleSystem::Particle::LifeTime, Vesper::ParticleProps::LifetimeVariation, Vesper::ParticleProps::Rotation, Vesper::ParticleSystem::Particle::Rotation, Vesper::ParticleProps::RotationVariation, Vesper::ParticleProps::SizeBegin, Vesper::ParticleSystem::Particle::SizeBegin, Vesper::ParticleProps::SizeEnd, Vesper::ParticleSystem::Particle::SizeEnd, and Vesper::ParticleProps::SizeVariation.

◆ OnRender()

void Vesper::ParticleSystem::OnRender ( Vesper::OrthographicCamera & camera)
44 {
45 for (auto& particle : m_ParticlePool)
46 {
47 if (!particle.Active)
48 continue;
49
50 float life = particle.LifeRemaining / particle.LifeTime;
51 glm::vec4 color = glm::lerp(particle.ColorEnd, particle.ColorBegin, life);
52 float size = glm::lerp(particle.SizeEnd, particle.SizeBegin, life);
53
55 { particle.Position },
56 { size, size },
58 particle.Rotation, 1.0f, color);
59
60 }
61 }
static Ref< Texture2D > GetWhiteTexture()
Returns a reference to the default white texture that allows for coloring.
Definition Renderer2D.cpp:492
static void DrawQuadRotatedWithTexture(const glm::mat4 &transform, const Ref< Texture2D > &texture, float tilingFactor, const glm::vec4 tintColor)
Draws a rotated textured quad with the given transform, texture, tiling factor, and tint color.
Definition Renderer2D.cpp:368

◆ OnUpdate()

void Vesper::ParticleSystem::OnUpdate ( Vesper::Timestep ts)
25 {
26 for (auto& particle : m_ParticlePool)
27 {
28 if (!particle.Active)
29 continue;
30
31 if (particle.LifeRemaining <= 0.0f)
32 {
33 particle.Active = false;
34 continue;
35 }
36
37 particle.LifeRemaining -= ts;
38 particle.Position += particle.Velocity * (float)ts;
39 particle.Rotation += 0.01f * ts;
40 }
41 }

◆ SetParticleProps()

void Vesper::ParticleSystem::SetParticleProps ( const ParticleProps & particleProps)
inline
33{ m_Props = particleProps; }
ParticleProps m_Props
Definition ParticleSystem.h:49

Member Data Documentation

◆ m_ParticlePool

std::vector<Particle> Vesper::ParticleSystem::m_ParticlePool
private

◆ m_PoolIndex

uint32_t Vesper::ParticleSystem::m_PoolIndex = 999
private

Referenced by ParticleSystem(), and ParticleSystem().

◆ m_Props

ParticleProps Vesper::ParticleSystem::m_Props
private

The documentation for this class was generated from the following files: