PointParticleEmitter2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: PointParticleEmitter2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D point particle emitter.
6 > Created Time: 2017/07/22
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_POINT_PARTICLE_EMITTER2_H
10 #define CUBBYFLOW_POINT_PARTICLE_EMITTER2_H
11 
13 
14 #include <random>
15 
16 namespace CubbyFlow
17 {
25  {
26  public:
27  class Builder;
28 
45  const Vector2D& origin,
46  const Vector2D& direction,
47  double speed,
48  double spreadAngleInDegrees,
49  size_t maxNumOfNewParticlesPerSec = 1,
50  size_t maxNumOfParticles = std::numeric_limits<size_t>::max(),
51  uint32_t seed = 0);
52 
55 
57  void SetMaxNumberOfNewParticlesPerSecond(size_t rate);
58 
60  size_t GetMaxNumberOfParticles() const;
61 
63  void SetMaxNumberOfParticles(size_t maxNumberOfParticles);
64 
66  static Builder GetBuilder();
67 
68  private:
69  std::mt19937 m_rng;
70 
71  double m_firstFrameTimeInSeconds = 0.0;
72  size_t m_numberOfEmittedParticles = 0;
73 
74  size_t m_maxNumberOfNewParticlesPerSecond;
75  size_t m_maxNumberOfParticles;
76 
77  Vector2D m_origin;
78  Vector2D m_direction;
79  double m_speed;
80  double m_spreadAngleInRadians;
81 
88  void OnUpdate(
89  double currentTimeInSeconds,
90  double timeIntervalInSeconds) override;
91 
92  void Emit(
93  Array1<Vector2D>* newPositions,
94  Array1<Vector2D>* newVelocities,
95  size_t maxNewNumberOfParticles);
96 
97  double Random();
98  };
99 
101  using PointParticleEmitter2Ptr = std::shared_ptr<PointParticleEmitter2>;
102 
107  {
108  public:
110  Builder& WithOrigin(const Vector2D& origin);
111 
113  Builder& WithDirection(const Vector2D& direction);
114 
116  Builder& WithSpeed(double speed);
117 
119  Builder& WithSpreadAngleInDegrees(double spreadAngleInDegrees);
120 
121  Builder& WithMaxNumberOfNewParticlesPerSecond(size_t maxNumOfNewParticlesPerSec);
122 
124  Builder& WithMaxNumberOfParticles(size_t maxNumberOfParticles);
125 
127  Builder& WithRandomSeed(uint32_t seed);
128 
131 
134 
135  private:
136  size_t m_maxNumberOfNewParticlesPerSecond = 1;
137  size_t m_maxNumberOfParticles = std::numeric_limits<size_t>::max();
138  Vector2D m_origin{ 0, 0 };
139  Vector2D m_direction{ 0, 1 };
140  double m_speed = 1.0;
141  double m_spreadAngleInDegrees = 90.0;
142  uint32_t m_seed = 0;
143  };
144 }
145 
146 #endif
std::shared_ptr< PointParticleEmitter2 > PointParticleEmitter2Ptr
Shared pointer for the PointParticleEmitter2 type.
Definition: PointParticleEmitter2.h:101
Builder & WithSpeed(double speed)
Returns builder with speed.
Builder & WithMaxNumberOfParticles(size_t maxNumberOfParticles)
Returns builder with max number of particles.
Builder & WithDirection(const Vector2D &direction)
Returns builder with direction.
PointParticleEmitter2Ptr MakeShared() const
Builds shared pointer of PointParticleEmitter2 instance.
void SetMaxNumberOfNewParticlesPerSecond(size_t rate)
Sets max number of new particles per second.
2-D point particle emitter.
Definition: PointParticleEmitter2.h:24
PointParticleEmitter2(const Vector2D &origin, const Vector2D &direction, double speed, double spreadAngleInDegrees, size_t maxNumOfNewParticlesPerSec=1, size_t maxNumOfParticles=std::numeric_limits< size_t >::max(), uint32_t seed=0)
1-D array class.
Definition: Array1.h:29
Definition: pybind11Utils.h:24
void SetMaxNumberOfParticles(size_t maxNumberOfParticles)
Sets max number of particles to be emitted.
Builder & WithRandomSeed(uint32_t seed)
Returns builder with random seed.
Builder & WithMaxNumberOfNewParticlesPerSecond(size_t maxNumOfNewParticlesPerSec)
PointParticleEmitter2 Build() const
Builds PointParticleEmitter2.
2-D vector class.
Definition: Vector2.h:26
Builder & WithOrigin(const Vector2D &origin)
Returns builder with origin.
Front-end to create PointParticleEmitter2 objects step by step.
Definition: PointParticleEmitter2.h:106
size_t GetMaxNumberOfNewParticlesPerSecond() const
Returns max number of new particles per second.
Builder & WithSpreadAngleInDegrees(double spreadAngleInDegrees)
Returns builder with spread angle in degrees.
Abstract base class for 2-D particle emitter.
Definition: ParticleEmitter2.h:19
size_t GetMaxNumberOfParticles() const
Returns max number of particles to be emitted.
static Builder GetBuilder()
Returns builder fox PointParticleEmitter2.