LiquidFun
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
b2ParticleGroup.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2013 Google, Inc.
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 * 1. The origin of this software must not be misrepresented; you must not
11 * claim that you wrote the original software. If you use this software
12 * in a product, an acknowledgment in the product documentation would be
13 * appreciated but is not required.
14 * 2. Altered source versions must be plainly marked as such, and must not be
15 * misrepresented as being the original software.
16 * 3. This notice may not be removed or altered from any source distribution.
17 */
18 #ifndef B2_PARTICLE_GROUP
19 #define B2_PARTICLE_GROUP
20 
22 
23 class b2Shape;
24 class b2World;
25 class b2ParticleSystem;
26 class b2ParticleGroup;
27 class b2ParticleColor;
28 
30 
33 {
44  b2_particleGroupInternalMask =
47 };
48 
52 {
53 
55  {
56  flags = 0;
57  groupFlags = 0;
58  position = b2Vec2_zero;
59  angle = 0;
60  linearVelocity = b2Vec2_zero;
61  angularVelocity = 0;
62  color = b2ParticleColor_zero;
63  strength = 1;
64  shape = NULL;
65  shapes = NULL;
66  shapeCount = 0;
67  stride = 0;
68  particleCount = 0;
69  positionData = NULL;
70  lifetime = 0.0f;
71  userData = NULL;
72  group = NULL;
73  }
74 
76  uint32 flags;
77 
79  uint32 groupFlags;
80 
84 
87  float32 angle;
88 
91 
93  float32 angularVelocity;
94 
97 
100  float32 strength;
101 
103  const b2Shape* shape;
104 
106  const b2Shape* const* shapes;
107 
109  int32 shapeCount;
110 
113  float32 stride;
114 
117 
120 
123  float32 lifetime;
124 
126  void* userData;
127 
130 
131 };
132 
135 {
136 
137 public:
138 
141  const b2ParticleGroup* GetNext() const;
142 
145  const b2ParticleSystem* GetParticleSystem() const;
146 
148  int32 GetParticleCount() const;
149 
151  int32 GetBufferIndex() const;
152 
154  bool ContainsParticle(int32 index) const;
155 
157  int32 GetGroupFlags() const;
158 
160  void SetGroupFlags(int32 flags);
161 
163  float32 GetMass() const;
164 
166  float32 GetInertia() const;
167 
169  b2Vec2 GetCenter() const;
170 
172  b2Vec2 GetLinearVelocity() const;
173 
175  float32 GetAngularVelocity() const;
176 
179  const b2Transform& GetTransform() const;
180 
183  const b2Vec2& GetPosition() const;
184 
187  float32 GetAngle() const;
188 
190  void* GetUserData() const;
191 
193  void SetUserData(void* data);
194 
196  void ApplyForce(const b2Vec2& force);
197 
200  void ApplyLinearImpulse(const b2Vec2& impulse);
201 
207  void DestroyParticles(bool callDestructionListener);
208 
213  void DestroyParticles();
214 
215 private:
216 
217  friend class b2ParticleSystem;
218 
219  b2ParticleSystem* m_system;
220  int32 m_firstIndex, m_lastIndex;
221  uint32 m_groupFlags;
222  float32 m_strength;
223  b2ParticleGroup* m_prev;
224  b2ParticleGroup* m_next;
225 
226  mutable int32 m_timestamp;
227  mutable float32 m_mass;
228  mutable float32 m_inertia;
229  mutable b2Vec2 m_center;
230  mutable b2Vec2 m_linearVelocity;
231  mutable float32 m_angularVelocity;
232  mutable b2Transform m_transform;
233 
234  void* m_userData;
235 
236  b2ParticleGroup();
237  ~b2ParticleGroup();
238  void UpdateStatistics() const;
239 
240 };
241 
243 {
244  return m_next;
245 }
246 
247 inline const b2ParticleGroup* b2ParticleGroup::GetNext() const
248 {
249  return m_next;
250 }
251 
253 {
254  return m_system;
255 }
256 
258 {
259  return m_system;
260 }
261 
263 {
264  return m_lastIndex - m_firstIndex;
265 }
266 
267 inline bool b2ParticleGroup::ContainsParticle(int32 index) const
268 {
269  return m_firstIndex <= index && index < m_lastIndex;
270 }
271 
272 inline b2ParticleGroup::~b2ParticleGroup()
273 {
274 }
275 
277 {
278  return m_firstIndex;
279 }
280 
281 inline int32 b2ParticleGroup::GetGroupFlags() const
282 {
283  return m_groupFlags & ~b2_particleGroupInternalMask;
284 }
285 
286 inline float32 b2ParticleGroup::GetMass() const
287 {
288  UpdateStatistics();
289  return m_mass;
290 }
291 
292 inline float32 b2ParticleGroup::GetInertia() const
293 {
294  UpdateStatistics();
295  return m_inertia;
296 }
297 
299 {
300  UpdateStatistics();
301  return m_center;
302 }
303 
305 {
306  UpdateStatistics();
307  return m_linearVelocity;
308 }
309 
311 {
312  UpdateStatistics();
313  return m_angularVelocity;
314 }
315 
317 {
318  return m_transform;
319 }
320 
322 {
323  return m_transform.p;
324 }
325 
326 inline float32 b2ParticleGroup::GetAngle() const
327 {
328  return m_transform.q.GetAngle();
329 }
330 
331 inline void* b2ParticleGroup::GetUserData() const
332 {
333  return m_userData;
334 }
335 
336 inline void b2ParticleGroup::SetUserData(void* data)
337 {
338  m_userData = data;
339 }
340 
342 {
343  DestroyParticles(false);
344 }
345 
346 #endif
Definition: b2Math.h:411
b2Vec2 linearVelocity
The linear velocity of the group&#39;s origin in world co-ordinates.
Definition: b2ParticleGroup.h:90
float32 stride
Definition: b2ParticleGroup.h:113
uint32 flags
The particle-behavior flags (See b2ParticleFlag).
Definition: b2ParticleGroup.h:76
Keeps its shape.
Definition: b2ParticleGroup.h:37
float32 GetAngle() const
Get the angle in radians.
Definition: b2Math.h:388
void * userData
Use this to store application-specific group data.
Definition: b2ParticleGroup.h:126
Definition: b2ParticleGroup.h:51
float32 angle
Definition: b2ParticleGroup.h:87
const b2Shape *const * shapes
A array of shapes where particles will be added.
Definition: b2ParticleGroup.h:106
float32 GetMass() const
Get the total mass of the group: the sum of all particles in it.
Definition: b2ParticleGroup.h:286
const b2Vec2 * positionData
The initial positions of the particleCount particles.
Definition: b2ParticleGroup.h:119
b2ParticleGroupFlag
The particle group type. Can be combined with the | operator.
Definition: b2ParticleGroup.h:32
b2Vec2 position
Definition: b2ParticleGroup.h:83
Will be destroyed on next simulation step.
Definition: b2ParticleGroup.h:41
void ApplyForce(const b2Vec2 &force)
Call b2ParticleSystem::ApplyForce for every particle in the group.
Definition: b2ParticleGroup.cpp:88
b2ParticleGroup * group
An existing particle group to which the particles will be added.
Definition: b2ParticleGroup.h:129
Updates depth data on next simulation step.
Definition: b2ParticleGroup.h:43
void SetGroupFlags(int32 flags)
Set the construction flags for the group.
Definition: b2ParticleGroup.cpp:45
uint32 groupFlags
The group-construction flags (See b2ParticleGroupFlag).
Definition: b2ParticleGroup.h:79
b2Vec2 GetLinearVelocity() const
Get the linear velocity of the group.
Definition: b2ParticleGroup.h:304
Definition: b2World.h:44
Definition: b2ParticleSystem.h:189
Won&#39;t be destroyed if it gets empty.
Definition: b2ParticleGroup.h:39
bool ContainsParticle(int32 index) const
Does this group contain the particle.
Definition: b2ParticleGroup.h:267
Definition: b2Shape.h:43
b2Vec2 GetCenter() const
Get the center of gravity for the group.
Definition: b2ParticleGroup.h:298
Small color object for each particle.
Definition: b2Particle.h:81
float32 angularVelocity
The angular velocity of the group.
Definition: b2ParticleGroup.h:93
float32 GetAngle() const
Definition: b2ParticleGroup.h:326
int32 particleCount
The number of particles in addition to ones added in the shape.
Definition: b2ParticleGroup.h:116
const b2Transform & GetTransform() const
Definition: b2ParticleGroup.h:316
A group of particles. b2ParticleGroup::CreateParticleGroup creates these.
Definition: b2ParticleGroup.h:134
void SetUserData(void *data)
Set the user data. Use this to store your application specific data.
Definition: b2ParticleGroup.h:336
float32 strength
Definition: b2ParticleGroup.h:100
void ApplyLinearImpulse(const b2Vec2 &impulse)
Definition: b2ParticleGroup.cpp:93
int32 GetParticleCount() const
Get the number of particles.
Definition: b2ParticleGroup.h:262
Prevents overlapping or leaking.
Definition: b2ParticleGroup.h:35
float32 GetInertia() const
Get the moment of inertia for the group.
Definition: b2ParticleGroup.h:292
b2ParticleSystem * GetParticleSystem()
Get the particle system that holds this particle group.
Definition: b2ParticleGroup.h:252
int32 shapeCount
The number of shapes.
Definition: b2ParticleGroup.h:109
void * GetUserData() const
Get the user data pointer that was provided in the group definition.
Definition: b2ParticleGroup.h:331
const b2Vec2 & GetPosition() const
Definition: b2ParticleGroup.h:321
int32 GetBufferIndex() const
Get the offset of this group in the global particle buffer.
Definition: b2ParticleGroup.h:276
A 2D column vector.
Definition: b2Math.h:56
b2ParticleGroup * GetNext()
Get the next particle group from the list in b2_World.
Definition: b2ParticleGroup.h:242
void DestroyParticles()
Definition: b2ParticleGroup.h:341
b2ParticleColor color
The color of all particles in the group.
Definition: b2ParticleGroup.h:96
float32 GetAngularVelocity() const
Get the angular velocity of the group.
Definition: b2ParticleGroup.h:310
const b2Shape * shape
The shape where particles will be added.
Definition: b2ParticleGroup.h:103
float32 lifetime
Definition: b2ParticleGroup.h:123
int32 GetGroupFlags() const
Get the construction flags for the group.
Definition: b2ParticleGroup.h:281