argos::CDynamics2DMultiBodyObjectModel Class Referenceabstract

Base class for object models with multiple bodies. More...

#include <dynamics2d_multi_body_object_model.h>

Inheritance diagram for argos::CDynamics2DMultiBodyObjectModel:
Collaboration diagram for argos::CDynamics2DMultiBodyObjectModel:

Classes

struct  SBody
 

Public Member Functions

 CDynamics2DMultiBodyObjectModel (CDynamics2DEngine &c_engine, CComposableEntity &c_entity)
 Class constructor. More...
 
virtual ~CDynamics2DMultiBodyObjectModel ()
 Class destructor. More...
 
CComposableEntityGetComposableEntity ()
 Returns the associated composable entity as a non-const reference. More...
 
const CComposableEntityGetComposableEntity () const
 Returns the associated composable entity as a const reference. More...
 
SBodyGetBody (size_t i)
 Returns the i-th body associated to the model. More...
 
const SBodyGetBody (size_t i) const
 Returns the i-th body associated to the model. More...
 
virtual void Reset ()
 
virtual void MoveTo (const CVector3 &c_position, const CQuaternion &c_orientation)
 
virtual void CalculateBoundingBox ()
 Calculates the axis-aligned box that contains the entire physics model. More...
 
virtual void UpdateFromEntityStatus ()=0
 Updates the state of this model from the status of the associated entity. More...
 
virtual bool IsCollidingWithSomething () const
 Returns true if this model is colliding with another model. More...
 
virtual void AddBody (cpBody *pt_body, const cpVect &t_offset_pos, cpFloat t_offset_orient, Real f_height)
 Adds a body. More...
 
- Public Member Functions inherited from argos::CDynamics2DModel
 CDynamics2DModel (CDynamics2DEngine &c_engine, CEmbodiedEntity &c_entity)
 
virtual ~CDynamics2DModel ()
 
CDynamics2DEngineGetDynamics2DEngine ()
 Returns the dynamics 2D engine state. More...
 
const CDynamics2DEngineGetDynamics2DEngine () const
 Returns the dynamics 2D engine state as a const reference. More...
 
- Public Member Functions inherited from argos::CPhysicsModel
 CPhysicsModel (CPhysicsEngine &c_engine, CEmbodiedEntity &c_entity)
 
virtual ~CPhysicsModel ()
 
CPhysicsEngineGetEngine ()
 Returns the physics engine associated to this physics model. More...
 
CEmbodiedEntityGetEmbodiedEntity ()
 Returns the embodied entity associated to this physics model. More...
 
const CEmbodiedEntityGetEmbodiedEntity () const
 Returns the embodied entity associated to this physics model. More...
 
virtual void UpdateEntityStatus ()
 Updates the status of the associated entity. More...
 
virtual void UpdatePhysics ()
 Performs extra work just before the physics update takes place. More...
 
const SBoundingBoxGetBoundingBox () const
 Returns an axis-aligned box that contains the physics model. More...
 
virtual void CalculateAnchors ()
 Calculates the anchors associated to this model. More...
 
SBoundingBoxGetBoundingBox ()
 Returns an axis-aligned box that contains the physics model. More...
 
template<typename MODEL >
void RegisterAnchorMethod (const SAnchor &s_anchor, void(MODEL::*pt_method)(SAnchor &))
 Registers an anchor method. More...
 

Additional Inherited Members

- Public Types inherited from argos::CDynamics2DModel
typedef std::map< std::string, CDynamics2DModel * > TMap
 
- Public Types inherited from argos::CPhysicsModel
typedef std::map< std::string, CPhysicsModel * > TMap
 
typedef std::vector< CPhysicsModel * > TVector
 

Detailed Description

Base class for object models with multiple bodies.

This class offers all the basic functionality to manage models composed of multiple bodies.

Multi-body objects are often active objects such as robots.

To use this class, simply create a class that inherits from it. The default implementations for Reset(), MoveTo(), etc. should be already OK for your needs.

In the constructor of your class, be sure to call the method AddBody() when you have created the bodies and associated the shapes to them. If this method is not called, the default implementations will have segfaults.

This class retains ownership for the bodies and shapes you created once you call AddBody(). In other words, you don't need to free these objects because ~CDynamics2DMultiBodyObjectModel() does it for you.

Definition at line 44 of file dynamics2d_multi_body_object_model.h.

Constructor & Destructor Documentation

◆ CDynamics2DMultiBodyObjectModel()

argos::CDynamics2DMultiBodyObjectModel::CDynamics2DMultiBodyObjectModel ( CDynamics2DEngine c_engine,
CComposableEntity c_entity 
)

Class constructor.

Parameters
c_engineThe dynamics 2D engine that manages this model.
c_entityThe composable entity associated to this model.
Exceptions
CARGoSExceptionif c_entity does not contain an embodied entity.

