Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00438_source.php on line 2

Warning: include(): Failed opening 'php/utility.php' for inclusion (include_path='.:/usr/lib64/php') in /home/argos/argos3/doc/api/embedded/a00438_source.php on line 2
The ARGoS Website

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 
46  IntersectedEntity(s_item.IntersectedEntity),
47  TOnRay(s_item.TOnRay) {}
48 
49  inline bool operator<(const SEmbodiedEntityIntersectionItem& s_item) {
50  return TOnRay < s_item.TOnRay;
51  }
52  };
53 
54  typedef std::vector<SEmbodiedEntityIntersectionItem> TEmbodiedEntityIntersectionData;
55 
63  extern bool GetEmbodiedEntitiesIntersectedByRay(TEmbodiedEntityIntersectionData& t_data,
64  const CRay3& c_ray);
65 
73  const CRay3& c_ray);
74 
84  const CRay3& c_ray,
85  CEmbodiedEntity& c_entity);
86 
87  /****************************************/
88  /****************************************/
89 
91 
92  public:
93 
97  struct SBoundaryFace {
98  std::string EngineId;
99  };
100 
104  struct SHorizontalFace : public SBoundaryFace {
106  };
107 
111  struct SVerticalFace : public SBoundaryFace {
113  };
114 
118  struct SVolume {
121  std::vector<SVerticalFace*> SideFaces;
122  SVolume();
123  ~SVolume();
124  void Init(TConfigurationNode& t_node);
125  bool IsActive() const;
126  };
127 
128  public:
129 
130  typedef std::vector<CPhysicsEngine*> TVector;
131  typedef std::map<std::string, CPhysicsEngine*, std::less<std::string> > TMap;
132 
133  public:
134 
135  CPhysicsEngine();
136  virtual ~CPhysicsEngine() {}
137 
138  virtual void Init(TConfigurationNode& t_tree);
139  virtual void Reset() {}
140  virtual void Destroy() {}
141 
142  virtual void Update() = 0;
143 
157  virtual void PostSpaceInit() {}
158 
162  virtual bool IsPointContained(const CVector3& c_point);
163 
164  virtual size_t GetNumPhysicsModels() = 0;
165 
172  virtual bool AddEntity(CEntity& c_entity) = 0;
173 
180  virtual bool RemoveEntity(CEntity& c_entity) = 0;
181 
185  inline bool IsEntityTransferNeeded() const {
186  return !m_vecTransferData.empty();
187  }
188 
192  inline bool IsEntityTransferActive() const {
193  return m_sVolume.IsActive();
194  }
195 
201  virtual void ScheduleEntityForTransfer(CEmbodiedEntity& c_entity);
202 
206  virtual void TransferEntities();
207 
211  inline SVolume& GetVolume() {
212  return m_sVolume;
213  }
214 
218  inline const SVolume& GetVolume() const {
219  return m_sVolume;
220  }
221 
227  virtual void CheckIntersectionWithRay(TEmbodiedEntityIntersectionData& t_data,
228  const CRay3& c_ray) const = 0;
229 
238  static Real GetSimulationClockTick();
239 
245 
255  static void SetSimulationClockTick(Real f_simulation_clock_tick);
256 
266  inline UInt32 GetIterations() const {
267  return m_unIterations;
268  }
269 
276  inline Real GetPhysicsClockTick() const {
277  return m_fPhysicsClockTick;
278  }
279 
284  inline const std::string& GetId() const {
285  return m_strId;
286  }
287 
292  void SetId(const std::string& str_id) {
293  m_strId = str_id;
294  }
295 
296  private:
297 
299  UInt32 m_unIterations;
300 
302  Real m_fPhysicsClockTick;
303 
305  std::string m_strId;
306 
308  static Real m_fSimulationClockTick;
309 
311  static Real m_fInverseSimulationClockTick;
312 
314  SVolume m_sVolume;
315 
317  std::vector<CEmbodiedEntity*> m_vecTransferData;
318  };
319 
320 }
321 
322 #define REGISTER_PHYSICS_ENGINE(CLASSNAME, \
323  LABEL, \
324  AUTHOR, \
325  VERSION, \
326  BRIEF_DESCRIPTION, \
327  LONG_DESCRIPTION, \
328  STATUS) \
329  REGISTER_SYMBOL(CPhysicsEngine, \
330  CLASSNAME, \
331  LABEL, \
332  AUTHOR, \
333  VERSION, \
334  BRIEF_DESCRIPTION, \
335  LONG_DESCRIPTION, \
336  STATUS)
337 
338 #endif
A 3D vector class.
Definition: vector3.h:29
SVolume & GetVolume()
Returns the boundary faces for the volume associated to this engine.
static Real GetInverseSimulationClockTick()
Returns the inverse of GetSimulationClockTick().
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
virtual void Destroy()
Undoes whatever was done by Init().
bool IsEntityTransferNeeded() const
Returns true if this engine has entities that must be transferred to another engine.
SEmbodiedEntityIntersectionItem(const SEmbodiedEntityIntersectionItem &s_item)
The volume boundaries.
virtual void Update()=0
std::map< std::string, CPhysicsEngine *, std::less< std::string > > TMap
virtual bool IsPointContained(const CVector3 &c_point)
Returns true if the given point is contained in this physics engine.
The basic entity type.
Definition: entity.h:89
Real GetPhysicsClockTick() const
Returns the length of the physics engine tick.
virtual void Init(TConfigurationNode &t_tree)
Initializes the resource.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
This entity is a link to a body in the physics engine.
A boundary face for entity transfer among physics engines.
void Init(TConfigurationNode &t_node)
virtual void PostSpaceInit()
Executes extra initialization activities after the space has been initialized.
SEmbodiedEntityIntersectionItem(CEmbodiedEntity *pc_entity, Real f_t_on_ray)
const std::string & GetId() const
Returns the id of this physics engine.
bool operator<(const SEmbodiedEntityIntersectionItem &s_item)
virtual bool RemoveEntity(CEntity &c_entity)=0
Removes an entity from the physics engine.
virtual void TransferEntities()
Executes the transfer of entities to other engines.
bool GetEmbodiedEntitiesIntersectedByRay(TEmbodiedEntityIntersectionData &t_data, const CRay3 &c_ray)
Checks whether the given ray intersects any entity.
std::vector< SVerticalFace * > SideFaces
std::vector< CPhysicsEngine * > TVector
unsigned int UInt32
32-bit unsigned integer.
Definition: datatypes.h:97
std::vector< SEmbodiedEntityIntersectionItem > TEmbodiedEntityIntersectionData
bool IsEntityTransferActive() const
Returns true if entity transfer is active for this engine.
A boundary face for top/bottom parts of the volume.
void SetId(const std::string &str_id)
Sets the id of this physics engine.
virtual size_t GetNumPhysicsModels()=0
virtual void CheckIntersectionWithRay(TEmbodiedEntityIntersectionData &t_data, const CRay3 &c_ray) const =0
Check which objects in this engine intersect the given ray.
bool GetClosestEmbodiedEntityIntersectedByRay(SEmbodiedEntityIntersectionItem &s_item, const CRay3 &c_ray)
Returns the closest intersection with an embodied entity to the ray start.
const SVolume & GetVolume() const
Returns the boundary faces for the volume associated to this engine.
static Real GetSimulationClockTick()
Returns the simulation clock tick.
UInt32 GetIterations() const
Returns the number of iterations per simulation clock tick.
virtual bool AddEntity(CEntity &c_entity)=0
Adds an entity to the physics engine.
A boundary face for side parts of the volume.
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
static void SetSimulationClockTick(Real f_simulation_clock_tick)
Sets the simulation clock tick.
virtual void ScheduleEntityForTransfer(CEmbodiedEntity &c_entity)
Schedules an entity of transfer.
virtual void Reset()
Resets the resource.
This class is the base of all XML-configurable ARGoS interface.