physics_engine.h
Go to the documentation of this file.
1 
7 #ifndef PHYSICS_ENGINE_H
8 #define PHYSICS_ENGINE_H
9 
10 namespace argos {
11  class CPhysicsEngine;
12  class CPhysicsModel;
13  class CEntity;
14  class CEmbodiedEntity;
15  class CVector3;
16  class CRay3;
17 }
18 
19 #include <map>
20 #include <argos3/core/utility/logging/argos_log.h>
21 #include <argos3/core/utility/math/ray2.h>
22 #include <argos3/core/utility/configuration/base_configurable_resource.h>
23 #include <argos3/core/utility/configuration/argos_configuration.h>
24 #include <argos3/core/utility/datatypes/datatypes.h>
25 #include <argos3/core/utility/plugins/factory.h>
26 
27 namespace argos {
28 
29  /****************************************/
30  /****************************************/
31 
35 
37  IntersectedEntity(NULL),
38  TOnRay(1.0f) {}
39 
41  Real f_t_on_ray) :
42  IntersectedEntity(pc_entity),
43  TOnRay(f_t_on_ray) {}
44 
47  TOnRay(s_item.TOnRay) {}
50  TOnRay = s_item.TOnRay;
51  return *this;
52  }
53  inline bool operator<(const SEmbodiedEntityIntersectionItem& s_item) {
54  return TOnRay < s_item.TOnRay;
55  }
56  };
57 
58  typedef std::vector<SEmbodiedEntityIntersectionItem> TEmbodiedEntityIntersectionData;
59 
68  const CRay3& c_ray);
69 
77  const CRay3& c_ray);
78 
88  const CRay3& c_ray,
89  CEmbodiedEntity& c_entity);
90 
91  /****************************************/
92  /****************************************/
93 
95 
96  public:
97 
101  struct SBoundaryFace {
102  std::string EngineId;
103  };
104 
108  struct SHorizontalFace : public SBoundaryFace {
110  };
111 
115  struct SVerticalFace : public SBoundaryFace {
117  };
118 
122  struct SVolume {
125  std::vector<SVerticalFace*> SideFaces;
126  SVolume();
127  ~SVolume();
128  void Init(TConfigurationNode& t_node);
129  bool IsActive() const;
130  };
131 
132  public:
133 
134  typedef std::vector<CPhysicsEngine*> TVector;
135  typedef std::map<std::string, CPhysicsEngine*, std::less<std::string> > TMap;
136 
137  public:
138 
139  CPhysicsEngine();
140  virtual ~CPhysicsEngine() {}
141 
142  virtual void Init(TConfigurationNode& t_tree);
143  virtual void Reset() {}
144  virtual void Destroy() {}
145 
146  virtual void Update() = 0;
147 
161  virtual void PostSpaceInit() {}
162 
166  virtual bool IsPointContained(const CVector3& c_point);
167 
168  virtual size_t GetNumPhysicsModels() = 0;
169 
176  virtual bool AddEntity(CEntity& c_entity) = 0;
177 
184  virtual bool RemoveEntity(CEntity& c_entity) = 0;
185 
189  inline bool IsEntityTransferNeeded() const {
190  return !m_vecTransferData.empty();
191  }
192 
196  inline bool IsEntityTransferActive() const {
197  return m_sVolume.IsActive();
198  }
199 
205  virtual void ScheduleEntityForTransfer(CEmbodiedEntity& c_entity);
206 
210  virtual void TransferEntities();
211 
215  inline SVolume& GetVolume() {
216  return m_sVolume;
217  }
218 
222  inline const SVolume& GetVolume() const {
223  return m_sVolume;
224  }
225 
232  const CRay3& c_ray) const = 0;
233 
242  static Real GetSimulationClockTick();
243 
249 
259  static void SetSimulationClockTick(Real f_simulation_clock_tick);
260 
270  inline UInt32 GetIterations() const {
271  return m_unIterations;
272  }
273 
280  inline Real GetPhysicsClockTick() const {
281  return m_fPhysicsClockTick;
282  }
283 
288  inline const std::string& GetId() const {
289  return m_strId;
290  }
291 
296  void SetId(const std::string& str_id) {
297  m_strId = str_id;
298  }
299 
300  private:
301 
303  UInt32 m_unIterations;
304 
306  Real m_fPhysicsClockTick;
307 
309  std::string m_strId;
310 
312  static Real m_fSimulationClockTick;
313 
315  static Real m_fInverseSimulationClockTick;
316 
318  SVolume m_sVolume;
319 
321  std::vector<CEmbodiedEntity*> m_vecTransferData;
322  };
323 
324 }
325 
326 #define REGISTER_PHYSICS_ENGINE(CLASSNAME, \
327  LABEL, \
328  AUTHOR, \
329  VERSION, \
330  BRIEF_DESCRIPTION, \
331  LONG_DESCRIPTION, \
332  STATUS) \
333  REGISTER_SYMBOL(CPhysicsEngine, \
334  CLASSNAME, \
335  LABEL, \
336  AUTHOR, \
337  VERSION, \
338  BRIEF_DESCRIPTION, \
339  LONG_DESCRIPTION, \
340  STATUS)
341 
342 #endif
unsigned int UInt32
32-bit unsigned integer.
Definition: datatypes.h:97
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
bool GetClosestEmbodiedEntityIntersectedByRay(SEmbodiedEntityIntersectionItem &s_item, const CRay3 &c_ray)
Returns the closest intersection with an embodied entity to the ray start.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
bool GetEmbodiedEntitiesIntersectedByRay(TEmbodiedEntityIntersectionData &t_data, const CRay3 &c_ray)
Checks whether the given ray intersects any entity.
std::vector< SEmbodiedEntityIntersectionItem > TEmbodiedEntityIntersectionData
This entity is a link to a body in the physics engine.
The basic entity type.
Definition: entity.h:90
SEmbodiedEntityIntersectionItem(CEmbodiedEntity *pc_entity, Real f_t_on_ray)
bool operator<(const SEmbodiedEntityIntersectionItem &s_item)
SEmbodiedEntityIntersectionItem(const SEmbodiedEntityIntersectionItem &s_item)
SEmbodiedEntityIntersectionItem & operator=(const SEmbodiedEntityIntersectionItem &s_item)
std::map< std::string, CPhysicsEngine *, std::less< std::string > > TMap
virtual void CheckIntersectionWithRay(TEmbodiedEntityIntersectionData &t_data, const CRay3 &c_ray) const =0
Check which objects in this engine intersect the given ray.
static Real GetSimulationClockTick()
Returns the simulation clock tick.
virtual bool IsPointContained(const CVector3 &c_point)
Returns true if the given point is contained in this physics engine.
void SetId(const std::string &str_id)
Sets the id of this physics engine.
SVolume & GetVolume()
Returns the boundary faces for the volume associated to this engine.
virtual void ScheduleEntityForTransfer(CEmbodiedEntity &c_entity)
Schedules an entity of transfer.
std::vector< CPhysicsEngine * > TVector
static Real GetInverseSimulationClockTick()
Returns the inverse of GetSimulationClockTick().
virtual void Update()=0
const SVolume & GetVolume() const
Returns the boundary faces for the volume associated to this engine.
const std::string & GetId() const
Returns the id of this physics engine.
virtual void Init(TConfigurationNode &t_tree)
Initializes the resource.
Real GetPhysicsClockTick() const
Returns the length of the physics engine tick.
virtual void PostSpaceInit()
Executes extra initialization activities after the space has been initialized.
static void SetSimulationClockTick(Real f_simulation_clock_tick)
Sets the simulation clock tick.
virtual size_t GetNumPhysicsModels()=0
bool IsEntityTransferNeeded() const
Returns true if this engine has entities that must be transferred to another engine.
virtual void TransferEntities()
Executes the transfer of entities to other engines.
UInt32 GetIterations() const
Returns the number of iterations per simulation clock tick.
bool IsEntityTransferActive() const
Returns true if entity transfer is active for this engine.
virtual void Destroy()
Undoes whatever was done by Init().
virtual bool RemoveEntity(CEntity &c_entity)=0
Removes an entity from the physics engine.
virtual void Reset()
Resets the resource.
virtual bool AddEntity(CEntity &c_entity)=0
Adds an entity to the physics engine.
A boundary face for entity transfer among physics engines.
A boundary face for top/bottom parts of the volume.
A boundary face for side parts of the volume.
The volume boundaries.
std::vector< SVerticalFace * > SideFaces
void Init(TConfigurationNode &t_node)
This class is the base of all XML-configurable ARGoS interface.
A 3D vector class.
Definition: vector3.h:31