pointmass3d_engine.h
Go to the documentation of this file.
1 
7 #ifndef POINTMASS3D_ENGINE_H
8 #define POINTMASS3D_ENGINE_H
9 
10 namespace argos {
11  class CPointMass3DEngine;
12  class CPointMass3DModel;
13  class CEmbodiedEntity;
14 }
15 
16 #include <argos3/core/utility/math/ray2.h>
17 #include <argos3/core/simulator/entity/controllable_entity.h>
18 #include <argos3/core/simulator/physics_engine/physics_engine.h>
19 
20 namespace argos {
21 
23 
24  public:
25 
27  virtual ~CPointMass3DEngine();
28 
29  virtual void Init(TConfigurationNode& t_tree);
30  virtual void Reset();
31  virtual void Destroy();
32 
33  virtual void Update();
34 
35  virtual size_t GetNumPhysicsModels();
36  virtual bool AddEntity(CEntity& c_entity);
37  virtual bool RemoveEntity(CEntity& c_entity);
38 
39  virtual bool IsPointContained(const CVector3& c_point);
40 
41  virtual bool IsEntityTransferNeeded() const;
42 
43  virtual void TransferEntities();
44 
46  const CRay3& c_ray) const;
47 
48  void AddPhysicsModel(const std::string& str_id,
49  CPointMass3DModel& c_model);
50  void RemovePhysicsModel(const std::string& str_id);
51 
52  std::map<std::string, CPointMass3DModel*>& GetPhysicsModels() {
53  return m_tPhysicsModels;
54  }
55 
56  const std::map<std::string, CPointMass3DModel*>& GetPhysicsModels() const {
57  return m_tPhysicsModels;
58  }
59 
60  inline Real GetGravity() const {
61  return m_fGravity;
62  }
63 
64  private:
65 
66  CControllableEntity::TMap m_tControllableEntities;
67  std::map<std::string, CPointMass3DModel*> m_tPhysicsModels;
68  Real m_fGravity;
69 
70  };
71 
72  /****************************************/
73  /****************************************/
74 
75  template <typename ACTION>
76  class CPointMass3DOperation : public CEntityOperation<ACTION, CPointMass3DEngine, SOperationOutcome> {
77  public:
79  };
80 
81  class CPointMass3DOperationAddEntity : public CPointMass3DOperation<CPointMass3DOperationAddEntity> {
82  public:
84  };
85 
86  class CPointMass3DOperationRemoveEntity : public CPointMass3DOperation<CPointMass3DOperationRemoveEntity> {
87  public:
89  };
90 
91 #define REGISTER_POINTMASS3D_OPERATION(ACTION, OPERATION, ENTITY) \
92  REGISTER_ENTITY_OPERATION(ACTION, CPointMass3DEngine, OPERATION, SOperationOutcome, ENTITY);
93 
94 #define REGISTER_STANDARD_POINTMASS3D_OPERATION_ADD_ENTITY(SPACE_ENTITY, PM3D_MODEL) \
95  class CPointMass3DOperationAdd ## SPACE_ENTITY : public CPointMass3DOperationAddEntity { \
96  public: \
97  CPointMass3DOperationAdd ## SPACE_ENTITY() {} \
98  virtual ~CPointMass3DOperationAdd ## SPACE_ENTITY() {} \
99  SOperationOutcome ApplyTo(CPointMass3DEngine& c_engine, \
100  SPACE_ENTITY& c_entity) { \
101  auto* pcPhysModel = new PM3D_MODEL(c_engine, \
102  c_entity); \
103  c_engine.AddPhysicsModel(c_entity.GetId(), \
104  *pcPhysModel); \
105  c_entity. \
106  GetComponent<CEmbodiedEntity>("body"). \
107  AddPhysicsModel(c_engine.GetId(), *pcPhysModel); \
108  return SOperationOutcome(true); \
109  } \
110  }; \
111  REGISTER_POINTMASS3D_OPERATION(CPointMass3DOperationAddEntity, \
112  CPointMass3DOperationAdd ## SPACE_ENTITY, \
113  SPACE_ENTITY);
114 
115 #define REGISTER_STANDARD_POINTMASS3D_OPERATION_REMOVE_ENTITY(SPACE_ENTITY) \
116  class CPointMass3DOperationRemove ## SPACE_ENTITY : public CPointMass3DOperationRemoveEntity { \
117  public: \
118  CPointMass3DOperationRemove ## SPACE_ENTITY() {} \
119  virtual ~CPointMass3DOperationRemove ## SPACE_ENTITY() {} \
120  SOperationOutcome ApplyTo(CPointMass3DEngine& c_engine, \
121  SPACE_ENTITY& c_entity) { \
122  c_engine.RemovePhysicsModel(c_entity.GetId()); \
123  c_entity. \
124  GetComponent<CEmbodiedEntity>("body"). \
125  RemovePhysicsModel(c_engine.GetId()); \
126  return SOperationOutcome(true); \
127  } \
128  }; \
129  REGISTER_POINTMASS3D_OPERATION(CPointMass3DOperationRemoveEntity, \
130  CPointMass3DOperationRemove ## SPACE_ENTITY, \
131  SPACE_ENTITY);
132 
133 #define REGISTER_STANDARD_POINTMASS3D_OPERATIONS_ON_ENTITY(SPACE_ENTITY, PM3D_ENTITY) \
134  REGISTER_STANDARD_POINTMASS3D_OPERATION_ADD_ENTITY(SPACE_ENTITY, PM3D_ENTITY) \
135  REGISTER_STANDARD_POINTMASS3D_OPERATION_REMOVE_ENTITY(SPACE_ENTITY)
136 
137  /****************************************/
138  /****************************************/
139 
140 }
141 
142 #endif
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
std::vector< SEmbodiedEntityIntersectionItem > TEmbodiedEntityIntersectionData
std::map< std::string, CControllableEntity * > TMap
A map of controllable entities, indexed by id.
The basic entity type.
Definition: entity.h:90
The basic operation to be stored in the vtable.
Definition: entity.h:331
A 3D vector class.
Definition: vector3.h:31
const std::map< std::string, CPointMass3DModel * > & GetPhysicsModels() const
virtual void CheckIntersectionWithRay(TEmbodiedEntityIntersectionData &t_data, const CRay3 &c_ray) const
Check which objects in this engine intersect the given ray.
virtual bool AddEntity(CEntity &c_entity)
Adds an entity to the physics engine.
virtual bool RemoveEntity(CEntity &c_entity)
Removes an entity from the physics engine.
virtual void Destroy()
Undoes whatever was done by Init().
virtual bool IsPointContained(const CVector3 &c_point)
Returns true if the given point is contained in this physics engine.
virtual bool IsEntityTransferNeeded() const
virtual size_t GetNumPhysicsModels()
void AddPhysicsModel(const std::string &str_id, CPointMass3DModel &c_model)
virtual void TransferEntities()
Executes the transfer of entities to other engines.
virtual void Reset()
Resets the resource.
virtual void Init(TConfigurationNode &t_tree)
Initializes the resource.
void RemovePhysicsModel(const std::string &str_id)
std::map< std::string, CPointMass3DModel * > & GetPhysicsModels()