![]() |
CUGL 3.0
Cornell University Game Library
|
#include <CUParticleSystem.h>
Public Member Functions | |
Particle3 () | |
Public Attributes | |
Vec3 | position |
Vec3 | velocity |
Color4 | color |
float | size |
float | life |
float | distance |
float | delay |
void * | userdata |
This class is the class representing a particle in a simulation.
Ideally, we would have allowed users to define their own particle classes, and templatized ParticleSystem
. However, this creates a lot of design issues. Templating has issues with proliferation (e.g. forcing any general purpose class that uses a particle system to be templated as well). The alternative is to use subclassing to limit the template to the method and not the entire class. But this causes issues with allocation and heap fragmentation (because the particle system would need to be a pointer of pointers).
The solution used by this class is delegation. This class is essentially a struct with no methods of its own. It has several base attributes, but also includes a void pointer for user-defined data.
The user manipulates these particles with three function pointers passed to ParticleSystem
: ParticleAllocator
, ParticleDeallocator
, and ParticleUpdater
. See the descriptions for these function types. Both ParticleAllocator
and ParticleUpdater
are required. ParticleDeallocator
is only required if ParticleAllocator
modifies the userdata
attribute of this class.
|
inline |
Creates an default particle.
This particle is uninitialized and unused. The particle system will initialize it before use.
Color4 cugl::graphics::Particle3::color |
The particle color
float cugl::graphics::Particle3::delay |
The delay in seconds until this particle is emitted
float cugl::graphics::Particle3::distance |
The squared distance to the camera. If dead, this value is -1.0f
float cugl::graphics::Particle3::life |
The remaining life of the particle. If <0 this particle is dead and unused.
Vec3 cugl::graphics::Particle3::position |
The particle position
float cugl::graphics::Particle3::size |
The particle size (scale to apply to template)
void* cugl::graphics::Particle3::userdata |
Optional user-data for more complex simulations.
This value can be allocated by ParticleAllocator
. But if that happens, the ParticleDeallocator
should clean up afterwards to prevent any memory leaks.
Vec3 cugl::graphics::Particle3::velocity |
The particle velocity