7 #ifndef DYNAMICS2D_ENGINE_H
8 #define DYNAMICS2D_ENGINE_H
11 class CDynamics2DEngine;
12 class CDynamics2DModel;
13 class CGripperEquippedEntity;
14 class CEmbodiedEntity;
17 #include <argos3/core/simulator/entity/controllable_entity.h>
18 #include <argos3/core/simulator/physics_engine/physics_engine.h>
19 #include <argos3/plugins/simulator/physics_engines/dynamics2d/chipmunk-physics/include/chipmunk.h>
71 const CRay3& c_ray)
const;
74 return m_fBoxLinearFriction;
78 return m_fBoxAngularFriction;
82 return m_fCylinderLinearFriction;
86 return m_fCylinderAngularFriction;
98 return m_ptGroundBody;
106 return cpSpaceGetDamping(m_ptSpace);
110 cpSpaceSetDamping(m_ptSpace, f_damping);
114 return CVector2(m_ptSpace->gravity.x, m_ptSpace->gravity.y);
118 m_ptSpace->gravity = cpv(c_gravity.
GetX(), c_gravity.
GetY());
122 return m_fGrippingRigidity;
126 m_fGrippingRigidity = f_gripping_rigidity;
131 const cpBody* pt_body);
142 cpFloat m_fBoxLinearFriction;
143 cpFloat m_fBoxAngularFriction;
144 cpFloat m_fCylinderLinearFriction;
145 cpFloat m_fCylinderAngularFriction;
147 cpBody* m_ptGroundBody;
148 Real m_fGrippingRigidity;
152 std::map<std::string, CDynamics2DModel*> m_tPhysicsModels;
159 template <
typename ACTION>
175 #define REGISTER_DYNAMICS2D_OPERATION(ACTION, OPERATION, ENTITY) \
176 REGISTER_ENTITY_OPERATION(ACTION, CDynamics2DEngine, OPERATION, SOperationOutcome, ENTITY);
178 #define REGISTER_STANDARD_DYNAMICS2D_OPERATION_ADD_ENTITY(SPACE_ENTITY, DYN2D_MODEL) \
179 class CDynamics2DOperationAdd ## SPACE_ENTITY : public CDynamics2DOperationAddEntity { \
181 CDynamics2DOperationAdd ## SPACE_ENTITY() {} \
182 virtual ~CDynamics2DOperationAdd ## SPACE_ENTITY() {} \
183 SOperationOutcome ApplyTo(CDynamics2DEngine& c_engine, \
184 SPACE_ENTITY& c_entity) { \
185 auto* pcPhysModel = new DYN2D_MODEL(c_engine, \
187 c_engine.AddPhysicsModel(c_entity.GetId(), \
190 GetComponent<CEmbodiedEntity>("body"). \
191 AddPhysicsModel(c_engine.GetId(), *pcPhysModel); \
192 return SOperationOutcome(true); \
195 REGISTER_DYNAMICS2D_OPERATION(CDynamics2DOperationAddEntity, \
196 CDynamics2DOperationAdd ## SPACE_ENTITY, \
199 #define REGISTER_STANDARD_DYNAMICS2D_OPERATION_REMOVE_ENTITY(SPACE_ENTITY) \
200 class CDynamics2DOperationRemove ## SPACE_ENTITY : public CDynamics2DOperationRemoveEntity { \
202 CDynamics2DOperationRemove ## SPACE_ENTITY() {} \
203 virtual ~CDynamics2DOperationRemove ## SPACE_ENTITY() {} \
204 SOperationOutcome ApplyTo(CDynamics2DEngine& c_engine, \
205 SPACE_ENTITY& c_entity) { \
206 c_engine.RemovePhysicsModel(c_entity.GetId()); \
208 GetComponent<CEmbodiedEntity>("body"). \
209 RemovePhysicsModel(c_engine.GetId()); \
210 return SOperationOutcome(true); \
213 REGISTER_DYNAMICS2D_OPERATION(CDynamics2DOperationRemoveEntity, \
214 CDynamics2DOperationRemove ## SPACE_ENTITY, \
217 #define REGISTER_STANDARD_DYNAMICS2D_OPERATIONS_ON_ENTITY(SPACE_ENTITY, DYN2D_ENTITY) \
218 REGISTER_STANDARD_DYNAMICS2D_OPERATION_ADD_ENTITY(SPACE_ENTITY, DYN2D_ENTITY) \
219 REGISTER_STANDARD_DYNAMICS2D_OPERATION_REMOVE_ENTITY(SPACE_ENTITY)
float Real
Collects all ARGoS code.
The namespace containing all the ARGoS related code.
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 operation to be stored in the vtable.
Real GetY() const
Returns the y coordinate of this vector.
Real GetX() const
Returns the x coordinate of this vector.
An entity that stores the state of a robot gripper.
cpConstraint * GripConstraint
CDynamics2DEngine & Engine
SDynamics2DEngineGripperData(CDynamics2DEngine &c_engine, CGripperEquippedEntity &c_entity, cpVect t_anchor)
CGripperEquippedEntity & GripperEntity
~SDynamics2DEngineGripperData()
void SetDamping(Real f_damping)
cpSpace * GetPhysicsSpace()
CVector2 GetGravity() const
cpFloat GetBoxAngularFriction() const
Real GetGrippingRigidity() const
Real GetElevation() const
virtual void Reset()
Resets the resource.
cpFloat GetBoxLinearFriction() const
void SetGravity(const CVector2 &c_gravity)
void RemovePhysicsModel(const std::string &str_id)
void PositionPhysicsToSpace(CVector3 &c_new_pos, const CVector3 &c_original_pos, const cpBody *pt_body)
virtual size_t GetNumPhysicsModels()
virtual void Init(TConfigurationNode &t_tree)
Initializes the resource.
void SetGrippingRigidity(Real f_gripping_rigidity)
virtual void Destroy()
Undoes whatever was done by Init().
virtual void CheckIntersectionWithRay(TEmbodiedEntityIntersectionData &t_data, const CRay3 &c_ray) const
Check which objects in this engine intersect the given ray.
cpFloat GetCylinderLinearFriction() const
void AddPhysicsModel(const std::string &str_id, CDynamics2DModel &c_model)
void OrientationPhysicsToSpace(CQuaternion &c_new_orient, cpBody *pt_body)
cpFloat GetCylinderAngularFriction() const
virtual bool RemoveEntity(CEntity &c_entity)
Removes an entity from the physics engine.
virtual bool AddEntity(CEntity &c_entity)
Adds an entity to the physics engine.
const cpSpace * GetPhysicsSpace() const
virtual ~CDynamics2DEngine()
virtual ~CDynamics2DOperation()
virtual ~CDynamics2DOperationAddEntity()
virtual ~CDynamics2DOperationRemoveEntity()
The base class for models in the dynamics 2D engine.