Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CParticleEmitter Class Reference

Particle emitter. More...

#include <ParticleEmitter.h>

Collaboration diagram for CParticleEmitter:

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...
 
const CQuaternionGetRotation () const
 
const CBoundingBoxAlignedGetParticleBounds () const
 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 UploadData (Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
 Upload the vertex data to the backend. More...
 
void Bind (Renderer::Backend::IDeviceCommandContext *deviceCommandContext, Renderer::Backend::IShaderProgram *shader)
 Bind rendering state (textures and blend modes). More...
 
void RenderArray (Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
 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
 
Renderer::Backend::IVertexInputLayoutm_VertexInputLayout = nullptr
 
int m_LastFrameNumber
 

Detailed Description

Particle emitter.

Emitters store particle data in two forms:

  • m_Particles contains the raw data used for the CPU particle simulation.
  • m_VertexArray contains the data required for rendering. Particles are rendered as billboard quads, so the vertex array contains four vertices per particle with different UV coordinates. The billboard position computation is performed by a vertex shader.

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::CParticleEmitter ( const CParticleEmitterTypePtr type)

Member Function Documentation

◆ AddParticle()

void CParticleEmitter::AddParticle ( const SParticle particle)

Push a new particle onto the ring buffer.

(May overwrite an old particle.)

◆ Bind()

void CParticleEmitter::Bind ( Renderer::Backend::IDeviceCommandContext deviceCommandContext,
Renderer::Backend::IShaderProgram shader 
)

Bind rendering state (textures and blend modes).

◆ GetParticleBounds()

const CBoundingBoxAligned & CParticleEmitter::GetParticleBounds ( ) const
inline

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

◆ GetPosition()

CVector3D CParticleEmitter::GetPosition ( ) const
inline

◆ GetRotation()

const CQuaternion & CParticleEmitter::GetRotation ( ) const
inline

◆ PrepareForRendering()

void CParticleEmitter::PrepareForRendering ( )

Make the vertex data available for subsequent binding and rendering.

◆ RenderArray()

void CParticleEmitter::RenderArray ( Renderer::Backend::IDeviceCommandContext deviceCommandContext)

Draw the vertex array.

◆ SetEntityVariable()

void CParticleEmitter::SetEntityVariable ( const std::string &  name,
float  value 
)

◆ SetPosition()

void CParticleEmitter::SetPosition ( const CVector3D pos)
inline

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

◆ SetRotation()

void CParticleEmitter::SetRotation ( const CQuaternion rot)
inline

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

◆ Unattach()

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 std::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 std::shared_ptr you're about to drop

◆ UpdateArrayData()

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.

◆ UploadData()

void CParticleEmitter::UploadData ( Renderer::Backend::IDeviceCommandContext deviceCommandContext)

Upload the vertex data to the backend.

Member Data Documentation

◆ m_Active

bool CParticleEmitter::m_Active

Whether this emitter is still emitting new particles.

◆ m_AttributeAxis

VertexArray::Attribute CParticleEmitter::m_AttributeAxis
private

◆ m_AttributeColor

VertexArray::Attribute CParticleEmitter::m_AttributeColor
private

◆ m_AttributePos

VertexArray::Attribute CParticleEmitter::m_AttributePos
private

◆ m_AttributeUV

VertexArray::Attribute CParticleEmitter::m_AttributeUV
private

◆ m_EmissionRoundingError

float CParticleEmitter::m_EmissionRoundingError

◆ m_EntityVariables

std::map<std::string, float> CParticleEmitter::m_EntityVariables

◆ m_IndexArray

VertexIndexArray CParticleEmitter::m_IndexArray
private

◆ m_LastFrameNumber

int CParticleEmitter::m_LastFrameNumber
private

◆ m_LastUpdateTime

float CParticleEmitter::m_LastUpdateTime

◆ m_NextParticleIdx

size_t CParticleEmitter::m_NextParticleIdx

◆ m_ParticleBounds

CBoundingBoxAligned CParticleEmitter::m_ParticleBounds
private

Bounding box of the current particle center points.

◆ m_Particles

std::vector<SParticle> CParticleEmitter::m_Particles

◆ m_Pos

CVector3D CParticleEmitter::m_Pos

◆ m_Rot

CQuaternion CParticleEmitter::m_Rot

◆ m_Type

CParticleEmitterTypePtr CParticleEmitter::m_Type

◆ m_VertexArray

VertexArray CParticleEmitter::m_VertexArray
private

◆ m_VertexInputLayout

Renderer::Backend::IVertexInputLayout* CParticleEmitter::m_VertexInputLayout = nullptr
private

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