PointParticleEmitter3.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_EMITTER3_HPP
12 #define CUBBYFLOW_POINT_PARTICLE_EMITTER3_HPP
13 
15 
16 #include <random>
17 
18 namespace CubbyFlow
19 {
27 {
28  public:
29  class Builder;
30 
47  const Vector3D& origin, const Vector3D& 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  [[nodiscard]] static Builder GetBuilder();
66 
67  private:
74  void OnUpdate(double currentTimeInSeconds,
75  double timeIntervalInSeconds) override;
76 
77  void Emit(Array1<Vector3D>* newPositions, Array1<Vector3D>* 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 = 1;
88  size_t m_maxNumberOfParticles = std::numeric_limits<size_t>::max();
89 
90  Vector3D m_origin;
91  Vector3D m_direction;
92  double m_speed;
93  double m_spreadAngleInRadians;
94 };
95 
97 using PointParticleEmitter3Ptr = std::shared_ptr<PointParticleEmitter3>;
98 
103 {
104  public:
106  [[nodiscard]] Builder& WithOrigin(const Vector3D& origin);
107 
109  [[nodiscard]] Builder& WithDirection(const Vector3D& 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]] PointParticleEmitter3 Build() const;
130 
132  [[nodiscard]] PointParticleEmitter3Ptr MakeShared() const;
133 
134  private:
135  size_t m_maxNumberOfNewParticlesPerSecond = 1;
136  size_t m_maxNumberOfParticles = std::numeric_limits<size_t>::max();
137  Vector3D m_origin{ 0, 0, 0 };
138  Vector3D m_direction{ 0, 1, 0 };
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
Abstract base class for 3-D particle emitter.
Definition: ParticleEmitter3.hpp:21
3-D point particle emitter.
Definition: PointParticleEmitter3.hpp:26
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)
Definition: Matrix.hpp:27
void SetMaxNumberOfNewParticlesPerSecond(size_t rate)
Sets max number of new particles per second.
Definition: pybind11Utils.hpp:20
Definition: Array-Impl.hpp:19
Front-end to create PointParticleEmitter3 objects step by step.
Definition: PointParticleEmitter3.hpp:102
std::shared_ptr< PointParticleEmitter3 > PointParticleEmitter3Ptr
Shared pointer for the PointParticleEmitter3 type.
Definition: PointParticleEmitter3.hpp:97
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.
void SetMaxNumberOfParticles(size_t maxNumberOfParticles)
Sets max number of particles to be emitted.