ComputerGraphik TU WIEN
Classes | Public Member Functions | Private Attributes | List of all members
ParticleSystemCPU Class Reference

Implementation of CPU particle system. More...

#include <particleSystemCPU.hpp>

Inheritance diagram for ParticleSystemCPU:
SceneObject

Classes

struct  ParticleCPU
 
struct  ParticleGPU
 

Public Member Functions

 ParticleSystemCPU (size_t particleCount, const std::string &name, Scene *scene=0, Model *model=0, const glm::mat4 &modelMatrix=glm::mat4(1.0f))
 
virtual ~ParticleSystemCPU ()
 
void push (const glm::vec3 &pos)
 
void draw () const
 
bool animate (double time)
 
void update (double deltaT)
 
void setShader (Shader *val)
 
- Public Member Functions inherited from SceneObject
 SceneObject (std::shared_ptr< SceneObject > &effectParent, const glm::mat4 &modelMatrix=glm::mat4(1))
 
 SceneObject (const std::string &name, Scene *scene=0, Model *model=0, const glm::mat4 &modelMatrix=glm::mat4(1))
 
virtual ~SceneObject ()
 
ModelgetModel () const
 
ShadergetShader () const
 
glm::mat4 getModelMatrix () const
 
glm::mat4 getGlobalModelMatrix () const
 
std::string getName () const
 
std::shared_ptr< SceneObjectgetParent () const
 
void setAnimationTime (double time)
 
bool setAnimation (const Animation &anim)
 
bool delChild (size_t idx)
 
bool getChild (size_t idx, std::shared_ptr< SceneObject > &child) const
 
bool addChild (std::shared_ptr< SceneObject > &child)
 
bool remEffect (const std::string &name)
 
SceneObjectgetEffect (const std::string &name) const
 
bool addEffect (const std::string &name, std::unique_ptr< SceneObject > &effect)
 
bool doNotRender ()
 
bool getIsVolSun ()
 
virtual void reset ()
 

Private Attributes

double lastAnimate
 
GLuint particlesVBO
 
int activeParticleCount
 
std::vector< ParticleCPUparticlesNew
 
std::vector< ParticleCPUparticlesCPU
 
std::vector< ParticleGPUparticlesGPU
 

Additional Inherited Members

- Public Types inherited from SceneObject
typedef std::vector< std::pair< double, glm::mat4 > > Animation
 
- Protected Attributes inherited from SceneObject
GLuint vao
 
Scenescene
 
Modelmodel
 
Shadershader
 
glm::mat4 modelMatrix
 
std::string name
 
std::weak_ptr< SceneObjectparent
 
std::vector< std::shared_ptr< SceneObject > > childs
 
std::map< std::string, std::unique_ptr< SceneObject > > effectChilds
 
size_t animIDX
 
Animation animation
 
bool norender
 
bool isVolSun
 

Detailed Description

Implementation of CPU particle system.

Author
Adam

When a tank is moving, it is leaving trail after itself. Each trail is a simple quad. When a new trail is added, it's position is written into a buffer and it's transparency is 1. During each update(), the transparency is decreased with a factor until it reaches 0. On zero the particle is dead and not updated. It uses transparency therefore sorting is needed based on the camera distance. Transparent objects must be rendered in the order of their distance from the camera. The highest is rendered first. This must be done, because if a transparent object is rendered, then later an object is rendered which is occluded by the transparent one, then because of the depth test, the later object would not be rendered. On each draw() the position and the transparency of each living particle is uploaded and drawn with instancing.

See also
http://www.opengl-tutorial.org/intermediate-tutorials/billboards-particles/particles-instancing/

Constructor & Destructor Documentation

ParticleSystemCPU::ParticleSystemCPU ( size_t  particleCount,
const std::string &  name,
Scene scene = 0,
Model model = 0,
const glm::mat4 &  modelMatrix = glm::mat4(1.0f) 
)
ParticleSystemCPU::~ParticleSystemCPU ( )
virtual

Member Function Documentation

bool ParticleSystemCPU::animate ( double  time)
virtual

Reimplemented from SceneObject.

void ParticleSystemCPU::draw ( ) const
virtual

Reimplemented from SceneObject.

void ParticleSystemCPU::push ( const glm::vec3 &  pos)
void ParticleSystemCPU::setShader ( Shader val)
virtual

Reimplemented from SceneObject.

void ParticleSystemCPU::update ( double  deltaT)
virtual

Reimplemented from SceneObject.

Member Data Documentation

int ParticleSystemCPU::activeParticleCount
private
double ParticleSystemCPU::lastAnimate
private
std::vector<ParticleCPU> ParticleSystemCPU::particlesCPU
private
std::vector<ParticleGPU> ParticleSystemCPU::particlesGPU
private
std::vector<ParticleCPU> ParticleSystemCPU::particlesNew
private
GLuint ParticleSystemCPU::particlesVBO
private

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