LiquidFun
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
b2ParticleGroup.h
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 
21 #include <Box2D/Particle/b2Particle.h>
22 
23 class b2Shape;
24 class b2World;
25 class b2ParticleSystem;
26 class b2ParticleGroup;
27 struct b2ParticleColor;
28 
29 enum b2ParticleGroupFlag
30 {
31  b2_solidParticleGroup = 1 << 0, // resists penetration
32  b2_rigidParticleGroup = 1 << 1, // keeps its shape
33 };
34 
38 {
39 
41  {
42  flags = 0;
43  groupFlags = 0;
44  position = b2Vec2_zero;
45  angle = 0;
46  linearVelocity = b2Vec2_zero;
47  angularVelocity = 0;
48  color = b2ParticleColor_zero;
49  strength = 1;
50  shape = NULL;
51  destroyAutomatically = true;
52  userData = NULL;
53  }
54 
56  uint32 flags;
57 
59  uint32 groupFlags;
60 
64 
67  float32 angle;
68 
71 
73  float32 angularVelocity;
74 
77 
79  float32 strength;
80 
82  const b2Shape* shape;
83 
86 
88  void* userData;
89 
90 };
91 
94 {
95 
96 public:
97 
100  const b2ParticleGroup* GetNext() const;
101 
103  int32 GetParticleCount() const;
104 
106  int32 GetBufferIndex() const;
107 
109  int32 GetGroupFlags() const;
110 
112  void SetGroupFlags(int32 flags);
113 
115  float32 GetMass() const;
116 
118  float32 GetInertia() const;
119 
121  b2Vec2 GetCenter() const;
122 
124  b2Vec2 GetLinearVelocity() const;
125 
127  float32 GetAngularVelocity() const;
128 
131  const b2Transform& GetTransform() const;
132 
135  const b2Vec2& GetPosition() const;
136 
139  float32 GetAngle() const;
140 
142  void* GetUserData() const;
143 
145  void SetUserData(void* data);
146 
147 private:
148 
149  friend class b2ParticleSystem;
150 
151  b2ParticleSystem* m_system;
152  int32 m_firstIndex, m_lastIndex;
153  uint32 m_groupFlags;
154  float32 m_strength;
155  b2ParticleGroup* m_prev;
156  b2ParticleGroup* m_next;
157 
158  mutable int32 m_timestamp;
159  mutable float32 m_mass;
160  mutable float32 m_inertia;
161  mutable b2Vec2 m_center;
162  mutable b2Vec2 m_linearVelocity;
163  mutable float32 m_angularVelocity;
164  mutable b2Transform m_transform;
165 
166  unsigned m_destroyAutomatically:1;
167  unsigned m_toBeDestroyed:1;
168  unsigned m_toBeSplit:1;
169 
170  void* m_userData;
171 
172  b2ParticleGroup();
173  ~b2ParticleGroup();
174  void UpdateStatistics() const;
175 
176 };
177 
179 {
180  return m_next;
181 }
182 
183 inline const b2ParticleGroup* b2ParticleGroup::GetNext() const
184 {
185  return m_next;
186 }
187 
189 {
190  return m_lastIndex - m_firstIndex;
191 }
192 
193 #endif
Definition: b2Math.h:361
b2Vec2 linearVelocity
The linear velocity of the group&#39;s origin in world co-ordinates.
Definition: b2ParticleGroup.h:70
uint32 flags
The particle-behavior flags.
Definition: b2ParticleGroup.h:56
void * userData
Use this to store application-specific group data.
Definition: b2ParticleGroup.h:88
bool destroyAutomatically
If true, destroy the group automatically after its last particle has been destroyed.
Definition: b2ParticleGroup.h:85
Definition: b2ParticleGroup.h:37
float32 angle
Definition: b2ParticleGroup.h:67
float32 GetMass() const
Get the total mass of the group: the sum of all particles in it.
Definition: b2ParticleGroup.cpp:67
b2Vec2 position
Definition: b2ParticleGroup.h:63
void SetGroupFlags(int32 flags)
Set the construction flags for the group.
Definition: b2ParticleGroup.cpp:62
uint32 groupFlags
The group-construction flags.
Definition: b2ParticleGroup.h:59
b2Vec2 GetLinearVelocity() const
Get the linear velocity of the group.
Definition: b2ParticleGroup.cpp:85
Definition: b2World.h:44
Definition: b2ParticleSystem.h:74
Definition: b2Shape.h:43
b2Vec2 GetCenter() const
Get the center of gravity for the group.
Definition: b2ParticleGroup.cpp:79
float32 angularVelocity
The angular velocity of the group.
Definition: b2ParticleGroup.h:73
float32 GetAngle() const
Definition: b2ParticleGroup.cpp:107
const b2Transform & GetTransform() const
Definition: b2ParticleGroup.cpp:97
A group of particles. These are created via b2World::CreateParticleGroup.
Definition: b2ParticleGroup.h:93
void SetUserData(void *data)
Set the user data. Use this to store your application specific data.
Definition: b2ParticleGroup.cpp:117
float32 strength
The strength of cohesion among the particles in a group with flag b2_elasticParticle or b2_springPart...
Definition: b2ParticleGroup.h:79
int32 GetParticleCount() const
Get the number of particles.
Definition: b2ParticleGroup.h:188
float32 GetInertia() const
Get the moment of inertia for the group.
Definition: b2ParticleGroup.cpp:73
void * GetUserData() const
Get the user data pointer that was provided in the group definition.
Definition: b2ParticleGroup.cpp:112
const b2Vec2 & GetPosition() const
Definition: b2ParticleGroup.cpp:102
Small color object for each particle.
Definition: b2Particle.h:42
int32 GetBufferIndex() const
Get the offset of this group in the global particle buffer.
Definition: b2ParticleGroup.cpp:52
A 2D column vector.
Definition: b2Math.h:64
b2ParticleGroup * GetNext()
Get the next particle group from the list in b2_World.
Definition: b2ParticleGroup.h:178
b2ParticleColor color
The color of all particles in the group.
Definition: b2ParticleGroup.h:76
float32 GetAngularVelocity() const
Get the angular velocity of the group.
Definition: b2ParticleGroup.cpp:91
const b2Shape * shape
Shape containing the particle group.
Definition: b2ParticleGroup.h:82
int32 GetGroupFlags() const
Get the construction flags for the group.
Definition: b2ParticleGroup.cpp:57