Definition at line 9 of file dynamics2d_multi_body_object_model.cpp.

◆ ~CDynamics2DMultiBodyObjectModel()

argos::CDynamics2DMultiBodyObjectModel::~CDynamics2DMultiBodyObjectModel ( )
virtual

Class destructor.

Disposes of the object body and its shapes.

Definition at line 17 of file dynamics2d_multi_body_object_model.cpp.

Member Function Documentation

◆ AddBody()

void argos::CDynamics2DMultiBodyObjectModel::AddBody ( cpBody *  pt_body,
const cpVect &  t_offset_pos,
cpFloat  t_offset_orient,
Real  f_height 
)
virtual

Adds a body.

You must call this method for this class' methods to work.

This class retains ownership of the passed body, so you don't need to explicitly delete anything.

Internally, this method also sets pc_body->userData to point to this, which is a requirement for ray cast queries to work properly.

Finally, this method also calculates the initial bounding box of the object.

Parameters
pt_bodyThe object body.
t_offset_posThe position of the body wrt the origin anchor.
t_offset_orientThe orientation of the body wrt the origin anchor.
f_heightThe object height.

Definition at line 136 of file dynamics2d_multi_body_object_model.cpp.

◆ CalculateBoundingBox()

void argos::CDynamics2DMultiBodyObjectModel::CalculateBoundingBox ( )
virtual

Calculates the axis-aligned box that contains the entire physics model.

The bounding box is often called AABB.

Implements argos::CPhysicsModel.

Reimplemented in argos::CDynamics2DFootBotModel.

Definition at line 88 of file dynamics2d_multi_body_object_model.cpp.

◆ GetBody() [1/2]

SBody& argos::CDynamics2DMultiBodyObjectModel::GetBody ( size_t  i)
inline

Returns the i-th body associated to the model.

Returns
The i-th body associated to the model.

Definition at line 96 of file dynamics2d_multi_body_object_model.h.

◆ GetBody() [2/2]

const SBody& argos::CDynamics2DMultiBodyObjectModel::GetBody ( size_t  i) const
inline

Returns the i-th body associated to the model.

Returns
The i-th body associated to the model.

Definition at line 104 of file dynamics2d_multi_body_object_model.h.

◆ GetComposableEntity() [1/2]

CComposableEntity& argos::CDynamics2DMultiBodyObjectModel::GetComposableEntity ( )
inline

Returns the associated composable entity as a non-const reference.

Returns
The associated composable entity as a non-const reference.

Definition at line 80 of file dynamics2d_multi_body_object_model.h.

◆ GetComposableEntity() [2/2]

const CComposableEntity& argos::CDynamics2DMultiBodyObjectModel::GetComposableEntity ( ) const
inline

Returns the associated composable entity as a const reference.

Returns
The associated composable entity as a const reference.

Definition at line 88 of file dynamics2d_multi_body_object_model.h.

◆ IsCollidingWithSomething()

bool argos::CDynamics2DMultiBodyObjectModel::IsCollidingWithSomething ( ) const
virtual

Returns true if this model is colliding with another model.

Returns
true if this model is colliding with another model.

Implements argos::CPhysicsModel.

Definition at line 116 of file dynamics2d_multi_body_object_model.cpp.

◆ MoveTo()

void argos::CDynamics2DMultiBodyObjectModel::MoveTo ( const CVector3 c_position,
const CQuaternion c_orientation 
)
virtual

Moves the entity to the wanted position and orientation within this engine. When you create a new model, you must implement this method. Don't forget to call UpdateEntityStatus() after you've changed the position.

This method should never be called directly from user code. It is called internally by CEmbodiedEntity::MoveTo(), which is meant to be called from user code.

CEmbodiedEntity::MoveTo() never calls this method if the embodied entity is static. This is because static entities cannot be moved around. Thus, there's no need in your code to check whether the associated entity is static.

Parameters
c_positionThe wanted position.
c_orientationThe wanted orientation.

Implements argos::CPhysicsModel.

Reimplemented in argos::CDynamics2DFootBotModel.

Definition at line 42 of file dynamics2d_multi_body_object_model.cpp.

◆ Reset()

void argos::CDynamics2DMultiBodyObjectModel::Reset ( )
virtual

Implements argos::CDynamics2DModel.

Reimplemented in argos::CDynamics2DFootBotModel.

Definition at line 71 of file dynamics2d_multi_body_object_model.cpp.

◆ UpdateFromEntityStatus()

virtual void argos::CDynamics2DMultiBodyObjectModel::UpdateFromEntityStatus ( )
pure virtual

Updates the state of this model from the status of the associated entity.

This method takes the current state of the associated entity (e.g., desired wheel speed, turret rotationss, etc.) and updates the state of this model. Typically, in this method you apply forces and set speeds.

Implements argos::CPhysicsModel.

Implemented in argos::CDynamics2DFootBotModel.