ARGoS  3
A parallel, multi-engine simulator for swarm robotics
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  PM3D_MODEL* 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
argos::CPointMass3DEngine::GetPhysicsModels
std::map< std::string, CPointMass3DModel * > & GetPhysicsModels()
Definition: pointmass3d_engine.h:52
argos::CPointMass3DEngine::GetPhysicsModels
const std::map< std::string, CPointMass3DModel * > & GetPhysicsModels() const
Definition: pointmass3d_engine.h:56
argos::CEntityOperation
The basic operation to be stored in the vtable.
Definition: entity.h:278
argos::CPointMass3DEngine::IsPointContained
virtual bool IsPointContained(const CVector3 &c_point)
Returns true if the given point is contained in this physics engine.
Definition: pointmass3d_engine.cpp:112
argos::CPointMass3DEngine::GetNumPhysicsModels
virtual size_t GetNumPhysicsModels()
Definition: pointmass3d_engine.cpp:85
argos::CPointMass3DEngine::~CPointMass3DEngine
virtual ~CPointMass3DEngine()
Definition: pointmass3d_engine.cpp:24
argos
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
argos::CVector3
A 3D vector class.
Definition: vector3.h:29
argos::CPointMass3DEngine::IsEntityTransferNeeded
virtual bool IsEntityTransferNeeded() const
Definition: pointmass3d_engine.cpp:119
argos::CRay3
Definition: ray3.h:19
argos::CPointMass3DOperationAddEntity
Definition: pointmass3d_engine.h:81
argos::CPointMass3DEngine::TransferEntities
virtual void TransferEntities()
Executes the transfer of entities to other engines.
Definition: pointmass3d_engine.cpp:126
argos::CPointMass3DOperation::~CPointMass3DOperation
virtual ~CPointMass3DOperation()
Definition: pointmass3d_engine.h:78
argos::TConfigurationNode
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
Definition: argos_configuration.h:27
argos::CPointMass3DEngine::CheckIntersectionWithRay
virtual void CheckIntersectionWithRay(TEmbodiedEntityIntersectionData &t_data, const CRay3 &c_ray) const
Check which objects in this engine intersect the given ray.
Definition: pointmass3d_engine.cpp:132
argos::CPointMass3DModel
Definition: pointmass3d_model.h:21
argos::CPointMass3DEngine::CPointMass3DEngine
CPointMass3DEngine()
Definition: pointmass3d_engine.cpp:17
argos::CPointMass3DEngine::Init
virtual void Init(TConfigurationNode &t_tree)
Initializes the resource.
Definition: pointmass3d_engine.cpp:30
argos::CPointMass3DEngine::GetGravity
Real GetGravity() const
Definition: pointmass3d_engine.h:60
argos::CPointMass3DEngine::RemoveEntity
virtual bool RemoveEntity(CEntity &c_entity)
Removes an entity from the physics engine.
Definition: pointmass3d_engine.cpp:102
argos::CPointMass3DEngine::Update
virtual void Update()
Definition: pointmass3d_engine.cpp:62
argos::CPointMass3DOperationAddEntity::~CPointMass3DOperationAddEntity
virtual ~CPointMass3DOperationAddEntity()
Definition: pointmass3d_engine.h:83
argos::CPointMass3DEngine::Destroy
virtual void Destroy()
Undoes whatever was done by Init().
Definition: pointmass3d_engine.cpp:50
argos::CPhysicsEngine
Definition: physics_engine.h:90
argos::CEntity
The basic entity type.
Definition: entity.h:89
argos::CPointMass3DOperationRemoveEntity
Definition: pointmass3d_engine.h:86
argos::CPointMass3DOperation
Definition: pointmass3d_engine.h:76
argos::CPointMass3DEngine::AddEntity
virtual bool AddEntity(CEntity &c_entity)
Adds an entity to the physics engine.
Definition: pointmass3d_engine.cpp:92
argos::CPointMass3DEngine::RemovePhysicsModel
void RemovePhysicsModel(const std::string &str_id)
Definition: pointmass3d_engine.cpp:158
argos::TEmbodiedEntityIntersectionData
std::vector< SEmbodiedEntityIntersectionItem > TEmbodiedEntityIntersectionData
Definition: physics_engine.h:54
argos::CPointMass3DEngine
Definition: pointmass3d_engine.h:22
argos::CPointMass3DEngine::AddPhysicsModel
void AddPhysicsModel(const std::string &str_id, CPointMass3DModel &c_model)
Definition: pointmass3d_engine.cpp:150
argos::CPointMass3DEngine::Reset
virtual void Reset()
Resets the resource.
Definition: pointmass3d_engine.cpp:40
Real
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
argos::CControllableEntity::TMap
std::map< std::string, CControllableEntity * > TMap
A map of controllable entities, indexed by id.
Definition: controllable_entity.h:36
argos::CPointMass3DOperationRemoveEntity::~CPointMass3DOperationRemoveEntity
virtual ~CPointMass3DOperationRemoveEntity()
Definition: pointmass3d_engine.h:88