PointParticleEmitter2.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_POINT_PARTICLE_EMITTER2_HPP
12 #define CUBBYFLOW_POINT_PARTICLE_EMITTER2_HPP
13 
15 
16 #include <random>
17 
18 namespace CubbyFlow
19 {
27 {
28  public:
29  class Builder;
30 
47  const Vector2D& origin, const Vector2D& direction, double speed,
48  double spreadAngleInDegrees, size_t maxNumOfNewParticlesPerSec = 1,
49  size_t maxNumOfParticles = std::numeric_limits<size_t>::max(),
50  uint32_t seed = 0);
51 
53  [[nodiscard]] size_t GetMaxNumberOfNewParticlesPerSecond() const;
54 
56  void SetMaxNumberOfNewParticlesPerSecond(size_t rate);
57 
59  [[nodiscard]] size_t GetMaxNumberOfParticles() const;
60 
62  void SetMaxNumberOfParticles(size_t maxNumberOfParticles);
63 
65  static Builder GetBuilder();
66 
67  private:
74  void OnUpdate(double currentTimeInSeconds,
75  double timeIntervalInSeconds) override;
76 
77  void Emit(Array1<Vector2D>* newPositions, Array1<Vector2D>* newVelocities,
78  size_t maxNewNumberOfParticles);
79 
80  [[nodiscard]] double Random();
81 
82  std::mt19937 m_rng;
83 
84  double m_firstFrameTimeInSeconds = 0.0;
85  size_t m_numberOfEmittedParticles = 0;
86 
87  size_t m_maxNumberOfNewParticlesPerSecond;
88  size_t m_maxNumberOfParticles;
89 
90  Vector2D m_origin;
91  Vector2D m_direction;
92  double m_speed;
93  double m_spreadAngleInRadians;
94 };
95 
97 using PointParticleEmitter2Ptr = std::shared_ptr<PointParticleEmitter2>;
98 
103 {
104  public:
106  [[nodiscard]] Builder& WithOrigin(const Vector2D& origin);
107 
109  [[nodiscard]] Builder& WithDirection(const Vector2D& direction);
110 
112  [[nodiscard]] Builder& WithSpeed(double speed);
113 
115  [[nodiscard]] Builder& WithSpreadAngleInDegrees(
116  double spreadAngleInDegrees);
117 
118  [[nodiscard]] Builder& WithMaxNumberOfNewParticlesPerSecond(
119  size_t maxNumOfNewParticlesPerSec);
120 
122  [[nodiscard]] Builder& WithMaxNumberOfParticles(
123  size_t maxNumberOfParticles);
124 
126  [[nodiscard]] Builder& WithRandomSeed(uint32_t seed);
127 
129  [[nodiscard]] PointParticleEmitter2 Build() const;
130 
132  [[nodiscard]] PointParticleEmitter2Ptr MakeShared() const;
133 
134  private:
135  size_t m_maxNumberOfNewParticlesPerSecond = 1;
136  size_t m_maxNumberOfParticles = std::numeric_limits<size_t>::max();
137  Vector2D m_origin{ 0, 0 };
138  Vector2D m_direction{ 0, 1 };
139  double m_speed = 1.0;
140  double m_spreadAngleInDegrees = 90.0;
141  uint32_t m_seed = 0;
142 };
143 } // namespace CubbyFlow
144 
145 #endif
std::shared_ptr< PointParticleEmitter2 > PointParticleEmitter2Ptr
Shared pointer for the PointParticleEmitter2 type.
Definition: PointParticleEmitter2.hpp:97
void SetMaxNumberOfNewParticlesPerSecond(size_t rate)
Sets max number of new particles per second.
2-D point particle emitter.
Definition: PointParticleEmitter2.hpp:26
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)
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
void SetMaxNumberOfParticles(size_t maxNumberOfParticles)
Sets max number of particles to be emitted.
Definition: Array-Impl.hpp:19
Front-end to create PointParticleEmitter2 objects step by step.
Definition: PointParticleEmitter2.hpp:102
size_t GetMaxNumberOfNewParticlesPerSecond() const
Returns max number of new particles per second.
Abstract base class for 2-D particle emitter.
Definition: ParticleEmitter2.hpp:21
size_t GetMaxNumberOfParticles() const
Returns max number of particles to be emitted.
static Builder GetBuilder()
Returns builder fox PointParticleEmitter2.