dynamics3d_model.h
Go to the documentation of this file.
1 
7 #ifndef DYNAMICS3D_MODEL_H
8 #define DYNAMICS3D_MODEL_H
9 
10 namespace argos {
11  class CDynamics3DEngine;
12 }
13 
14 #include <argos3/core/simulator/physics_engine/physics_model.h>
15 #include <argos3/core/simulator/entity/composable_entity.h>
16 #include <argos3/core/utility/math/vector3.h>
17 #include <argos3/core/utility/math/quaternion.h>
18 
19 #ifdef __APPLE__
20 #pragma clang diagnostic push
21 #pragma clang diagnostic ignored "-Wreorder"
22 #else
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wreorder"
25 #endif
26 
27 #include <argos3/plugins/simulator/physics_engines/dynamics3d/bullet/btBulletCollisionCommon.h>
28 #include <argos3/plugins/simulator/physics_engines/dynamics3d/bullet/BulletDynamics/Featherstone/btMultiBodyDynamicsWorld.h>
29 
30 #ifdef __APPLE__
31 #pragma clang diagnostic pop
32 #else
33 #pragma GCC diagnostic pop
34 #endif
35 
36 #include <functional>
37 
38 namespace argos {
39 
40  /****************************************/
41  /****************************************/
42 
44 
45  public:
46 
47  typedef std::map<std::string, CDynamics3DModel*> TMap;
48 
49  public:
50 
51  class CAbstractBody {
52 
53  public:
54 
55  using TVector = std::vector<std::shared_ptr<CAbstractBody> >;
56 
57  using TVectorIterator = std::vector<std::shared_ptr<CAbstractBody> >::iterator;
58 
59  struct SData {
60 
61  struct SDipole {
62  /* Constructor */
63  SDipole(const std::function<btVector3()>& fn_get_field,
64  const btTransform& c_offset) :
65  GetField(fn_get_field),
66  Offset(c_offset) {}
67  /* Data */
68  std::function<btVector3()> GetField;
69  btTransform Offset;
70  };
71 
72  /* Constructor */
73  SData(const btTransform& c_start_transform,
74  const btTransform& c_center_of_mass_offset,
75  const btVector3& c_inertia,
76  btScalar f_mass,
77  btScalar f_friction,
78  const std::vector<SDipole>& vec_dipoles = std::vector<SDipole>());
79  /* Data */
80  btTransform StartTransform;
81  btTransform InverseStartTransform;
82  btTransform CenterOfMassOffset;
84  btVector3 Inertia;
85  btScalar Mass;
86  btScalar Friction;
87  std::vector<SDipole> Dipoles;
88  };
89 
90  public:
91 
93  SAnchor* ps_anchor,
94  const std::shared_ptr<btCollisionShape>& ptr_shape,
95  const SData& s_data);
96 
97  virtual ~CAbstractBody() {}
98 
100 
101  SAnchor& GetAnchor();
102 
103  btCollisionShape& GetShape();
104 
105  const SData& GetData() const;
106 
107  virtual void Reset() = 0;
108 
109  virtual void AddToWorld(btMultiBodyDynamicsWorld& c_world) = 0;
110 
111  virtual void RemoveFromWorld(btMultiBodyDynamicsWorld& c_world) = 0;
112 
113  virtual void ApplyForce(const btVector3& c_force) = 0;
114 
115  virtual void ApplyForce(const btVector3& c_force, const btVector3& c_offset) = 0;
116 
117  virtual void ApplyTorque(const btVector3& c_torque) = 0;
118 
119  virtual btTransform& GetTransform() = 0;
120 
121  void UpdateAnchor();
122 
123  protected:
124  /* Link to the model */
126  /* Link to the anchor */
128  /* Link to the collision shape */
129  std::shared_ptr<btCollisionShape> m_ptrShape;
130  /* Data for setting up the body */
132  };
133 
134  public:
135 
137  CComposableEntity& c_entity);
138 
139  virtual ~CDynamics3DModel() {}
140 
141  virtual void Reset() = 0;
142 
144  return m_cEngine;
145  }
146 
147  inline const CDynamics3DEngine& GetEngine() const {
148  return m_cEngine;
149  }
150 
152  return m_cComposableEntity;
153  }
154 
155  inline const CComposableEntity& GetComposableEntity() const {
156  return m_cComposableEntity;
157  }
158 
159  virtual bool IsCollidingWithSomething() const;
160 
161  virtual void UpdateEntityStatus();
162 
163  virtual void UpdateFromEntityStatus() {}
164 
165  std::vector<std::shared_ptr<CAbstractBody> >& GetBodies() {
166  return m_vecBodies;
167  }
168 
169  virtual void AddToWorld(btMultiBodyDynamicsWorld& c_world) = 0;
170 
171  virtual void RemoveFromWorld(btMultiBodyDynamicsWorld& c_world) = 0;
172 
173  protected:
174 
175  std::vector<std::shared_ptr<CAbstractBody> > m_vecBodies;
176 
177  private:
178 
179  CDynamics3DEngine& m_cEngine;
180  CComposableEntity& m_cComposableEntity;
181 
182  };
183 
184  /****************************************/
185  /****************************************/
186 
187 }
188 
189 #endif
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
Basic class for an entity that contains other entities.
An anchor related to the body of an entity.
Definition: physics_model.h:38
const CDynamics3DEngine & GetEngine() const
virtual void AddToWorld(btMultiBodyDynamicsWorld &c_world)=0
virtual bool IsCollidingWithSomething() const
Returns true if this model is colliding with another model.
virtual void Reset()=0
std::vector< std::shared_ptr< CAbstractBody > > m_vecBodies
virtual void UpdateFromEntityStatus()
Updates the state of this model from the status of the associated entity.
std::vector< std::shared_ptr< CAbstractBody > > & GetBodies()
CComposableEntity & GetComposableEntity()
const CComposableEntity & GetComposableEntity() const
virtual void UpdateEntityStatus()
Updates the status of the associated entity.
std::map< std::string, CDynamics3DModel * > TMap
virtual void RemoveFromWorld(btMultiBodyDynamicsWorld &c_world)=0
CDynamics3DEngine & GetEngine()
CDynamics3DModel(CDynamics3DEngine &c_engine, CComposableEntity &c_entity)
virtual void ApplyTorque(const btVector3 &c_torque)=0
virtual void RemoveFromWorld(btMultiBodyDynamicsWorld &c_world)=0
virtual btTransform & GetTransform()=0
std::vector< std::shared_ptr< CAbstractBody > >::iterator TVectorIterator
std::shared_ptr< btCollisionShape > m_ptrShape
std::vector< std::shared_ptr< CAbstractBody > > TVector
virtual void ApplyForce(const btVector3 &c_force, const btVector3 &c_offset)=0
CAbstractBody(CDynamics3DModel &c_model, SAnchor *ps_anchor, const std::shared_ptr< btCollisionShape > &ptr_shape, const SData &s_data)
virtual void ApplyForce(const btVector3 &c_force)=0
virtual void AddToWorld(btMultiBodyDynamicsWorld &c_world)=0
SData(const btTransform &c_start_transform, const btTransform &c_center_of_mass_offset, const btVector3 &c_inertia, btScalar f_mass, btScalar f_friction, const std::vector< SDipole > &vec_dipoles=std::vector< SDipole >())
SDipole(const std::function< btVector3()> &fn_get_field, const btTransform &c_offset)