7 #ifndef PHYSICS_MODEL_H
8 #define PHYSICS_MODEL_H
15 class CEmbodiedEntity;
19 #include <argos3/core/utility/datatypes/datatypes.h>
20 #include <argos3/core/utility/math/vector3.h>
21 #include <argos3/core/utility/math/quaternion.h>
68 const std::string& str_id,
106 typedef std::map<std::string, CPhysicsModel*>
TMap;
115 while(!m_vecAnchorMethodHolders.empty()) {
116 delete m_vecAnchorMethodHolders.back();
117 m_vecAnchorMethodHolders.pop_back();
134 return m_cEmbodiedEntity;
142 return m_cEmbodiedEntity;
215 return m_sBoundingBox;
243 return m_sBoundingBox;
264 class CAnchorMethodHolder {};
272 template <
typename MODEL>
class CAnchorMethodHolderImpl :
public CAnchorMethodHolder {
274 typedef void (MODEL::*TMethod)(SAnchor&);
276 CAnchorMethodHolderImpl(TMethod t_method) : Method(t_method) {}
289 template <
typename USER_IMPL>
290 void Thunk(SAnchor& s_anchor);
298 std::vector<CAnchorMethodHolder*> m_vecAnchorMethodHolders;
305 std::vector<TThunk> m_vecThunks;
315 template <
typename MODEL>
317 void(MODEL::*pt_method)(SAnchor&));
324 template <
typename MODEL>
325 void CPhysicsModel::Thunk(SAnchor& s_anchor) {
333 MODEL& cImpl =
static_cast<MODEL&
>(*this);
335 CAnchorMethodHolderImpl<MODEL>& cMethodHolder =
static_cast<CAnchorMethodHolderImpl<MODEL>&
>(*m_vecAnchorMethodHolders[s_anchor.Index]);
337 (cImpl.*(cMethodHolder.Method))(s_anchor);
340 template <
typename MODEL>
342 void(MODEL::*pt_method)(
SAnchor&)) {
344 m_vecThunks[s_anchor.
Index] = &CPhysicsModel::Thunk<MODEL>;
346 m_vecAnchorMethodHolders[s_anchor.
Index] =
new CAnchorMethodHolderImpl<MODEL>(pt_method);
unsigned int UInt32
32-bit unsigned integer.
The namespace containing all the ARGoS related code.
This entity is a link to a body in the physics engine.
An anchor related to the body of an entity.
CEmbodiedEntity & Body
The embodied entity that owns this anchor.
CQuaternion Orientation
The orientation of the anchor wrt the global coordinate system.
CQuaternion OffsetOrientation
The initial orientation of the anchor wrt the body coordinate system.
std::string Id
The id of the anchor.
void Disable()
Disables this anchor.
SAnchor(CEmbodiedEntity &c_body, const std::string &str_id, UInt32 un_index, const CVector3 &c_offset_position, const CQuaternion &c_offset_orientation, const CVector3 &c_position, const CQuaternion &c_orientation)
Struct constructor.
UInt32 Index
The index of the anchor assigned by the embodied entity.
CVector3 Position
The position of the anchor wrt the global coordinate system.
void Enable()
Enables this anchor.
UInt32 InUseCount
A counter for the devices using this anchor.
CVector3 OffsetPosition
The initial position of the anchor wrt the body coordinate system.
bool Intersects(const SBoundingBox &s_bb) const
virtual void UpdateFromEntityStatus()=0
Updates the state of this model from the status of the associated entity.
void RegisterAnchorMethod(const SAnchor &s_anchor, void(MODEL::*pt_method)(SAnchor &))
Registers an anchor method.
std::map< std::string, CPhysicsModel * > TMap
std::vector< CPhysicsModel * > TVector
virtual void UpdatePhysics()
Performs extra work just before the physics update takes place.
virtual void MoveTo(const CVector3 &c_position, const CQuaternion &c_orientation)=0
virtual void CalculateAnchors()
Calculates the anchors associated to this model.
CEmbodiedEntity & GetEmbodiedEntity()
Returns the embodied entity associated to this physics model.
CPhysicsModel(CPhysicsEngine &c_engine, CEmbodiedEntity &c_entity)
CPhysicsEngine & GetEngine()
Returns the physics engine associated to this physics model.
const CEmbodiedEntity & GetEmbodiedEntity() const
Returns the embodied entity associated to this physics model.
virtual bool IsCollidingWithSomething() const =0
Returns true if this model is colliding with another model.
const SBoundingBox & GetBoundingBox() const
Returns an axis-aligned box that contains the physics model.
virtual void CalculateBoundingBox()=0
Calculates the axis-aligned box that contains the entire physics model.
SBoundingBox & GetBoundingBox()
Returns an axis-aligned box that contains the physics model.
virtual void UpdateEntityStatus()
Updates the status of the associated entity.
Real GetX() const
Returns the x coordinate of this vector.
Real GetY() const
Returns the y coordinate of this vector.
Real GetZ() const
Returns the z coordinate of this vector.