9 #include <argos3/core/simulator/space/space.h>
10 #include <argos3/core/simulator/simulator.h>
11 #include <argos3/core/utility/string_utilities.h>
12 #include <argos3/core/utility/math/matrix/rotationmatrix3.h>
22 m_sBoundingBox(nullptr),
23 m_psOriginAnchor(nullptr) {}
29 const std::string& str_id,
34 m_bMovable(b_movable),
35 m_sBoundingBox(nullptr),
36 m_psOriginAnchor(new
SAnchor(*this,
43 m_cInitOriginPosition(c_position),
44 m_cInitOriginOrientation(c_orientation) {
107 psAnchor = it->second;
108 if(psAnchor->
Index > 0) {
135 auto* psAnchor =
new SAnchor(*
this,
139 c_offset_orientation,
159 ++(it->second->InUseCount);
161 if(it->second->InUseCount == 1) {
171 if(str_id ==
"origin")
return;
180 --((*it)->InUseCount);
182 if((*it)->InUseCount == 0) {
198 return *(it->second);
212 return *(it->second);
220 std::map<std::string, SAnchor*>::const_iterator it =
m_mapAnchors.find(str_id);
226 return (it->second->InUseCount > 0);
304 return *(it->second);
315 return *(it->second);
324 bool b_ignore_collisions) {
336 if(bNoCollision && !b_check_only) {
351 bool bNoCollision =
true;
356 if(bNoCollision && !b_check_only) {
364 for(
size_t j = 0; j < i; ++j) {
376 #define CHECK_CORNER(MINMAX, COORD, OP) \
377 if(m_sBoundingBox->MINMAX ## Corner.Get ## COORD() OP sBBox.MINMAX ## Corner.Get ## COORD()) { \
378 m_sBoundingBox->MINMAX ## Corner.Set ## COORD(sBBox.MINMAX ## Corner.Get ## COORD()); \
427 "\", but this entity has not been added to any physics engine.");
450 const std::string& str_id) {
451 return (ps_anchor->
Id == str_id);
457 void CEmbodiedEntitySpaceHashUpdater::operator()(CAbstractSpaceHash<CEmbodiedEntity>& c_space_hash,
458 CEmbodiedEntity& c_element) {
460 c_space_hash.SpaceToHashTable(m_nMinX, m_nMinY, m_nMinZ, c_element.GetBoundingBox().MinCorner);
462 c_space_hash.SpaceToHashTable(m_nMaxX, m_nMaxY, m_nMaxZ, c_element.GetBoundingBox().MaxCorner);
464 for(
SInt32 nK = m_nMinZ; nK <= m_nMaxZ; ++nK) {
465 for(
SInt32 nJ = m_nMinY; nJ <= m_nMaxY; ++nJ) {
466 for(
SInt32 nI = m_nMinX; nI <= m_nMaxX; ++nI) {
467 c_space_hash.UpdateCell(nI, nJ, nK, c_element);
483 m_cGrid.ClampCoordinates(m_nMinI, m_nMinJ, m_nMinK);
486 m_cGrid.ClampCoordinates(m_nMaxI, m_nMaxJ, m_nMaxK);
488 for(
SInt32 m_nK = m_nMinK; m_nK <= m_nMaxK; ++m_nK) {
489 for(
SInt32 m_nJ = m_nMinJ; m_nJ <= m_nMaxJ; ++m_nJ) {
490 for(
SInt32 m_nI = m_nMinI; m_nI <= m_nMaxI; ++m_nI) {
491 m_cGrid.UpdateCell(m_nI, m_nJ, m_nK, c_entity);
520 class CSpaceOperationRemoveEmbodiedEntity :
public CSpaceOperationRemoveEntity {
522 void ApplyTo(CSpace& c_space, CEmbodiedEntity& c_entity) {
524 CEntity* pcRoot = &c_entity;
525 while(pcRoot->HasParent()) {
526 pcRoot = &pcRoot->GetParent();
530 while(c_entity.GetPhysicsModelsNum() > 0) {
531 c_entity.GetPhysicsModel(0).GetEngine().RemoveEntity(*pcRoot);
534 catch(CARGoSException& ex) {
548 c_space.RemoveEntity(c_entity);
#define CHECK_CORNER(MINMAX, COORD, OP)
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
signed int SInt32
32-bit signed integer.
unsigned int UInt32
32-bit unsigned integer.
The namespace containing all the ARGoS related code.
bool operator==(const SAnchor *ps_anchor, const std::string &str_id)
Returns true if the anchor id matches the given id.
void GetNodeAttributeOrDefault(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer, const T &t_default)
Returns the value of a node's attribute, or the passed default value.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
REGISTER_SPACE_OPERATION(CSpaceOperationAddEntity, CSpaceOperationAddCFloorEntity, CFloorEntity)
T Max(const T &t_v1, const T &t_v2)
Returns the bigger of the two passed arguments.
T Min(const T &t_v1, const T &t_v2)
Returns the smaller of the two passed arguments.
Basic class for an entity that contains other entities.
This entity is a link to a body in the physics engine.
CQuaternion m_cInitOriginOrientation
void DisableAnchor(const std::string &str_id)
Disables an anchor.
virtual void AddPhysicsModel(const std::string &str_engine_id, CPhysicsModel &c_physics_model)
Adds a new physics model to this embodied entity.
bool IsAnchorEnabled(const std::string &str_id)
Returns true if the given anchor is enabled, false otherwise.
void RemovePhysicsModel(const std::string &str_engine_id)
Removes a physics model from this embodied entity.
CEmbodiedEntity(CComposableEntity *pc_parent)
Class constructor.
const SAnchor & GetAnchor(const std::string &str_id) const
Returns the wanted anchor as a const reference.
const SBoundingBox & GetBoundingBox() const
Returns the bounding box of this embodied entity.
SAnchor * m_psOriginAnchor
CPhysicsModel::TVector m_tPhysicsModelVector
std::map< std::string, SAnchor * > m_mapAnchors
void CalculateBoundingBox()
Calculates the bounding box of this entity.
std::vector< SAnchor * > m_vecEnabledAnchors
virtual bool IsCollidingWithSomething() const
Returns true if this entity is colliding with another object.
virtual ~CEmbodiedEntity()
Class destructor.
const CPhysicsModel & GetPhysicsModel(size_t un_idx) const
Returns a physics model associated to this entity.
CVector3 m_cInitOriginPosition
UInt32 GetPhysicsModelsNum() const
Returns the number of physics models associated to this entity.
SBoundingBox * m_sBoundingBox
virtual bool MoveTo(const CVector3 &c_position, const CQuaternion &c_orientation, bool b_check_only=false, bool b_ignore_collisions=false)
Moves the entity to the wanted position and orientation.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
CPhysicsModel::TMap m_tPhysicsModelMap
void EnableAnchor(const std::string &str_id)
Enables an anchor.
SAnchor & AddAnchor(const std::string &str_id, const CVector3 &c_rel_position=CVector3(), const CQuaternion &c_rel_orientation=CQuaternion())
Adds an anchor to the embodied entity.
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...
virtual bool operator()(CEmbodiedEntity &c_entity)
CEmbodiedEntityGridUpdater(CGrid< CEmbodiedEntity > &c_grid)
const std::string & GetId() const
Returns the id of this entity.
std::string GetContext() const
Returns the context of this entity.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
An anchor related to the body of an entity.
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.
UInt32 Index
The index of the anchor assigned by the embodied entity.
CVector3 Position
The position of the anchor wrt the global coordinate system.
CVector3 OffsetPosition
The initial position of the anchor wrt the body coordinate system.
void AddEntity(ENTITY &c_entity)
Adds an entity of the given type.
virtual void AddEntityToPhysicsEngine(CEmbodiedEntity &c_entity)
The exception that wraps all errors in ARGoS.
CVector3 & Rotate(const CQuaternion &c_quaternion)
Rotates this vector by the given quaternion.