LiquidFun
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
b2ParticleSystem.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_SYSTEM_H
19 #define B2_PARTICLE_SYSTEM_H
20 
21 #include <Box2D/Common/b2SlabAllocator.h>
23 #include <Box2D/Dynamics/b2TimeStep.h>
24 
25 #ifdef LIQUIDFUN_UNIT_TESTS
26 #include <gtest/gtest.h>
27 #endif // LIQUIDFUN_UNIT_TESTS
28 
29 class b2World;
30 class b2Body;
31 class b2Shape;
32 class b2ParticleGroup;
33 class b2BlockAllocator;
34 class b2StackAllocator;
35 class b2QueryCallback;
36 class b2RayCastCallback;
37 class b2Fixture;
38 class b2ContactFilter;
39 class b2ContactListener;
40 struct b2ParticleGroupDef;
41 struct b2Vec2;
42 struct b2AABB;
43 class b2ParticlePairSet;
44 
46 {
48  int32 indexA, indexB;
49 
52  uint32 flags;
53 
57  float32 weight;
58 
61 };
62 
64 {
66  int32 index;
67 
70 
73 
75  float32 weight;
76 
79 
81  float32 mass;
82 };
83 
85 {
87  {
88  radius = 1.0f;
89 
90  // Initialize physical coefficients to the maximum values that
91  // maintain numerical stability.
92  pressureStrength = 0.05f;
93  dampingStrength = 1.0f;
94  elasticStrength = 0.25f;
95  springStrength = 0.25f;
96  viscousStrength = 0.25f;
99  repulsiveStrength = 1.0f;
100  powderStrength = 0.5f;
101  ejectionStrength = 0.5f;
102  staticPressureStrength = 0.2f;
105  colorMixingStrength = 0.5f;
106  destroyByAge = true;
107  lifetimeGranularity = 1.0f / 60.0f;
108  }
109 
111  float32 radius;
112 
116 
120 
124 
127  float32 springStrength;
128 
132 
136 
141 
147 
150  float32 powderStrength;
151 
155 
161 
165 
169 
174 
179 
187 };
188 
190 {
191 public:
199  int32 CreateParticle(const b2ParticleDef& def);
200 
202  const b2ParticleHandle* GetParticleHandleFromIndex(const int32 index);
203 
207  void DestroyParticle(int32 index)
208  {
209  DestroyParticle(index, false);
210  }
211 
217  void DestroyParticle(int32 index, bool callDestructionListener);
218 
226  void DestroyOldestParticle(const int32 index,
227  const bool callDestructionListener);
228 
238  int32 DestroyParticlesInShape(const b2Shape& shape, const b2Transform& xf)
239  {
240  return DestroyParticlesInShape(shape, xf, false);
241  }
242 
254  int32 DestroyParticlesInShape(const b2Shape& shape, const b2Transform& xf,
255  bool callDestructionListener);
256 
261 
266  void JoinParticleGroups(b2ParticleGroup* groupA, b2ParticleGroup* groupB);
267 
273  const b2ParticleGroup* GetParticleGroupList() const;
274 
276  int32 GetParticleGroupCount() const;
277 
279  int32 GetParticleCount() const;
280 
282  int32 GetMaxParticleCount() const;
283 
291  void SetMaxParticleCount(int32 count);
292 
297  void SetPaused(bool paused);
298 
302  bool GetPaused() const;
303 
308  void SetDensity(float32 density);
309 
311  float32 GetDensity() const;
312 
315  void SetGravityScale(float32 gravityScale);
316 
318  float32 GetGravityScale() const;
319 
323  void SetDamping(float32 damping);
324 
326  float32 GetDamping() const;
327 
336  void SetStaticPressureIterations(int32 iterations);
337 
339  int32 GetStaticPressureIterations() const;
340 
345  void SetRadius(float32 radius);
346 
348  float32 GetRadius() const;
349 
354  const b2Vec2* GetPositionBuffer() const;
355 
360  const b2Vec2* GetVelocityBuffer() const;
361 
366  const b2ParticleColor* GetColorBuffer() const;
367 
372  const b2ParticleGroup* const* GetGroupBuffer() const;
373 
377  void** GetUserDataBuffer();
378  void* const* GetUserDataBuffer() const;
379 
383  const uint32* GetFlagsBuffer() const;
384 
386  void SetParticleFlags(int32 index, uint32 flags);
388  uint32 GetParticleFlags(const int32 index);
389 
402  void SetFlagsBuffer(uint32* buffer, int32 capacity);
403  void SetPositionBuffer(b2Vec2* buffer, int32 capacity);
404  void SetVelocityBuffer(b2Vec2* buffer, int32 capacity);
405  void SetColorBuffer(b2ParticleColor* buffer, int32 capacity);
406  void SetUserDataBuffer(void** buffer, int32 capacity);
407 
412  int32 GetContactCount();
413 
418  int32 GetBodyContactCount();
419 
424  void SetStuckThreshold(int32 iterations);
425 
428  const int32* GetStuckCandidates() const;
429 
431  int32 GetStuckCandidateCount() const;
432 
434  float32 ComputeCollisionEnergy() const;
435 
443  void SetStrictContactCheck(bool enabled);
445  bool GetStrictContactCheck() const;
446 
450  void SetParticleLifetime(const int32 index, const float32 lifetime);
455  float32 GetParticleLifetime(const int32 index);
456 
465  void SetDestructionByAge(const bool enable);
468  bool GetDestructionByAge() const;
469 
472  const int32* GetExpirationTimeBuffer();
476  float32 ExpirationTimeToLifetime(const int32 expirationTime) const;
485  const int32* GetIndexByExpirationTimeBuffer();
486 
492  void ParticleApplyLinearImpulse(int32 index, const b2Vec2& impulse);
493 
504  void ApplyLinearImpulse(int32 firstIndex, int32 lastIndex,
505  const b2Vec2& impulse);
506 
510  void ParticleApplyForce(int32 index, const b2Vec2& force);
511 
519  void ApplyForce(int32 firstIndex, int32 lastIndex, const b2Vec2& force);
520 
523  const b2ParticleSystem* GetNext() const;
524 
530  void QueryAABB(b2QueryCallback* callback, const b2AABB& aabb) const;
531 
538  void QueryShapeAABB(b2QueryCallback* callback, const b2Shape& shape,
539  const b2Transform& xf) const;
540 
548  void RayCast(b2RayCastCallback* callback, const b2Vec2& point1,
549  const b2Vec2& point2) const;
550 
554  void ComputeAABB(b2AABB* const aabb) const;
555 
556 private:
557  friend class b2World;
558  friend class b2ParticleGroup;
559  friend class b2ParticleBodyContactRemovePredicate;
560 #ifdef LIQUIDFUN_UNIT_TESTS
561  FRIEND_TEST(FunctionTests, GetParticleMass);
562 #endif // LIQUIDFUN_UNIT_TESTS
563 
564  template <typename T>
565  struct UserOverridableBuffer
566  {
567  UserOverridableBuffer()
568  {
569  data = NULL;
570  userSuppliedCapacity = 0;
571  }
572  T* data;
573  int32 userSuppliedCapacity;
574  };
575 
577  struct Proxy
578  {
579  int32 index;
580  uint32 tag;
581  friend inline bool operator<(const Proxy &a, const Proxy &b)
582  {
583  return a.tag < b.tag;
584  }
585  friend inline bool operator<(uint32 a, const Proxy &b)
586  {
587  return a < b.tag;
588  }
589  friend inline bool operator<(const Proxy &a, uint32 b)
590  {
591  return a.tag < b;
592  }
593  };
594 
596  struct Pair
597  {
598  int32 indexA, indexB;
599  uint32 flags;
600  float32 strength;
601  float32 distance;
602  };
603 
605  struct Triad
606  {
607  int32 indexA, indexB, indexC;
608  uint32 flags;
609  float32 strength;
610  b2Vec2 pa, pb, pc;
611  float32 ka, kb, kc, s;
612  };
613 
615  class ConnectionFilter
616  {
617  public:
618  virtual ~ConnectionFilter() {}
621  virtual bool IsNecessary(int32 index) const
622  {
623  B2_NOT_USED(index);
624  return true;
625  }
627  virtual bool ShouldCreatePair(int32 a, int32 b) const
628  {
629  B2_NOT_USED(a);
630  B2_NOT_USED(b);
631  return true;
632  }
634  virtual bool ShouldCreateTriad(int32 a, int32 b, int32 c) const
635  {
636  B2_NOT_USED(a);
637  B2_NOT_USED(b);
638  B2_NOT_USED(c);
639  return true;
640  }
641  };
642 
644  static const int32 k_pairFlags =
648  static const int32 k_triadFlags =
651  static const int32 k_noPressureFlags =
655  static const int32 k_extraDampingFlags =
657 
658  b2ParticleSystem(const b2ParticleSystemDef* def, b2World* world);
659  ~b2ParticleSystem();
660 
661  template <typename T> void FreeBuffer(T** b, int capacity);
662  template <typename T> void FreeUserOverridableBuffer(
663  UserOverridableBuffer<T>* b);
664  template <typename T> T* ReallocateBuffer(T* buffer, int32 oldCapacity,
665  int32 newCapacity);
666  template <typename T> T* ReallocateBuffer(
667  T* buffer, int32 userSuppliedCapacity, int32 oldCapacity,
668  int32 newCapacity, bool deferred);
669  template <typename T> T* ReallocateBuffer(
670  UserOverridableBuffer<T>* buffer, int32 oldCapacity, int32 newCapacity,
671  bool deferred);
672  template <typename T> T* RequestBuffer(T* buffer);
673  template <typename T> T* RequestGrowableBuffer(T* buffer,
674  int32 count, int32 *capacity);
675 
678  void ReallocateHandleBuffers(int32 newCapacity);
679 
680  void ReallocateInternalAllocatedBuffers(int32 capacity);
681  int32 CreateParticleForGroup(
682  const b2ParticleGroupDef& groupDef,
683  const b2Transform& xf, const b2Vec2& position);
684  void CreateParticlesStrokeShapeForGroup(
685  const b2Shape* shape,
686  const b2ParticleGroupDef& groupDef, const b2Transform& xf);
687  void CreateParticlesFillShapeForGroup(
688  const b2Shape* shape,
689  const b2ParticleGroupDef& groupDef, const b2Transform& xf);
690  void CreateParticlesWithShapeForGroup(
691  const b2Shape* shape,
692  const b2ParticleGroupDef& groupDef, const b2Transform& xf);
693  void CreateParticlesWithShapesForGroup(
694  const b2Shape* const* shapes, int32 shapeCount,
695  const b2ParticleGroupDef& groupDef, const b2Transform& xf);
696  void DestroyParticleGroup(b2ParticleGroup* group);
697 
698  void UpdatePairsAndTriads(
699  int32 firstIndex, int32 lastIndex, const ConnectionFilter& filter);
700  void UpdatePairsAndTriadsWithReactiveParticles();
701  static bool ComparePairIndices(const Pair& a, const Pair& b);
702  static bool MatchPairIndices(const Pair& a, const Pair& b);
703  static bool CompareTriadIndices(const Triad& a, const Triad& b);
704  static bool MatchTriadIndices(const Triad& a, const Triad& b);
705  void ComputeDepth();
706 
707  void UpdateAllParticleFlags();
708  void UpdateAllGroupFlags();
709  void AddContact(int32 a, int32 b, b2ContactFilter* const contactFilter,
710  b2ContactListener* const contactListener,
711  b2ParticlePairSet* const particlePairSet);
712  void UpdateContacts(bool exceptZombie);
713  void UpdateBodyContacts();
714 
715  void Solve(const b2TimeStep& step);
716  void SolveCollision(const b2TimeStep& step);
717  void LimitVelocity(const b2TimeStep& step);
718  void SolveGravity(const b2TimeStep& step);
719  void SolveBarrier(const b2TimeStep& step);
720  void SolveStaticPressure(const b2TimeStep& step);
721  void ComputeWeight();
722  void SolvePressure(const b2TimeStep& step);
723  void SolveDamping(const b2TimeStep& step);
724  void SolveExtraDamping();
725  void SolveWall();
726  void SolveRigid(const b2TimeStep& step);
727  void SolveElastic(const b2TimeStep& step);
728  void SolveSpring(const b2TimeStep& step);
729  void SolveTensile(const b2TimeStep& step);
730  void SolveViscous();
731  void SolveRepulsive(const b2TimeStep& step);
732  void SolvePowder(const b2TimeStep& step);
733  void SolveSolid(const b2TimeStep& step);
734  void SolveForce(const b2TimeStep& step);
735  void SolveColorMixing();
736  void SolveZombie();
739  void SolveLifetimes(const b2TimeStep& step);
740  void RotateBuffer(int32 start, int32 mid, int32 end);
741 
742  float32 GetCriticalVelocity(const b2TimeStep& step) const;
743  float32 GetCriticalVelocitySquared(const b2TimeStep& step) const;
744  float32 GetCriticalPressure(const b2TimeStep& step) const;
745  float32 GetParticleStride() const;
746  float32 GetParticleMass() const;
747  float32 GetParticleInvMass() const;
748 
749  // Get the world's contact filter if any particles with the
750  // b2_contactFilterParticle flag are present in the system.
751  b2ContactFilter* GetFixtureContactFilter() const;
752 
753  // Get the world's contact filter if any particles with the
754  // b2_particleContactFilterParticle flag are present in the system.
755  b2ContactFilter* GetParticleContactFilter() const;
756 
757  // Get the world's contact listener if any particles with the
758  // b2_fixtureContactListenerParticle flag are present in the system.
759  b2ContactListener* GetFixtureContactListener() const;
760 
761  // Get the world's contact listener if any particles with the
762  // b2_particleContactListenerParticle flag are present in the system.
763  b2ContactListener* GetParticleContactListener() const;
764 
765  template <typename T> void SetUserOverridableBuffer(
766  UserOverridableBuffer<T>* buffer, T* newBufferData, int32 newCapacity);
767 
768  void SetGroupFlags(b2ParticleGroup* group, uint32 flags);
769 
770  void RemoveSpuriousBodyContacts();
771  static bool BodyContactCompare(const b2ParticleBodyContact& lhs,
772  const b2ParticleBodyContact& rhs);
773 
774  void DetectStuckParticle(int32 particle);
775 
777  bool ValidateParticleIndex(const int32 index) const;
778 
780  int32 GetQuantizedTimeElapsed() const;
782  int64 LifetimeToExpirationTime(const float32 lifetime) const;
783 
784  bool ForceCanBeApplied(uint32 flags) const;
785  void PrepareForceBuffer();
786 
787  bool m_paused;
788  int32 m_timestamp;
789  int32 m_allParticleFlags;
790  bool m_needsUpdateAllParticleFlags;
791  int32 m_allGroupFlags;
792  bool m_needsUpdateAllGroupFlags;
793  bool m_hasForce;
794  int32 m_iterationIndex;
795  float32 m_density;
796  float32 m_inverseDensity;
797  float32 m_gravityScale;
798  float32 m_particleDiameter;
799  float32 m_inverseDiameter;
800  float32 m_squaredDiameter;
801  bool m_strictContactCheck;
802 
803  int32 m_count;
804  int32 m_internalAllocatedCapacity;
805  int32 m_maxCount;
807  b2SlabAllocator<b2ParticleHandle> m_handleAllocator;
809  UserOverridableBuffer<b2ParticleHandle*> m_handleIndexBuffer;
810  UserOverridableBuffer<uint32> m_flagsBuffer;
811  UserOverridableBuffer<b2Vec2> m_positionBuffer;
812  UserOverridableBuffer<b2Vec2> m_velocityBuffer;
813  b2Vec2* m_forceBuffer;
816  float32* m_weightBuffer;
821  float32* m_staticPressureBuffer;
824  float32* m_accumulationBuffer;
829  b2Vec2* m_accumulation2Buffer;
834  float32* m_depthBuffer;
835  UserOverridableBuffer<b2ParticleColor> m_colorBuffer;
836  b2ParticleGroup** m_groupBuffer;
837  UserOverridableBuffer<void*> m_userDataBuffer;
838 
840  int32 m_stuckThreshold;
841  UserOverridableBuffer<int32> m_lastBodyContactStepBuffer;
842  UserOverridableBuffer<int32> m_bodyContactCountBuffer;
843  UserOverridableBuffer<int32> m_consecutiveContactStepsBuffer;
844  int32 m_stuckParticleCount;
845  int32 m_stuckParticleCapacity;
846  int32 *m_stuckParticleBuffer;
847 
848  int32 m_proxyCount;
849  int32 m_proxyCapacity;
850  Proxy* m_proxyBuffer;
851 
852  int32 m_contactCount;
853  int32 m_contactCapacity;
854  b2ParticleContact* m_contactBuffer;
855 
856  int32 m_bodyContactCount;
857  int32 m_bodyContactCapacity;
858  b2ParticleBodyContact* m_bodyContactBuffer;
859 
860  int32 m_pairCount;
861  int32 m_pairCapacity;
862  Pair* m_pairBuffer;
863 
864  int32 m_triadCount;
865  int32 m_triadCapacity;
866  Triad* m_triadBuffer;
867 
871  UserOverridableBuffer<int32> m_expirationTimeBuffer;
873  UserOverridableBuffer<int32> m_indexByExpirationTimeBuffer;
876  int64 m_timeElapsed;
879  bool m_expirationTimeBufferRequiresSorting;
880 
881  int32 m_groupCount;
882  b2ParticleGroup* m_groupList;
883 
884  b2ParticleSystemDef m_def;
885 
886  b2World* m_world;
887  b2ParticleSystem* m_prev;
888  b2ParticleSystem* m_next;
889 };
890 
892 {
893  return m_groupList;
894 }
895 
897 {
898  return m_groupList;
899 }
900 
902 {
903  return m_groupCount;
904 }
905 
907 {
908  return m_count;
909 }
910 
911 inline void b2ParticleSystem::SetPaused(bool paused)
912 {
913  m_paused = paused;
914 }
915 
916 inline bool b2ParticleSystem::GetPaused() const
917 {
918  return m_paused;
919 }
920 
922 {
923  return m_contactBuffer;
924 }
925 
926 inline int32 b2ParticleSystem::GetContactCount()
927 {
928  return m_contactCount;
929 }
930 
932 {
933  return m_bodyContactBuffer;
934 }
935 
936 inline int32 b2ParticleSystem::GetBodyContactCount()
937 {
938  return m_bodyContactCount;
939 }
940 
942 {
943  return m_next;
944 }
945 
946 inline const b2ParticleSystem* b2ParticleSystem::GetNext() const
947 {
948  return m_next;
949 }
950 
951 inline const int32* b2ParticleSystem::GetStuckCandidates() const
952 {
953  return m_stuckParticleBuffer;
954 }
955 
957 {
958  return m_stuckParticleCount;
959 }
960 
962 {
963  m_strictContactCheck = enabled;
964 }
965 
967 {
968  return m_strictContactCheck;
969 }
970 
971 inline void b2ParticleSystem::SetRadius(float32 radius)
972 {
973  m_particleDiameter = 2 * radius;
974  m_squaredDiameter = m_particleDiameter * m_particleDiameter;
975  m_inverseDiameter = 1 / m_particleDiameter;
976 }
977 
978 inline void b2ParticleSystem::SetDensity(float32 density)
979 {
980  m_density = density;
981  m_inverseDensity = 1 / m_density;
982 }
983 
984 inline float32 b2ParticleSystem::GetDensity() const
985 {
986  return m_density;
987 }
988 
989 inline void b2ParticleSystem::SetGravityScale(float32 gravityScale)
990 {
991  m_gravityScale = gravityScale;
992 }
993 
994 inline float32 b2ParticleSystem::GetGravityScale() const
995 {
996  return m_gravityScale;
997 }
998 
999 inline void b2ParticleSystem::SetDamping(float32 damping)
1000 {
1001  m_def.dampingStrength = damping;
1002 }
1003 
1004 inline float32 b2ParticleSystem::GetDamping() const
1005 {
1006  return m_def.dampingStrength;
1007 }
1008 
1010 {
1011  m_def.staticPressureIterations = iterations;
1012 }
1013 
1015 {
1016  return m_def.staticPressureIterations;
1017 }
1018 
1019 inline float32 b2ParticleSystem::GetRadius() const
1020 {
1021  return m_particleDiameter / 2;
1022 }
1023 
1024 inline float32 b2ParticleSystem::GetCriticalVelocity(const b2TimeStep& step) const
1025 {
1026  return m_particleDiameter * step.inv_dt;
1027 }
1028 
1029 inline float32 b2ParticleSystem::GetCriticalVelocitySquared(
1030  const b2TimeStep& step) const
1031 {
1032  float32 velocity = GetCriticalVelocity(step);
1033  return velocity * velocity;
1034 }
1035 
1036 inline float32 b2ParticleSystem::GetCriticalPressure(const b2TimeStep& step) const
1037 {
1038  return m_density * GetCriticalVelocitySquared(step);
1039 }
1040 
1041 inline float32 b2ParticleSystem::GetParticleStride() const
1042 {
1043  return b2_particleStride * m_particleDiameter;
1044 }
1045 
1046 inline float32 b2ParticleSystem::GetParticleMass() const
1047 {
1048  float32 stride = GetParticleStride();
1049  return m_density * stride * stride;
1050 }
1051 
1052 inline float32 b2ParticleSystem::GetParticleInvMass() const
1053 {
1054  // mass = density * stride^2, so we take the inverse of this.
1055  float32 inverseStride = m_inverseDiameter * (1.0f / b2_particleStride);
1056  return m_inverseDensity * inverseStride * inverseStride;
1057 }
1058 
1060 {
1061  return m_positionBuffer.data;
1062 }
1063 
1065 {
1066  return m_velocityBuffer.data;
1067 }
1068 
1070 {
1071  return m_maxCount;
1072 }
1073 
1075 {
1076  b2Assert(m_count <= count);
1077  m_maxCount = count;
1078 }
1079 
1080 inline const uint32* b2ParticleSystem::GetFlagsBuffer() const
1081 {
1082  return m_flagsBuffer.data;
1083 }
1084 
1085 inline const b2Vec2* b2ParticleSystem::GetPositionBuffer() const
1086 {
1087  return m_positionBuffer.data;
1088 }
1089 
1090 inline const b2Vec2* b2ParticleSystem::GetVelocityBuffer() const
1091 {
1092  return m_velocityBuffer.data;
1093 }
1094 
1096 {
1097  return ((b2ParticleSystem*) this)->GetColorBuffer();
1098 }
1099 
1100 inline const b2ParticleGroup* const* b2ParticleSystem::GetGroupBuffer() const
1101 {
1102  return m_groupBuffer;
1103 }
1104 
1105 inline void* const* b2ParticleSystem::GetUserDataBuffer() const
1106 {
1107  return ((b2ParticleSystem*) this)->GetUserDataBuffer();
1108 }
1109 
1111 {
1112  return m_groupBuffer;
1113 }
1114 
1115 inline uint32 b2ParticleSystem::GetParticleFlags(int32 index)
1116 {
1117  return GetFlagsBuffer()[index];
1118 }
1119 
1120 inline bool b2ParticleSystem::ValidateParticleIndex(const int32 index) const
1121 {
1122  return index >= 0 && index < GetParticleCount() &&
1123  index != b2_invalidParticleIndex;
1124 }
1125 
1127 {
1128  return m_def.destroyByAge;
1129 }
1130 
1132  const b2Vec2& impulse)
1133 {
1134  ApplyLinearImpulse(index, index + 1, impulse);
1135 }
1136 
1137 #endif
Definition: b2Math.h:411
const int32 * GetExpirationTimeBuffer()
Definition: b2ParticleSystem.cpp:3527
float32 ExpirationTimeToLifetime(const int32 expirationTime) const
Definition: b2ParticleSystem.cpp:3509
Prevents other particles from leaking.
Definition: b2Particle.h:54
void SetPaused(bool paused)
Definition: b2ParticleSystem.h:911
float32 radius
Particles behave as circles with this radius. In Box2D units.
Definition: b2ParticleSystem.h:111
void ApplyForce(int32 firstIndex, int32 lastIndex, const b2Vec2 &force)
Definition: b2ParticleSystem.cpp:3687
const uint32 * GetFlagsBuffer() const
Definition: b2ParticleSystem.h:1080
b2Vec2 * GetVelocityBuffer()
Definition: b2ParticleSystem.h:1064
Definition: b2ParticleSystem.h:84
const b2ParticleBodyContact * GetBodyContacts()
Definition: b2ParticleSystem.h:931
void ParticleApplyLinearImpulse(int32 index, const b2Vec2 &impulse)
Definition: b2ParticleSystem.h:1131
float32 repulsiveStrength
Definition: b2ParticleSystem.h:146
float32 GetRadius() const
Get the particle radius.
Definition: b2ParticleSystem.h:1019
float32 lifetimeGranularity
Definition: b2ParticleSystem.h:186
void SetDensity(float32 density)
Definition: b2ParticleSystem.h:978
const b2ParticleHandle * GetParticleHandleFromIndex(const int32 index)
Retrieve a handle to the particle at the specified index.
Definition: b2ParticleSystem.cpp:739
Definition: b2ParticleGroup.h:51
uint32 flags
Definition: b2ParticleSystem.h:52
float32 ComputeCollisionEnergy() const
Compute the kinetic energy that can be lost by damping force.
Definition: b2ParticleSystem.cpp:3842
float32 weight
Definition: b2ParticleSystem.h:57
Definition: b2WorldCallbacks.h:241
b2ParticleColor * GetColorBuffer()
Definition: b2ParticleSystem.cpp:548
void RayCast(b2RayCastCallback *callback, const b2Vec2 &point1, const b2Vec2 &point2) const
Definition: b2ParticleSystem.cpp:3780
void SetParticleLifetime(const int32 index, const float32 lifetime)
Definition: b2ParticleSystem.cpp:3473
b2ParticleGroup * GetParticleGroupList()
Definition: b2ParticleSystem.h:891
float32 weight
Weight of the contact. A value between 0.0f and 1.0f.
Definition: b2ParticleSystem.h:75
Definition: b2StackAllocator.h:37
b2Vec2 normal
The normalized direction from A to B.
Definition: b2ParticleSystem.h:60
Definition: b2World.h:44
Definition: b2ParticleSystem.h:189
Definition: b2WorldCallbacks.h:74
int32 staticPressureIterations
Definition: b2ParticleSystem.h:168
const b2ParticleContact * GetContacts()
Definition: b2ParticleSystem.h:921
b2ParticleGroup * CreateParticleGroup(const b2ParticleGroupDef &def)
Definition: b2ParticleSystem.cpp:1034
int32 GetStuckCandidateCount() const
Get the number of stuck particle candidates from the last step.
Definition: b2ParticleSystem.h:956
void ComputeAABB(b2AABB *const aabb) const
Definition: b2ParticleSystem.cpp:1719
Definition: b2WorldCallbacks.h:128
uint32 GetParticleFlags(const int32 index)
Get flags for a particle. See the b2ParticleFlag enum.
Definition: b2ParticleSystem.h:1115
Definition: b2BlockAllocator.h:36
float32 GetParticleLifetime(const int32 index)
Definition: b2ParticleSystem.cpp:3519
Definition: b2Shape.h:43
void QueryShapeAABB(b2QueryCallback *callback, const b2Shape &shape, const b2Transform &xf) const
Definition: b2ParticleSystem.cpp:3771
With restitution from deformation.
Definition: b2Particle.h:42
bool GetStrictContactCheck() const
Get the status of the strict contact check.
Definition: b2ParticleSystem.h:966
float32 colorMixingStrength
Definition: b2ParticleSystem.h:173
float32 powderStrength
Definition: b2ParticleSystem.h:150
bool GetDestructionByAge() const
Definition: b2ParticleSystem.h:1126
int32 index
Index of the particle making contact.
Definition: b2ParticleSystem.h:66
void SetMaxParticleCount(int32 count)
Definition: b2ParticleSystem.h:1074
void ParticleApplyForce(int32 index, const b2Vec2 &force)
Definition: b2ParticleSystem.cpp:3715
float32 staticPressureRelaxation
Definition: b2ParticleSystem.h:164
Definition: b2Particle.h:272
b2Vec2 normal
The normalized direction from the particle to the body.
Definition: b2ParticleSystem.h:78
Small color object for each particle.
Definition: b2Particle.h:81
Without isotropic pressure.
Definition: b2Particle.h:46
void SetParticleFlags(int32 index, uint32 flags)
Set flags for a particle. See the b2ParticleFlag enum.
Definition: b2ParticleSystem.cpp:3617
float32 pressureStrength
Definition: b2ParticleSystem.h:115
float32 ejectionStrength
Definition: b2ParticleSystem.h:154
b2Fixture * fixture
The specific fixture making contact.
Definition: b2ParticleSystem.h:72
float32 mass
The effective mass used in calculating force.
Definition: b2ParticleSystem.h:81
const int32 * GetStuckCandidates() const
Definition: b2ParticleSystem.h:951
void SetDamping(float32 damping)
Definition: b2ParticleSystem.h:999
int32 GetParticleCount() const
Get the number of particles.
Definition: b2ParticleSystem.h:906
void ** GetUserDataBuffer()
Definition: b2ParticleSystem.cpp:554
With surface tension.
Definition: b2Particle.h:48
A group of particles. b2ParticleGroup::CreateParticleGroup creates these.
Definition: b2ParticleGroup.h:134
float32 dampingStrength
Definition: b2ParticleSystem.h:119
An axis aligned bounding box.
Definition: b2Collision.h:162
int32 indexA
Indices of the respective particles making contact.
Definition: b2ParticleSystem.h:48
int32 DestroyParticlesInShape(const b2Shape &shape, const b2Transform &xf)
Definition: b2ParticleSystem.h:238
void SetFlagsBuffer(uint32 *buffer, int32 capacity)
Definition: b2ParticleSystem.cpp:3589
float32 GetGravityScale() const
Get the particle gravity scale.
Definition: b2ParticleSystem.h:994
This is an internal structure.
Definition: b2TimeStep.h:39
b2Vec2 * GetPositionBuffer()
Definition: b2ParticleSystem.h:1059
Less compressibility.
Definition: b2Particle.h:56
int32 GetParticleGroupCount() const
Get the number of particle groups.
Definition: b2ParticleSystem.h:901
float32 viscousStrength
Definition: b2ParticleSystem.h:131
int32 GetMaxParticleCount() const
Get the maximum number of particles.
Definition: b2ParticleSystem.h:1069
bool destroyByAge
Definition: b2ParticleSystem.h:178
void DestroyOldestParticle(const int32 index, const bool callDestructionListener)
Definition: b2ParticleSystem.cpp:770
Definition: b2ParticleSystem.h:63
void SetRadius(float32 radius)
Definition: b2ParticleSystem.h:971
int32 GetStaticPressureIterations() const
Get the number of iterations for static pressure of particles.
Definition: b2ParticleSystem.h:1014
#define b2_particleStride
The default distance between particles, multiplied by the particle diameter.
Definition: b2Settings.h:156
A rigid body. These are created via b2World::CreateBody.
Definition: b2Body.h:127
bool GetPaused() const
Definition: b2ParticleSystem.h:916
void SetStaticPressureIterations(int32 iterations)
Definition: b2ParticleSystem.h:1009
float32 surfaceTensionNormalStrength
Definition: b2ParticleSystem.h:140
void SetDestructionByAge(const bool enable)
Definition: b2ParticleSystem.cpp:3554
With restitution from stretching.
Definition: b2Particle.h:40
void SetStuckThreshold(int32 iterations)
Definition: b2ParticleSystem.cpp:3861
float32 staticPressureStrength
Definition: b2ParticleSystem.h:160
b2ParticleGroup *const * GetGroupBuffer()
Definition: b2ParticleSystem.h:1110
b2Body * body
The body making contact.
Definition: b2ParticleSystem.h:69
int32 CreateParticle(const b2ParticleDef &def)
Definition: b2ParticleSystem.cpp:627
float32 springStrength
Definition: b2ParticleSystem.h:127
Definition: b2ParticleSystem.h:45
A 2D column vector.
Definition: b2Math.h:56
void JoinParticleGroups(b2ParticleGroup *groupA, b2ParticleGroup *groupB)
Definition: b2ParticleSystem.cpp:1102
#define b2_invalidParticleIndex
A symbolic constant that stands for particle allocation error.
Definition: b2Settings.h:153
void ApplyLinearImpulse(int32 firstIndex, int32 lastIndex, const b2Vec2 &impulse)
Definition: b2ParticleSystem.cpp:3725
float32 surfaceTensionPressureStrength
Definition: b2ParticleSystem.h:135
float32 GetDamping() const
Get damping for particles.
Definition: b2ParticleSystem.h:1004
float32 elasticStrength
Definition: b2ParticleSystem.h:123
float32 GetDensity() const
Get the particle density.
Definition: b2ParticleSystem.h:984
Definition: b2WorldCallbacks.h:208
void SetStrictContactCheck(bool enabled)
Definition: b2ParticleSystem.h:961
b2ParticleSystem * GetNext()
Get the next particle-system in the world&#39;s particle-system list.
Definition: b2ParticleSystem.h:941
void DestroyParticle(int32 index)
Definition: b2ParticleSystem.h:207
void QueryAABB(b2QueryCallback *callback, const b2AABB &aabb) const
Definition: b2ParticleSystem.cpp:3737
const int32 * GetIndexByExpirationTimeBuffer()
Definition: b2ParticleSystem.cpp:3539
Definition: b2Particle.h:320
void SetGravityScale(float32 gravityScale)
Definition: b2ParticleSystem.h:989
Definition: b2Fixture.h:108