AGXDynamics  2.31.1.0
ParticleState.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGX_PARTICLESTATE_H
18 #define AGX_PARTICLESTATE_H
19 
20 #include <agx/Math.h>
21 #include <agx/BitSet_small.h>
22 #include <agxData/Type.h>
23 
25 
26 namespace agx
27 {
28  typedef agx::UInt32 ParticleStateDataType;
29 
30  class ParticleState : public BitSet_small<ParticleStateDataType>
31  {
32  public:
33  ParticleState();
34  agx::UInt32 motionControl() const;
35  bool enabled() const;
36  bool removed() const;
37  bool enableMerge() const;
38  bool enableRotation() const;
39  bool particleClipped() const;
40  bool particleFiltered() const;
41  bool isTerrainSoilParticle() const;
42 
43  void setMotionControl(agx::UInt32 motionControl);
44  void setEnabled(bool flag);
45  void setRemoved(bool flag);
46  void setEnableMerge(bool flag);
47  void setEnableRotation(bool flag);
48  void setParticleClipped(bool flag);
49  void setParticleFiltered(bool flag);
50  void setIsTerrainSoilParticle(bool flag);
51 
52  private:
53  friend class RigidBody;
54  friend class DynamicsSystem;
55  friend class MergedBody;
56  friend class MassPropertiesUpdate;
57 
58  static const UInt16 TERRAIN_SOIL_PARTICLE = 11;
59  static const UInt16 RENDERING_PARTICLE_FILTERED = 10;
60  static const UInt16 RENDERING_PARTICLE_CLIPPED = 9;
61  static const UInt16 ENABLE_NO_ROTATIONS = 8;
62  static const UInt16 ENABLE_MERGE_BIT = 7;
63  static const UInt16 REMOVED_BIT = 6;
64  static const UInt16 ENABLE_BIT = 5;
65  };
66 
67  /* Implementation */
68  AGX_FORCE_INLINE ParticleState::ParticleState() : BitSet_small<ParticleStateDataType>()
69  {
70  this->set(ENABLE_BIT, true);
71  this->set(REMOVED_BIT, false);
72  this->set(ENABLE_MERGE_BIT, true);
73  this->set(RENDERING_PARTICLE_CLIPPED, false);
74  this->set(RENDERING_PARTICLE_FILTERED, false );
75  this->set(TERRAIN_SOIL_PARTICLE, false);
76  this->setMotionControl(3); // This should be the DYNAMIC enum number in GranularBodySystem
77  }
78 
79  AGX_FORCE_INLINE agx::UInt32 ParticleState::motionControl() const
80  {
81  return (agx::UInt32)(m_state & 0x3);
82  }
83 
84  AGX_FORCE_INLINE bool ParticleState::enabled() const
85  {
86  return this->test(ENABLE_BIT);
87  }
88 
89  AGX_FORCE_INLINE bool ParticleState::particleClipped() const
90  {
91  return this->test(RENDERING_PARTICLE_CLIPPED);
92  }
93 
94  AGX_FORCE_INLINE bool ParticleState::removed() const
95  {
96  return this->test(REMOVED_BIT);
97  }
98 
99  AGX_FORCE_INLINE bool ParticleState::enableMerge() const
100  {
101  return this->test(ENABLE_MERGE_BIT);
102  }
103 
104  AGX_FORCE_INLINE bool ParticleState::enableRotation() const
105  {
106  return !this->test(ENABLE_NO_ROTATIONS);
107  }
108 
109  AGX_FORCE_INLINE bool agx::ParticleState::particleFiltered() const
110  {
111  return this->test(RENDERING_PARTICLE_FILTERED);
112  }
113 
114  AGX_FORCE_INLINE bool agx::ParticleState::isTerrainSoilParticle() const
115  {
116  return this->test( TERRAIN_SOIL_PARTICLE );
117  }
118 
120  {
121  const ParticleStateDataType mask = (ParticleStateDataType) 0x3;
122  m_state = (m_state & ~mask) | ((ParticleStateDataType)motionControl);
123  }
124 
125  AGX_FORCE_INLINE void ParticleState::setEnabled(bool flag)
126  {
127  this->set(ENABLE_BIT, flag);
128  }
129 
130  AGX_FORCE_INLINE void ParticleState::setParticleClipped(bool flag)
131  {
132  this->set(RENDERING_PARTICLE_CLIPPED, flag);
133  }
134 
135  AGX_FORCE_INLINE void agx::ParticleState::setParticleFiltered(bool flag)
136  {
137  this->set(RENDERING_PARTICLE_FILTERED, flag);
138  }
139 
140  AGX_FORCE_INLINE void ParticleState::setEnableRotation(bool flag)
141  {
142  this->set(ENABLE_NO_ROTATIONS, !flag);
143  }
144 
145  AGX_FORCE_INLINE void ParticleState::setRemoved(bool flag)
146  {
147  this->set(REMOVED_BIT, flag);
148  }
149 
150  AGX_FORCE_INLINE void ParticleState::setEnableMerge(bool flag)
151  {
152  this->set(ENABLE_MERGE_BIT, flag);
153  }
154 
155  AGX_FORCE_INLINE void agx::ParticleState::setIsTerrainSoilParticle( bool flag )
156  {
157  this->set( TERRAIN_SOIL_PARTICLE, flag );
158  }
159 
160 #ifndef SWIG
161  std::ostream& operator << (std::ostream& output, const ParticleState& state);
162 #endif // !SWIG
163 }
164 
165 AGX_TYPE_BINDING(agx::ParticleState, "ParticleState")
166 
168 
169 #endif /* AGX_RIGIDBODYSTATE_H */
std::ostream & operator<<(std::ostream &stream, const AtomicValueT< T > &value)
Definition: AtomicValue.h:109
#define AGX_TYPE_BINDING(_Type, _Name)
Definition: Type.h:179
#define AGX_FORCE_INLINE
Definition: Object.h:63
Namespace agx contains the dynamics/math part of the AGX Dynamics API.
AGXPHYSICS_EXPORT void setMotionControl(agx::RigidBodyPtrVector &bodies, agx::RigidBody::MotionControl motionControl)
Utility function to set motion control for a vector of rigid bodies.
uint16_t UInt16
Definition: Integer.h:39
uint32_t UInt32
Definition: Integer.h:40
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:102
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:101