PointParticleEmitter3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: PointParticleEmitter3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 3-D point particle emitter.
6 > Created Time: 2017/07/22
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_POINT_PARTICLE_EMITTER3_H
10 #define CUBBYFLOW_POINT_PARTICLE_EMITTER3_H
11 
13 
14 #include <random>
15 
16 namespace CubbyFlow
17 {
25  {
26  public:
27  class Builder;
28 
45  const Vector3D& origin,
46  const Vector3D& 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 = 1;
75  size_t m_maxNumberOfParticles = std::numeric_limits<size_t>::max();
76 
77  Vector3D m_origin;
78  Vector3D 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<Vector3D>* newPositions,
94  Array1<Vector3D>* newVelocities,
95  size_t maxNewNumberOfParticles);
96 
97  double Random();
98  };
99 
101  using PointParticleEmitter3Ptr = std::shared_ptr<PointParticleEmitter3>;
102 
107  {
108  public:
110  Builder& WithOrigin(const Vector3D& origin);
111 
113  Builder& WithDirection(const Vector3D& 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  Vector3D m_origin{ 0, 0, 0 };
139  Vector3D m_direction{ 0, 1, 0 };
140  double m_speed = 1.0;
141  double m_spreadAngleInDegrees = 90.0;
142  uint32_t m_seed = 0;
143  };
144 }
145 
146 #endif
3-D vector class.
Definition: Vector3.h:26
PointParticleEmitter3 Build() const
Builds PointParticleEmitter3.
Abstract base class for 3-D particle emitter.
Definition: ParticleEmitter3.h:19
PointParticleEmitter3Ptr MakeShared() const
Builds shared pointer of PointParticleEmitter3 instance.
Builder & WithRandomSeed(uint32_t seed)
Returns builder with random seed.
3-D point particle emitter.
Definition: PointParticleEmitter3.h:24
Builder & WithMaxNumberOfParticles(size_t maxNumberOfParticles)
Returns builder with max number of particles.
Builder & WithSpeed(double speed)
Returns builder with speed.
PointParticleEmitter3(const Vector3D &origin, const Vector3D &direction, double speed, double spreadAngleInDegrees, size_t maxNumOfNewParticlesPerSec=1, size_t maxNumOfParticles=std::numeric_limits< size_t >::max(), uint32_t seed=0)
Builder & WithDirection(const Vector3D &direction)
Returns builder with direction.
void SetMaxNumberOfNewParticlesPerSecond(size_t rate)
Sets max number of new particles per second.
1-D array class.
Definition: Array1.h:29
Definition: pybind11Utils.h:24
Front-end to create PointParticleEmitter3 objects step by step.
Definition: PointParticleEmitter3.h:106
std::shared_ptr< PointParticleEmitter3 > PointParticleEmitter3Ptr
Shared pointer for the PointParticleEmitter3 type.
Definition: PointParticleEmitter3.h:101
size_t GetMaxNumberOfNewParticlesPerSecond() const
Returns max number of new particles per second.
static Builder GetBuilder()
Returns builder fox PointParticleEmitter3.
size_t GetMaxNumberOfParticles() const
Returns max number of particles to be emitted.
Builder & WithSpreadAngleInDegrees(double spreadAngleInDegrees)
Returns builder with spread angle in degrees.
void SetMaxNumberOfParticles(size_t maxNumberOfParticles)
Sets max number of particles to be emitted.
Builder & WithMaxNumberOfNewParticlesPerSecond(size_t maxNumOfNewParticlesPerSec)
Builder & WithOrigin(const Vector3D &origin)
Returns builder with origin.