Jet  v1.3.3
particle_system_solver3.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_SOLVER3_H_
8 #define INCLUDE_JET_PARTICLE_SYSTEM_SOLVER3_H_
9 
10 #include <jet/collider3.h>
11 #include <jet/constants.h>
12 #include <jet/vector_field3.h>
13 #include <jet/particle_emitter3.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 Vector3D& gravity() const;
75 
77  void setGravity(const Vector3D& newGravity);
78 
88 
90  const Collider3Ptr& collider() const;
91 
93  void setCollider(const Collider3Ptr& newCollider);
94 
96  const ParticleEmitter3Ptr& emitter() const;
97 
99  void setEmitter(const ParticleEmitter3Ptr& newEmitter);
100 
102  const VectorField3Ptr& wind() const;
103 
112  void setWind(const VectorField3Ptr& 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<Vector3D> newPositions,
140  ArrayAccessor1<Vector3D> newVelocities);
141 
144 
145  private:
146  double _dragCoefficient = 1e-4;
147  double _restitutionCoefficient = 0.0;
148  Vector3D _gravity = Vector3D(0.0, kGravity, 0.0);
149 
150  ParticleSystemData3Ptr _particleSystemData;
151  ParticleSystemData3::VectorData _newPositions;
152  ParticleSystemData3::VectorData _newVelocities;
153  Collider3Ptr _collider;
154  ParticleEmitter3Ptr _emitter;
155  VectorField3Ptr _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<ParticleSystemSolver3> ParticleSystemSolver3Ptr;
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 ParticleSystemSolverBuilderBase3<ParticleSystemSolver3::Builder> {
208  public:
211 
214 };
215 
216 } // namespace jet
217 
218 #endif // INCLUDE_JET_PARTICLE_SYSTEM_SOLVER3_H_
jet::Array< T, 1 >
1-D array class.
Definition: array1.h:31
jet::ParticleSystemSolver3::wind
const VectorField3Ptr & wind() const
Returns the wind field.
jet::ParticleSystemSolver3::emitter
const ParticleEmitter3Ptr & emitter() const
Returns the emitter.
jet::ParticleSystemSolver3::resolveCollision
void resolveCollision()
Resolves any collisions occured by the particles.
jet::ParticleSystemSolver3::setParticleSystemData
void setParticleSystemData(const ParticleSystemData3Ptr &newParticles)
Assign a new particle system data.
jet::ParticleSystemSolver3::ParticleSystemSolver3
ParticleSystemSolver3(double radius, double mass)
Constructs a solver with particle parameters.
jet::ParticleSystemSolver3::~ParticleSystemSolver3
virtual ~ParticleSystemSolver3()
Destructor.
jet::ParticleSystemData3Ptr
std::shared_ptr< ParticleSystemData3 > ParticleSystemData3Ptr
Shared pointer type of ParticleSystemData3.
Definition: particle_system_data3.h:250
jet::PhysicsAnimation
Abstract base class for physics-based animation.
Definition: physics_animation.h:20
particle_emitter3.h
jet::ParticleEmitter3Ptr
std::shared_ptr< ParticleEmitter3 > ParticleEmitter3Ptr
Shared pointer for the ParticleEmitter3 type.
Definition: particle_emitter3.h:79
jet::ParticleSystemSolver3::onEndAdvanceTimeStep
virtual void onEndAdvanceTimeStep(double timeStepInSeconds)
Called after a time-step is completed.
jet::ParticleSystemSolver3::onBeginAdvanceTimeStep
virtual void onBeginAdvanceTimeStep(double timeStepInSeconds)
Called when a time-step is about to begin.
jet::ParticleSystemSolver3::setRestitutionCoefficient
void setRestitutionCoefficient(double newRestitutionCoefficient)
Sets the restitution coefficient.
jet::ParticleSystemSolver3::Builder
Front-end to create ParticleSystemSolver3 objects step by step.
Definition: particle_system_solver3.h:207
particle_system_data3.h
jet::ParticleSystemSolver3::setWind
void setWind(const VectorField3Ptr &newWind)
Sets the wind.
jet::ParticleSystemSolver3::onAdvanceTimeStep
void onAdvanceTimeStep(double timeStepInSeconds) override
Called to advane a single time-step.
jet::ParticleSystemSolver3::ParticleSystemSolver3
ParticleSystemSolver3()
Constructs an empty solver.
collider3.h
jet::ParticleSystemSolver3::restitutionCoefficient
double restitutionCoefficient() const
Sets the restitution coefficient.
jet::ParticleSystemSolver3::accumulateForces
virtual void accumulateForces(double timeStepInSeconds)
Accumulates forces applied to the particles.
jet
Definition: advection_solver2.h:18
jet::ParticleSystemSolver3::builder
static Builder builder()
Returns builder fox ParticleSystemSolver3.
jet::ParticleSystemSolverBuilderBase3::withMass
DerivedBuilder & withMass(double mass)
Returns builder with mass per particle.
Definition: particle_system_solver3.h:198
jet::ParticleSystemSolverBuilderBase3::withRadius
DerivedBuilder & withRadius(double radius)
Returns builder with particle radius.
Definition: particle_system_solver3.h:192
jet::ParticleSystemSolver3::particleSystemData
const ParticleSystemData3Ptr & particleSystemData() const
Returns the particle system data.
jet::ParticleSystemSolverBuilderBase3::_mass
double _mass
Definition: particle_system_solver3.h:188
jet::ParticleSystemSolver3::Builder::build
ParticleSystemSolver3 build() const
Builds ParticleSystemSolver3.
jet::ParticleSystemSolver3
Basic 3-D particle system solver.
Definition: particle_system_solver3.h:31
jet::ParticleSystemSolver3::setCollider
void setCollider(const Collider3Ptr &newCollider)
Sets the collider.
jet::ParticleSystemSolver3::dragCoefficient
double dragCoefficient() const
Returns the drag coefficient.
jet::ParticleSystemSolver3::onInitialize
void onInitialize() override
Initializes the simulator.
vector_field3.h
jet::ParticleSystemSolverBuilderBase3::_radius
double _radius
Definition: particle_system_solver3.h:187
jet::kGravity
constexpr double kGravity
Gravity.
Definition: constants.h:301
jet::ParticleSystemSolver3::resolveCollision
void resolveCollision(ArrayAccessor1< Vector3D > newPositions, ArrayAccessor1< Vector3D > newVelocities)
jet::Vector3D
Vector3< double > Vector3D
Double-type 3D vector.
Definition: vector3.h:349
jet::ParticleSystemSolver3::setEmitter
void setEmitter(const ParticleEmitter3Ptr &newEmitter)
Sets the emitter.
constants.h
jet::Vector< T, 3 >
3-D vector class.
Definition: vector3.h:25
jet::ParticleSystemSolver3Ptr
std::shared_ptr< ParticleSystemSolver3 > ParticleSystemSolver3Ptr
Shared pointer type for the ParticleSystemSolver3.
Definition: particle_system_solver3.h:171
physics_animation.h
jet::Collider3Ptr
std::shared_ptr< Collider3 > Collider3Ptr
Shared pointer type for the Collider2.
Definition: collider3.h:118
jet::ParticleSystemSolver3::Builder::makeShared
ParticleSystemSolver3Ptr makeShared() const
Builds shared pointer of ParticleSystemSolver3 instance.
jet::ParticleSystemSolver3::collider
const Collider3Ptr & collider() const
Returns the collider.
jet::ParticleSystemSolver3::setGravity
void setGravity(const Vector3D &newGravity)
Sets the gravity.
jet::ParticleSystemSolver3::gravity
const Vector3D & gravity() const
Returns the gravity.
jet::ParticleSystemSolverBuilderBase3
Base class for particle-based solver builder.
Definition: particle_system_solver3.h:178
jet::ArrayAccessor< T, 1 >
1-D array accessor class.
Definition: array_accessor1.h:27
jet::VectorField3Ptr
std::shared_ptr< VectorField3 > VectorField3Ptr
Shared pointer for the VectorField3 type.
Definition: vector_field3.h:40
jet::ParticleSystemSolver3::setDragCoefficient
void setDragCoefficient(double newDragCoefficient)
Sets the drag coefficient.