The LARC Game Engine
A Simple Game Engine from the Laboratory for Recreational Computing
Public Member Functions | Public Attributes | List of all members
LParticle< VECTOR, SPRITEDESC > Class Template Reference

A particle. More...

#include <Particle.h>

Inheritance diagram for LParticle< VECTOR, SPRITEDESC >:
LParticleDesc< VECTOR, SPRITEDESC >

Public Member Functions

 LParticle (const LParticleDesc< VECTOR, SPRITEDESC > &, float)
 Constructor. More...
 
void move (float)
 Move and rotate. More...
 
void rescale (float)
 Rescale. More...
 
void fade (float)
 Fade. More...
 
void translate (const VECTOR &)
 Translate. More...
 

Public Attributes

float m_fBirthTime = 0.0f
 Time of creation.
 
- Public Attributes inherited from LParticleDesc< VECTOR, SPRITEDESC >
VECTOR m_vVel = VECTOR::Zero
 Velocity.
 
VECTOR m_vAccel = VECTOR::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.
 

Detailed Description

template<class VECTOR, class SPRITEDESC>
class LParticle< VECTOR, SPRITEDESC >

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
VECTORA vector class.
SPRITEDESCA sprite descriptor class.

Constructor & Destructor Documentation

◆ LParticle()

template<T0 >
LParticle< T0 >::LParticle ( const LParticleDesc< VECTOR, SPRITEDESC > &  d,
float  t 
)

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

Template Parameters
VECTORA vector class.
SPRITEDESCA sprite descriptor class.
Parameters
dParticle descriptor.
tBirth time.

Member Function Documentation

◆ fade()

template<T0 >
void LParticle< T0 >::fade ( float  f)

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

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

◆ move()

template<T0 >
void LParticle< T0 >::move ( float  t)

Translate, apply acceleration, apply friction, and rotate.

Template Parameters
VECTORA vector class.
SPRITEDESCA sprite descriptor class.
Parameters
tTime step.

◆ rescale()

template<T0 >
void LParticle< T0 >::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
VECTORA vector class.
SPRITEDESCA sprite descriptor class.
Parameters
fFraction of lifespan lived, from 0.0f to 1.0f inclusive.

◆ translate()

template<T0 >
void LParticle< T0 >::translate ( const VECTOR &  delta)

Move particle by a given distance and direction.

Parameters
deltaVector amount to add to current position.
Template Parameters
VECTORA vector class.
SPRITEDESCA sprite descriptor class.