VolumeParticleEmitter2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: VolumeParticleEmitter2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D volumetric particle emitter.
6 > Created Time: 2017/06/19
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_VOLUME_PARTICLE_EMITTER2_H
10 #define CUBBYFLOW_VOLUME_PARTICLE_EMITTER2_H
11 
15 
16 #include <random>
17 
18 namespace CubbyFlow
19 {
26  {
27  public:
28  class Builder;
29 
48  const ImplicitSurface2Ptr& implicitSurface,
49  const BoundingBox2D& bounds,
50  double spacing,
51  const Vector2D& initialVel = Vector2D(),
52  size_t maxNumberOfParticles = std::numeric_limits<size_t>::max(),
53  double jitter = 0.0,
54  bool isOneShot = true,
55  bool allowOverlapping = false,
56  uint32_t seed = 0);
57 
66  void SetPointGenerator(const PointGenerator2Ptr& newPointsGen);
67 
69  double GetJitter() const;
70 
72  void SetJitter(double newJitter);
73 
75  bool GetIsOneShot() const;
76 
86  void SetIsOneShot(bool newValue);
87 
89  bool GetAllowOverlapping() const;
90 
100  void SetAllowOverlapping(bool newValue);
101 
103  size_t GetMaxNumberOfParticles() const;
104 
106  void SetMaxNumberOfParticles(size_t newMaxNumberOfParticles);
107 
109  double GetSpacing() const;
110 
112  void SetSpacing(double newSpacing);
113 
116 
118  void SetInitialVelocity(const Vector2D& newInitialVel);
119 
121  static Builder GetBuilder();
122 
123  private:
124  std::mt19937 m_rng;
125 
126  ImplicitSurface2Ptr m_implicitSurface;
127  BoundingBox2D m_bounds;
128  double m_spacing;
129  Vector2D m_initialVel;
130  PointGenerator2Ptr m_pointsGen;
131 
132  size_t m_maxNumberOfParticles = std::numeric_limits<size_t>::max();
133  size_t m_numberOfEmittedParticles = 0;
134 
135  double m_jitter = 0.0;
136  bool m_isOneShot = true;
137  bool m_allowOverlapping = false;
138 
145  void OnUpdate(double currentTimeInSeconds, double timeIntervalInSeconds) override;
146 
147  void Emit(const ParticleSystemData2Ptr& particles,
148  Array1<Vector2D>* newPositions, Array1<Vector2D>* newVelocities);
149 
150  double Random();
151  };
152 
154  using VolumeParticleEmitter2Ptr = std::shared_ptr<VolumeParticleEmitter2>;
155 
160  {
161  public:
163  Builder& WithImplicitSurface(const ImplicitSurface2Ptr& implicitSurface);
164 
166  Builder& WithSurface(const Surface2Ptr& surface);
167 
169  Builder& WithMaxRegion(const BoundingBox2D& bounds);
170 
172  Builder& WithSpacing(double spacing);
173 
175  Builder& WithInitialVelocity(const Vector2D& initialVel);
176 
178  Builder& WithMaxNumberOfParticles(size_t maxNumberOfParticles);
179 
181  Builder& WithJitter(double jitter);
182 
184  Builder& WithIsOneShot(bool isOneShot);
185 
187  Builder& WithAllowOverlapping(bool allowOverlapping);
188 
190  Builder& WithRandomSeed(uint32_t seed);
191 
194 
197 
198  private:
199  ImplicitSurface2Ptr m_implicitSurface;
200  bool m_isBoundSet = false;
201  BoundingBox2D m_bounds;
202  double m_spacing = 0.1;
203  Vector2D m_initialVel{ 0, 0 };
204  size_t m_maxNumberOfParticles = std::numeric_limits<size_t>::max();
205  double m_jitter = 0.0;
206  bool m_isOneShot = true;
207  bool m_allowOverlapping = false;
208  uint32_t m_seed = 0;
209  };
210 }
211 
212 #endif
Builder & WithSurface(const Surface2Ptr &surface)
Returns builder with surface defining volume shape.
Builder & WithMaxRegion(const BoundingBox2D &bounds)
Returns builder with max region.
Builder & WithAllowOverlapping(bool allowOverlapping)
Returns builder with overlapping flag.
Builder & WithImplicitSurface(const ImplicitSurface2Ptr &implicitSurface)
Returns builder with implicit surface defining volume shape.
Builder & WithSpacing(double spacing)
Returns builder with spacing.
void SetInitialVelocity(const Vector2D &newInitialVel)
Returns the initial velocity of the particles.
Builder & WithRandomSeed(uint32_t seed)
Returns builder with random seed.
Builder & WithInitialVelocity(const Vector2D &initialVel)
Returns builder with initial velocity.
std::shared_ptr< VolumeParticleEmitter2 > VolumeParticleEmitter2Ptr
Shared pointer for the VolumeParticleEmitter2 type.
Definition: VolumeParticleEmitter2.h:154
size_t GetMaxNumberOfParticles() const
Returns max number of particles to be emitted.
double GetJitter() const
Returns jitter amount.
void SetPointGenerator(const PointGenerator2Ptr &newPointsGen)
Sets the point generator.
std::shared_ptr< ParticleSystemData2 > ParticleSystemData2Ptr
Shared pointer type of ParticleSystemData2.
Definition: ParticleSystemData2.h:250
1-D array class.
Definition: Array1.h:29
2-D axis-aligned bounding box class.
Definition: BoundingBox2.h:44
Vector2D GetInitialVelocity() const
Sets the initial velocity of the particles.
Definition: pybind11Utils.h:24
void SetSpacing(double newSpacing)
Sets the spacing between particles.
Vector2< double > Vector2D
Double-type 2D vector.
Definition: Vector2.h:341
void SetJitter(double newJitter)
Sets jitter amount between 0 and 1.
Front-end to create VolumeParticleEmitter2 objects step by step.
Definition: VolumeParticleEmitter2.h:159
2-D volumetric particle emitter.
Definition: VolumeParticleEmitter2.h:25
Builder & WithMaxNumberOfParticles(size_t maxNumberOfParticles)
Returns builder with max number of particles.
std::shared_ptr< ImplicitSurface2 > ImplicitSurface2Ptr
Shared pointer type for the ImplicitSurface2.
Definition: ImplicitSurface2.h:43
Builder & WithJitter(double jitter)
Returns builder with jitter amount.
double GetSpacing() const
Returns the spacing between particles.
void SetIsOneShot(bool newValue)
Sets the flag to true if particles are emitted just once.
2-D vector class.
Definition: Vector2.h:26
Builder & WithIsOneShot(bool isOneShot)
Returns builder with one-shot flag.
void SetMaxNumberOfParticles(size_t newMaxNumberOfParticles)
Sets the max number of particles to be emitted.
VolumeParticleEmitter2Ptr MakeShared() const
Builds shared pointer of VolumeParticleEmitter2 instance.
static Builder GetBuilder()
Returns builder fox VolumeParticleEmitter2.
bool GetIsOneShot() const
Returns true if particles should be emitted just once.
std::shared_ptr< PointGenerator2 > PointGenerator2Ptr
Shared pointer for the PointGenerator2 type.
Definition: PointGenerator2.h:53
std::shared_ptr< Surface2 > Surface2Ptr
Shared pointer for the Surface2 type.
Definition: Surface2.h:100
Abstract base class for 2-D particle emitter.
Definition: ParticleEmitter2.h:19
void SetAllowOverlapping(bool newValue)
Sets the flag to true if particles can overlap each other.
VolumeParticleEmitter2(const ImplicitSurface2Ptr &implicitSurface, const BoundingBox2D &bounds, double spacing, const Vector2D &initialVel=Vector2D(), size_t maxNumberOfParticles=std::numeric_limits< size_t >::max(), double jitter=0.0, bool isOneShot=true, bool allowOverlapping=false, uint32_t seed=0)
bool GetAllowOverlapping() const
Returns true if particles can be overlapped.
VolumeParticleEmitter2 Build() const
Builds VolumeParticleEmitter2.