SAGE
A Simple Academic Game Engine
Loading...
Searching...
No Matches
Sage::CParticle< VEC, SD > Class Template Reference

A particle. More...

#include <SageParticle.h>

Inheritance diagram for Sage::CParticle< VEC, SD >:
Collaboration diagram for Sage::CParticle< VEC, SD >:

Public Member Functions

 CParticle (const CParticleDesc< VEC, SD > &, float)
 Constructor.
 
void move (float)
 Move and rotate.
 
void rescale (float)
 Rescale.
 
void fade (float)
 Fade.
 
void translate (const VEC &)
 Translate by an amount.
 
void translateto (const VEC &)
 Translate to a destination.
 

Public Attributes

float m_fBirthTime = 0.0f
 Time of creation.
 
- Public Attributes inherited from Sage::CParticleDesc< VEC, SD >
VEC m_vVel = VEC::Zero
 Velocity.
 
VEC m_vAccel = VEC::Zero
 Acceleration.
 
float m_fFriction = 0.0f
 Coefficient of friction.
 
float m_fRSpeed = 0.0f
 Rotational speed.
 
float m_fLifeSpan = FLT_MAX
 Time it will live for.
 
float m_fMaxScale = 1.0f
 Maximum scale.
 
float m_fScaleInFrac = 0.0f
 Fraction of life growing in.
 
float m_fScaleOutFrac = 0.0f
 Fraction of life shrinking out.
 
float m_fFadeInFrac = 0.0f
 Fraction of life fading in.
 
float m_fFadeOutFrac = 0.0f
 Fraction of life fading out.
 

Protected Member Functions

float Frac (float, float, float, float)
 Compute fraction.
 

Detailed Description

template<class VEC, class SD>
class Sage::CParticle< VEC, SD >

A particle is a sprite that exists for a brief time. It can grow in and shrink out, and also fade in and fade out using an alpha channel. It's templated so we can define a 2D and a 3D version with a minimum of fuss.

Template Parameters
VECA vector class.
SDA sprite descriptor class.

Constructor & Destructor Documentation

◆ CParticle()

template<class VEC , class SD >
CParticle::CParticle ( const CParticleDesc< VEC, SD > & d,
float t )

Create a particle given a particle descriptor and a creation time.

Template Parameters
VECA vector class.
SDA sprite descriptor class.
Parameters
dParticle descriptor.
tBirth time.

Member Function Documentation

◆ fade()

template<class VEC , class SD >
void CParticle::fade ( float f)

Make the particle's alpha channel fade in or fade out over time.

Template Parameters
VECA vector class.
SDA sprite descriptor class.
Parameters
fFraction of lifespan lived, from 0.0f to 1.0f inclusive.

◆ Frac()

template<class VEC , class SD >
float CParticle::Frac ( float fCurFrac,
float fInFrac,
float fOutFrac,
float fMaxFrac )
protected

Compute fraction.

Template Parameters
VECA vector class.
SDA sprite descriptor class.
Parameters
fCurFracCurrent fraction.
fInFracIn fraction.
fOutFracOut fraction.
fMaxFracMaximum fraction (which is the default).
Returns
Fraction.

◆ move()

template<class VEC , class SD >
void CParticle::move ( float t)

Translate, apply acceleration, apply friction, and rotate.

Template Parameters
VECA vector class.
SDA sprite descriptor class.
Parameters
tTime step.

◆ rescale()

template<class VEC , class SD >
void CParticle::rescale ( float f)

Rescale the particle. It grows to m_fMaxScale for the first m_fScaleInFrac fraction of its life, and shrink to zero for the last m_fScaleOutFrac of its life.

Template Parameters
VECA vector class.
SDA sprite descriptor class.
Parameters
fFraction of lifespan lived, from 0.0f to 1.0f inclusive.

◆ translate()

template<class VEC , class SD >
void CParticle::translate ( const VEC & delta)

Move particle by a given distance and direction.

Parameters
deltaVector amount to add to current position.
Template Parameters
VECA vector class.
SDA sprite descriptor class.

◆ translateto()

template<class VEC , class SD >
void CParticle::translateto ( const VEC & v)

Move particle by a given distance and direction.

Parameters
vDestination.
Template Parameters
VECA vector class.
SDA sprite descriptor class.