AGX Dynamics  2.37.3.2
RigidBodyState.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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_RIGIDBODYSTATE_H
18 #define AGX_RIGIDBODYSTATE_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  class RigidBodyState : public BitSet_small<agx::UInt32>
29  {
30  public:
31  RigidBodyState();
32  agx::UInt32 motionControl() const;
33  bool handleAsParticle() const;
34  bool hasEffectiveMass() const;
35  bool hasEffectiveInertia() const;
36  bool enabled() const;
37  bool removed() const;
38  bool sleeping() const;
39  bool mergedRootBody() const;
40  bool powerline() const;
41  bool isKinematicForParticles() const;
42 
43  void setKinematicForParticles(bool flag);
44 
45  private:
46  friend class RigidBody;
47  friend class DynamicsSystem;
48  friend class MergedBody;
49  friend class MassPropertiesUpdate;
50 
51  void setMotionControl(agx::UInt32 motionControl);
52  void setHandleAsParticle(bool flag);
53  void setHasEffectiveMass(bool flag);
54  void setHasEffectiveInertia(bool flag);
55  void setEnabled(bool flag);
56  void setRemoved(bool flag);
57  void setSleeping(bool flag);
58  void setMergedRootBody(bool flag);
59  void setPowerline(bool flag);
60 
61  enum Bit : agx::UInt32
62  {
63  PARTICLE_KINEMATIC_BIT = 29,
64  HYDRAULICS_BIT = 28,
65  MERGED_ROOT_BODY_BIT = 25,
66  SLEEPING_BIT = 24,
67  REMOVED_BIT = 20,
68  HAS_EFFECTIVE_INERTIA_BIT = 18,
69  HAS_EFFECTIVE_MASS_BIT = 17,
70  HANDLE_AS_PARTICLE_BIT = 16,
71  ENABLE_BIT = 12
72  };
73  };
74 
75  /* Implementation */
76  AGX_FORCE_INLINE RigidBodyState::RigidBodyState() : BitSet_small<UInt32>()
77  {
78  this->set(ENABLE_BIT, true);
79  }
80 
81  AGX_FORCE_INLINE agx::UInt32 RigidBodyState::motionControl() const
82  {
83  return (agx::UInt32)(m_state & 0x3);
84  }
85 
86  AGX_FORCE_INLINE bool RigidBodyState::handleAsParticle() const
87  {
88  return this->test(HANDLE_AS_PARTICLE_BIT);
89  }
90 
91  AGX_FORCE_INLINE bool RigidBodyState::hasEffectiveMass() const
92  {
93  return this->test(HAS_EFFECTIVE_MASS_BIT);
94  }
95 
96  AGX_FORCE_INLINE bool RigidBodyState::hasEffectiveInertia() const
97  {
98  return this->test(HAS_EFFECTIVE_INERTIA_BIT);
99  }
100 
101  AGX_FORCE_INLINE bool RigidBodyState::enabled() const
102  {
103  return this->test(ENABLE_BIT);
104  }
105 
106  AGX_FORCE_INLINE bool RigidBodyState::removed() const
107  {
108  return this->test(REMOVED_BIT);
109  }
110 
111  AGX_FORCE_INLINE bool RigidBodyState::sleeping() const
112  {
113  return this->test(SLEEPING_BIT);
114  }
115 
116  AGX_FORCE_INLINE bool RigidBodyState::mergedRootBody() const
117  {
118  return this->test(MERGED_ROOT_BODY_BIT);
119  }
120 
121  AGX_FORCE_INLINE bool RigidBodyState::powerline() const
122  {
123  return this->test(HYDRAULICS_BIT);
124  }
125 
126  AGX_FORCE_INLINE bool RigidBodyState::isKinematicForParticles() const
127  {
128  return this->test(PARTICLE_KINEMATIC_BIT);
129  }
130 
132  {
133  m_state = ( m_state & ~0x3 ) | ((agx::UInt32)motionControl);
134  }
135 
136  AGX_FORCE_INLINE void RigidBodyState::setEnabled(bool flag)
137  {
138  this->set(ENABLE_BIT, flag);
139  }
140 
141  AGX_FORCE_INLINE void RigidBodyState::setHandleAsParticle(bool flag)
142  {
143  this->set(HANDLE_AS_PARTICLE_BIT, flag);
144  }
145 
146  AGX_FORCE_INLINE void RigidBodyState::setHasEffectiveMass(bool flag)
147  {
148  this->set(HAS_EFFECTIVE_MASS_BIT, flag);
149  }
150 
151  AGX_FORCE_INLINE void RigidBodyState::setHasEffectiveInertia(bool flag)
152  {
153  this->set(HAS_EFFECTIVE_INERTIA_BIT, flag);
154  }
155 
156  AGX_FORCE_INLINE void RigidBodyState::setRemoved(bool flag)
157  {
158  this->set(REMOVED_BIT, flag);
159  }
160 
161  AGX_FORCE_INLINE void RigidBodyState::setSleeping(bool flag)
162  {
163  this->set(SLEEPING_BIT, flag);
164  }
165 
166  AGX_FORCE_INLINE void RigidBodyState::setMergedRootBody(bool flag)
167  {
168  this->set(MERGED_ROOT_BODY_BIT, flag);
169  }
170 
171  AGX_FORCE_INLINE void RigidBodyState::setPowerline(bool flag)
172  {
173  this->set(HYDRAULICS_BIT, flag);
174  }
175 
176  inline void RigidBodyState::setKinematicForParticles(bool flag)
177  {
178  this->set(PARTICLE_KINEMATIC_BIT, flag);
179  }
180 
181  std::ostream& operator << ( std::ostream& output, const RigidBodyState& state );
182 }
183 
184 AGX_TYPE_BINDING(agx::RigidBodyState, "RigidBodyState")
185 
187 
188 #endif /* AGX_RIGIDBODYSTATE_H */
#define AGX_TYPE_BINDING(_Type, _Name)
Definition: Type.h:179
#define AGX_FORCE_INLINE
Definition: Object.h:59
std::ostream & operator<<(std::ostream &o, const agx::Vec6 &v)
Definition: Vec6.h:230
The agx namespace 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.
uint32_t UInt32
Definition: Integer.h:40
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97