Jet  v1.3.3
particle_system_solver2.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_PARTICLE_SYSTEM_SOLVER2_H_
8 #define INCLUDE_JET_PARTICLE_SYSTEM_SOLVER2_H_
9 
10 #include <jet/collider2.h>
11 #include <jet/constants.h>
12 #include <jet/vector_field2.h>
13 #include <jet/particle_emitter2.h>
15 #include <jet/physics_animation.h>
16 
17 namespace jet {
18 
32  public:
33  class Builder;
34 
37 
40  double radius,
41  double mass);
42 
45 
47  double dragCoefficient() const;
48 
57  void setDragCoefficient(double newDragCoefficient);
58 
60  double restitutionCoefficient() const;
61 
71  void setRestitutionCoefficient(double newRestitutionCoefficient);
72 
74  const Vector2D& gravity() const;
75 
77  void setGravity(const Vector2D& newGravity);
78 
88 
90  const Collider2Ptr& collider() const;
91 
93  void setCollider(const Collider2Ptr& newCollider);
94 
96  const ParticleEmitter2Ptr& emitter() const;
97 
99  void setEmitter(const ParticleEmitter2Ptr& newEmitter);
100 
102  const VectorField2Ptr& wind() const;
103 
112  void setWind(const VectorField2Ptr& newWind);
113 
115  static Builder builder();
116 
117  protected:
119  void onInitialize() override;
120 
122  void onAdvanceTimeStep(double timeStepInSeconds) override;
123 
125  virtual void accumulateForces(double timeStepInSeconds);
126 
128  virtual void onBeginAdvanceTimeStep(double timeStepInSeconds);
129 
131  virtual void onEndAdvanceTimeStep(double timeStepInSeconds);
132 
135 
139  ArrayAccessor1<Vector2D> newPositions,
140  ArrayAccessor1<Vector2D> newVelocities);
141 
144 
145  private:
146  double _dragCoefficient = 1e-4;
147  double _restitutionCoefficient = 0.0;
148  Vector2D _gravity = Vector2D(0.0, kGravity);
149 
150  ParticleSystemData2Ptr _particleSystemData;
151  ParticleSystemData2::VectorData _newPositions;
152  ParticleSystemData2::VectorData _newVelocities;
153  Collider2Ptr _collider;
154  ParticleEmitter2Ptr _emitter;
155  VectorField2Ptr _wind;
156 
157  void beginAdvanceTimeStep(double timeStepInSeconds);
158 
159  void endAdvanceTimeStep(double timeStepInSeconds);
160 
161  void accumulateExternalForces();
162 
163  void timeIntegration(double timeStepInSeconds);
164 
165  void updateCollider(double timeStepInSeconds);
166 
167  void updateEmitter(double timeStepInSeconds);
168 };
169 
171 typedef std::shared_ptr<ParticleSystemSolver2> ParticleSystemSolver2Ptr;
172 
173 
177 template <typename DerivedBuilder>
179  public:
181  DerivedBuilder& withRadius(double radius);
182 
184  DerivedBuilder& withMass(double mass);
185 
186  protected:
187  double _radius = 1e-3;
188  double _mass = 1e-3;
189 };
190 
191 template <typename T>
193  _radius = radius;
194  return static_cast<T&>(*this);
195 }
196 
197 template <typename T>
199  _mass = mass;
200  return static_cast<T&>(*this);
201 }
202 
207  : public ParticleSystemSolverBuilderBase2<ParticleSystemSolver2::Builder> {
208  public:
211 
214 };
215 
216 } // namespace jet
217 
218 #endif // INCLUDE_JET_PARTICLE_SYSTEM_SOLVER2_H_
jet::Array< T, 1 >
1-D array class.
Definition: array1.h:31
jet::ParticleSystemSolver2::emitter
const ParticleEmitter2Ptr & emitter() const
Returns the emitter.
jet::ParticleSystemSolverBuilderBase2::withRadius
DerivedBuilder & withRadius(double radius)
Returns builder with particle radius.
Definition: particle_system_solver2.h:192
jet::ParticleSystemSolver2::~ParticleSystemSolver2
virtual ~ParticleSystemSolver2()
Destructor.
jet::ParticleSystemSolver2::ParticleSystemSolver2
ParticleSystemSolver2(double radius, double mass)
Constructs a solver with particle parameters.
jet::ParticleSystemSolverBuilderBase2::_radius
double _radius
Definition: particle_system_solver2.h:187
jet::ParticleSystemSolverBuilderBase2
Base class for particle-based solver builder.
Definition: particle_system_solver2.h:178
jet::Vector2D
Vector2< double > Vector2D
Double-type 2D vector.
Definition: vector2.h:340
jet::PhysicsAnimation
Abstract base class for physics-based animation.
Definition: physics_animation.h:20
jet::ParticleSystemSolverBuilderBase2::_mass
double _mass
Definition: particle_system_solver2.h:188
jet::ParticleSystemSolver2::setRestitutionCoefficient
void setRestitutionCoefficient(double newRestitutionCoefficient)
Sets the restitution coefficient.
jet::ParticleSystemSolver2::onInitialize
void onInitialize() override
Initializes the simulator.
jet::ParticleSystemSolver2Ptr
std::shared_ptr< ParticleSystemSolver2 > ParticleSystemSolver2Ptr
Shared pointer type for the ParticleSystemSolver2.
Definition: particle_system_solver2.h:171
jet::ParticleSystemSolver2::wind
const VectorField2Ptr & wind() const
Returns the wind field.
vector_field2.h
jet::ParticleSystemSolver2::Builder::makeShared
ParticleSystemSolver2Ptr makeShared() const
Builds shared pointer of ParticleSystemSolver2 instance.
jet::ParticleSystemSolver2::onBeginAdvanceTimeStep
virtual void onBeginAdvanceTimeStep(double timeStepInSeconds)
Called when a time-step is about to begin.
jet::ParticleSystemSolver2::dragCoefficient
double dragCoefficient() const
Returns the drag coefficient.
jet::ParticleSystemSolver2::gravity
const Vector2D & gravity() const
Returns the gravity.
jet
Definition: advection_solver2.h:18
jet::ParticleSystemSolver2::Builder
Front-end to create ParticleSystemSolver2 objects step by step.
Definition: particle_system_solver2.h:207
particle_emitter2.h
jet::ParticleSystemSolver2::resolveCollision
void resolveCollision()
Resolves any collisions occured by the particles.
jet::ParticleSystemSolver2::collider
const Collider2Ptr & collider() const
Returns the collider.
jet::Vector< T, 2 >
2-D vector class.
Definition: vector2.h:24
jet::ParticleSystemSolver2::resolveCollision
void resolveCollision(ArrayAccessor1< Vector2D > newPositions, ArrayAccessor1< Vector2D > newVelocities)
jet::ParticleSystemSolver2::onEndAdvanceTimeStep
virtual void onEndAdvanceTimeStep(double timeStepInSeconds)
Called after a time-step is completed.
jet::ParticleSystemSolver2::setWind
void setWind(const VectorField2Ptr &newWind)
Sets the wind.
jet::Collider2Ptr
std::shared_ptr< Collider2 > Collider2Ptr
Shared pointer type for the Collider2.
Definition: collider2.h:118
jet::ParticleSystemSolver2::setParticleSystemData
void setParticleSystemData(const ParticleSystemData2Ptr &newParticles)
Assign a new particle system data.
jet::ParticleSystemSolver2::restitutionCoefficient
double restitutionCoefficient() const
Sets the restitution coefficient.
collider2.h
jet::ParticleSystemSolver2::setCollider
void setCollider(const Collider2Ptr &newCollider)
Sets the collider.
jet::ParticleSystemSolver2::onAdvanceTimeStep
void onAdvanceTimeStep(double timeStepInSeconds) override
Called to advane a single time-step.
particle_system_data2.h
jet::kGravity
constexpr double kGravity
Gravity.
Definition: constants.h:301
jet::ParticleSystemSolver2::accumulateForces
virtual void accumulateForces(double timeStepInSeconds)
Accumulates forces applied to the particles.
jet::ParticleSystemSolver2::setGravity
void setGravity(const Vector2D &newGravity)
Sets the gravity.
jet::ParticleEmitter2Ptr
std::shared_ptr< ParticleEmitter2 > ParticleEmitter2Ptr
Shared pointer for the ParticleEmitter2 type.
Definition: particle_emitter2.h:79
jet::VectorField2Ptr
std::shared_ptr< VectorField2 > VectorField2Ptr
Shared pointer for the VectorField2 type.
Definition: vector_field2.h:40
jet::ParticleSystemSolver2::builder
static Builder builder()
Returns builder fox ParticleSystemSolver2.
constants.h
jet::ParticleSystemSolverBuilderBase2::withMass
DerivedBuilder & withMass(double mass)
Returns builder with mass per particle.
Definition: particle_system_solver2.h:198
jet::ParticleSystemData2Ptr
std::shared_ptr< ParticleSystemData2 > ParticleSystemData2Ptr
Shared pointer type of ParticleSystemData2.
Definition: particle_system_data2.h:250
jet::ParticleSystemSolver2::ParticleSystemSolver2
ParticleSystemSolver2()
Constructs an empty solver.
physics_animation.h
jet::ParticleSystemSolver2::setEmitter
void setEmitter(const ParticleEmitter2Ptr &newEmitter)
Sets the emitter.
jet::ParticleSystemSolver2
Basic 2-D particle system solver.
Definition: particle_system_solver2.h:31
jet::ParticleSystemSolver2::setDragCoefficient
void setDragCoefficient(double newDragCoefficient)
Sets the drag coefficient.
jet::ParticleSystemSolver2::particleSystemData
const ParticleSystemData2Ptr & particleSystemData() const
Returns the particle system data.
jet::ArrayAccessor< T, 1 >
1-D array accessor class.
Definition: array_accessor1.h:27
jet::ParticleSystemSolver2::Builder::build
ParticleSystemSolver2 build() const
Builds ParticleSystemSolver2.