iMSTK
Interactive Medical Simulation Toolkit
imstkRenderParticleEmitter.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkMath.h"
10 #include "imstkAnimationModel.h"
11 #include "imstkColor.h"
12 
13 namespace imstk
14 {
15 struct RenderParticle;
16 class StopWatch;
17 
24 {
25  float m_time = 0;
26  Color m_color = Color::White;
27  Vec3f m_acceleration = Vec3f(0, 0, 0);
28  float m_rotationalAcceleration = 0;
29  float m_scale = 1.0f;
30 };
31 
39 {
40 public:
44  enum class Shape
45  {
46  Cube
47  };
48 
52  enum class Mode
53  {
54  Continuous,
55  Burst
56  };
57 
61  explicit RenderParticleEmitter(std::shared_ptr<Geometry> geometry,
62  const float time = 3000.0f,
63  Mode mode = Mode::Continuous);
64 
69  virtual void setGeometry(std::shared_ptr<Geometry> renderParticles);
70 
75  RenderParticleEmitter::Mode getEmitterMode() const;
76 
81  void setEmitterSize(const float size);
82 
97  void setInitialVelocityRange(const Vec3f minDirection,
98  const Vec3f maxDirection,
99  const float minSpeed,
100  const float maxSpeed,
101  const float minRotationSpeed,
102  const float maxRotationSpeed);
103 
109  bool addKeyFrame(RenderParticleKeyFrame keyFrame);
110 
114  RenderParticleKeyFrame* getStartKeyFrame();
115  RenderParticleKeyFrame* getEndKeyFrame();
116 
121  std::vector<RenderParticleKeyFrame>& getKeyFrames();
122 
127  virtual void reset();
128 
132  virtual void update();
133 
134 protected:
138  void initializeParticles();
139 
143  void interpolateColor(Color& destination,
144  const Color& sourceA,
145  const Color& sourceB,
146  const float alpha);
147 
151  void emitParticle(std::unique_ptr<RenderParticle>& particle);
152 
157  float getRandomNormalizedFloat();
158 
159  std::vector<RenderParticleKeyFrame> m_keyFrames;
160 
164  = RenderParticleEmitter::Shape::Cube;
165 
166  Vec3f m_minDirection;
167  Vec3f m_maxDirection;
168  float m_minSpeed;
169  float m_maxSpeed;
170  float m_minRotationSpeed;
171  float m_maxRotationSpeed;
172 
173  float m_time;
174  float m_emitTime;
175 
176  std::unique_ptr<StopWatch> m_stopWatch;
177 
178  double m_lastUpdateTime = 0.0;
179  bool m_started = false;
180 
181  float m_emitterSize = 1.0f;
182 
183  const int c_maxNumKeyFrames = 16;
184 
185  std::shared_ptr<Geometry> m_animationGeometry = nullptr;
186  std::vector<std::unique_ptr<RenderParticle>>* m_particles;
187 };
188 } // imstk
Keyframe for particle animation.
Compound Geometry.
std::vector< RenderParticleKeyFrame > m_keyFrames
Particle keyframes.
Emitter continuously releases/recycles particles.
float m_time
total time for particle system
Contains geometric and animation render information.
Color in RGB space.
Definition: imstkColor.h:24
static Color White
Various commonly used colors.
Definition: imstkColor.h:112
Animation method for rendering particles Common use cases include smoke and fire. ...