Pyrogenesis  trunk
Public Member Functions | Public Attributes | Private Attributes | List of all members
CParticleEmitter Class Reference

Particle emitter. More...

#include <ParticleEmitter.h>

Collaboration diagram for CParticleEmitter:
Collaboration graph
[legend]

Public Member Functions

 CParticleEmitter (const CParticleEmitterTypePtr &type)
 
void SetPosition (const CVector3D &pos)
 Set the position to be used for emission of new particles. More...
 
CVector3D GetPosition () const
 
void SetRotation (const CQuaternion &rot)
 Set the rotation to be used for emission of new particles (note: depends on particles). More...
 
CQuaternion GetRotation () const
 
CBoundingBoxAligned GetParticleBounds ()
 Get the bounding box of the center points of particles at their current positions. More...
 
void AddParticle (const SParticle &particle)
 Push a new particle onto the ring buffer. More...
 
void UpdateArrayData (int frameNumber)
 Update particle and vertex array data. More...
 
void PrepareForRendering ()
 Make the vertex data available for subsequent binding and rendering. More...
 
void Bind (const CShaderProgramPtr &shader)
 Bind rendering state (textures and blend modes). More...
 
void RenderArray (const CShaderProgramPtr &shader)
 Draw the vertex array. More...
 
void Unattach (const CParticleEmitterPtr &self)
 Stop this emitter emitting new particles, and pass responsibility for rendering to the CParticleManager. More...
 
void SetEntityVariable (const std::string &name, float value)
 

Public Attributes

CParticleEmitterTypePtr m_Type
 
bool m_Active
 Whether this emitter is still emitting new particles. More...
 
CVector3D m_Pos
 
CQuaternion m_Rot
 
std::map< std::string, float > m_EntityVariables
 
std::vector< SParticlem_Particles
 
size_t m_NextParticleIdx
 
float m_LastUpdateTime
 
float m_EmissionRoundingError
 

Private Attributes

CBoundingBoxAligned m_ParticleBounds
 Bounding box of the current particle center points. More...
 
VertexIndexArray m_IndexArray
 
VertexArray m_VertexArray
 
VertexArray::Attribute m_AttributePos
 
VertexArray::Attribute m_AttributeAxis
 
VertexArray::Attribute m_AttributeUV
 
VertexArray::Attribute m_AttributeColor
 
int m_LastFrameNumber
 

Detailed Description

Particle emitter.

Emitters store particle data in two forms:

The number of particles is a constant for the entire life of the emitter, to simplify the updating and rendering. m_Particles acts like a ring buffer, so we don't have to worry about dynamically allocating particles. If particles have variable lifetimes, they'll exist in the array with alpha=0 until they're overwritten by a new particle after the maximum lifetime.

(It's quite likely this could be made more efficient, if the overhead of any added complexity is not high.)

Constructor & Destructor Documentation

CParticleEmitter::CParticleEmitter ( const CParticleEmitterTypePtr type)

Member Function Documentation

void CParticleEmitter::AddParticle ( const SParticle particle)

Push a new particle onto the ring buffer.

(May overwrite an old particle.)

void CParticleEmitter::Bind ( const CShaderProgramPtr shader)

Bind rendering state (textures and blend modes).

CBoundingBoxAligned CParticleEmitter::GetParticleBounds ( )
inline

Get the bounding box of the center points of particles at their current positions.

CVector3D CParticleEmitter::GetPosition ( ) const
inline
CQuaternion CParticleEmitter::GetRotation ( ) const
inline
void CParticleEmitter::PrepareForRendering ( )

Make the vertex data available for subsequent binding and rendering.

void CParticleEmitter::RenderArray ( const CShaderProgramPtr shader)

Draw the vertex array.

void CParticleEmitter::SetEntityVariable ( const std::string &  name,
float  value 
)
void CParticleEmitter::SetPosition ( const CVector3D pos)
inline

Set the position to be used for emission of new particles.

void CParticleEmitter::SetRotation ( const CQuaternion rot)
inline

Set the rotation to be used for emission of new particles (note: depends on particles).

void CParticleEmitter::Unattach ( const CParticleEmitterPtr self)

Stop this emitter emitting new particles, and pass responsibility for rendering to the CParticleManager.

This should be called before dropping the last shared_ptr to this object so that it will carry on rendering (until all particles have dissipated) even when it's no longer attached to a model.

Parameters
selfthe shared_ptr you're about to drop
void CParticleEmitter::UpdateArrayData ( int  frameNumber)

Update particle and vertex array data.

Must be called before RenderArray.

If frameNumber is the same as the previous call to UpdateArrayData, then the function will do no work and return immediately.

Member Data Documentation

bool CParticleEmitter::m_Active

Whether this emitter is still emitting new particles.

VertexArray::Attribute CParticleEmitter::m_AttributeAxis
private
VertexArray::Attribute CParticleEmitter::m_AttributeColor
private
VertexArray::Attribute CParticleEmitter::m_AttributePos
private
VertexArray::Attribute CParticleEmitter::m_AttributeUV
private
float CParticleEmitter::m_EmissionRoundingError
std::map<std::string, float> CParticleEmitter::m_EntityVariables
VertexIndexArray CParticleEmitter::m_IndexArray
private
int CParticleEmitter::m_LastFrameNumber
private
float CParticleEmitter::m_LastUpdateTime
size_t CParticleEmitter::m_NextParticleIdx
CBoundingBoxAligned CParticleEmitter::m_ParticleBounds
private

Bounding box of the current particle center points.

std::vector<SParticle> CParticleEmitter::m_Particles
CVector3D CParticleEmitter::m_Pos
CQuaternion CParticleEmitter::m_Rot
CParticleEmitterTypePtr CParticleEmitter::m_Type
VertexArray CParticleEmitter::m_VertexArray
private

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