ManaPlus
Public Member Functions | Data Fields
ParticleEmitterProp< T > Struct Template Reference

#include <particleemitterprop.h>

Public Member Functions

 ParticleEmitterProp ()
 
void set (const T min, const T max)
 
void set (const T val)
 
void setFunction (ParticleChangeFuncT func, T amplitude, const int period, const int phase)
 
value (int tick) const
 

Data Fields

minVal
 
maxVal
 
ParticleChangeFuncT changeFunc
 
changeAmplitude
 
int changePeriod
 
int changePhase
 

Detailed Description

template<typename T>
struct ParticleEmitterProp< T >

Definition at line 33 of file particleemitterprop.h.

Constructor & Destructor Documentation

◆ ParticleEmitterProp()

template<typename T >
ParticleEmitterProp< T >::ParticleEmitterProp ( )
inline

Member Function Documentation

◆ set() [1/2]

template<typename T >
void ParticleEmitterProp< T >::set ( const T  min,
const T  max 
)
inline

◆ set() [2/2]

template<typename T >
void ParticleEmitterProp< T >::set ( const T  val)
inline

Definition at line 53 of file particleemitterprop.h.

54  {
55  set(val, val);
56  }
void set(const T min, const T max)

References ParticleEmitterProp< T >::set().

◆ setFunction()

template<typename T >
void ParticleEmitterProp< T >::setFunction ( ParticleChangeFuncT  func,
amplitude,
const int  period,
const int  phase 
)
inline

◆ value()

template<typename T >
T ParticleEmitterProp< T >::value ( int  tick) const
inline

Definition at line 71 of file particleemitterprop.h.

72  {
73  tick += changePhase;
74  T val = static_cast<T>(minVal + (maxVal - minVal)
75  * (rand() / (static_cast<double>(RAND_MAX) + 1)));
76 
77  switch (changeFunc)
78  {
80  val += static_cast<T>(std::sin(M_PI * 2 * (static_cast<double>(
81  tick % changePeriod) / static_cast<double>(
83  break;
85  val += static_cast<T>(changeAmplitude * (static_cast<double>(
86  tick % changePeriod) / static_cast<double>(
88  break;
90  if ((tick % changePeriod) * 2 < changePeriod)
91  {
92  val += changeAmplitude - static_cast<T>((
93  tick % changePeriod) / static_cast<double>(
95  }
96  else
97  {
98  val += changeAmplitude * -3 + static_cast<T>((
99  tick % changePeriod) / static_cast<double>(
101  // I have no idea why this works but it does
102  }
103  break;
105  if ((tick % changePeriod) * 2 < changePeriod)
106  val += changeAmplitude;
107  else
108  val -= changeAmplitude;
109  break;
111  default:
112  // nothing
113  break;
114  }
115 
116  return val;
117  }

References ParticleEmitterProp< T >::changeAmplitude, ParticleEmitterProp< T >::changeFunc, ParticleEmitterProp< T >::changePeriod, ParticleEmitterProp< T >::changePhase, ParticleChangeFunc::FUNC_NONE, ParticleChangeFunc::FUNC_SAW, ParticleChangeFunc::FUNC_SINE, ParticleChangeFunc::FUNC_SQUARE, ParticleChangeFunc::FUNC_TRIANGLE, ParticleEmitterProp< T >::maxVal, and ParticleEmitterProp< T >::minVal.

Referenced by ParticleEmitter::createParticles(), and ParticleEmitter::ParticleEmitter().

Field Documentation

◆ changeAmplitude

template<typename T >
T ParticleEmitterProp< T >::changeAmplitude

◆ changeFunc

template<typename T >
ParticleChangeFuncT ParticleEmitterProp< T >::changeFunc

◆ changePeriod

template<typename T >
int ParticleEmitterProp< T >::changePeriod

◆ changePhase

template<typename T >
int ParticleEmitterProp< T >::changePhase

◆ maxVal

template<typename T >
T ParticleEmitterProp< T >::maxVal

◆ minVal

template<typename T >
T ParticleEmitterProp< T >::minVal

The documentation for this struct was generated from the following file: