9 #include <argos3/core/simulator/entity/composable_entity.h>
11 #include <argos3/core/utility/math/matrix/transformationmatrix3.h>
23 m_cMultiBody(un_num_links, 0.0f, btVector3(0,0,0), b_fixed_base, false),
24 m_unNumLinks(un_num_links),
25 m_bFixedBase(b_fixed_base) {
46 for(
const std::shared_ptr<CAbstractBody>& ptr_body :
m_vecBodies) {
66 for(
const std::shared_ptr<CAbstractBody>& ptr_body :
m_vecBodies) {
67 ptr_body->AddToWorld(c_world);
76 for(
const std::shared_ptr<CAbstractBody>& ptr_body :
m_vecBodies) {
77 ptr_body->RemoveFromWorld(c_world);
87 btVector3 cModelAabbMin, cModelAabbMax, cBodyAabbMin, cBodyAabbMax;
89 std::shared_ptr<CAbstractBody>& ptr_base =
m_vecBodies[0];
90 ptr_base->GetShape().getAabb(ptr_base->GetTransform(), cModelAabbMin, cModelAabbMax);
92 for(
const std::shared_ptr<CAbstractBody>& ptr_body :
m_vecBodies) {
94 ptr_body->GetShape().getAabb(ptr_body->GetTransform(), cBodyAabbMin, cBodyAabbMax);
96 cModelAabbMin.setX(cModelAabbMin.getX() < cBodyAabbMin.getX() ? cModelAabbMin.getX() : cBodyAabbMin.getX());
97 cModelAabbMin.setY(cModelAabbMin.getY() < cBodyAabbMin.getY() ? cModelAabbMin.getY() : cBodyAabbMin.getY());
98 cModelAabbMin.setZ(cModelAabbMin.getZ() < cBodyAabbMin.getZ() ? cModelAabbMin.getZ() : cBodyAabbMin.getZ());
100 cModelAabbMax.setX(cModelAabbMax.getX() > cBodyAabbMax.getX() ? cModelAabbMax.getX() : cBodyAabbMax.getX());
101 cModelAabbMax.setY(cModelAabbMax.getY() > cBodyAabbMax.getY() ? cModelAabbMax.getY() : cBodyAabbMax.getY());
102 cModelAabbMax.setZ(cModelAabbMax.getZ() > cBodyAabbMax.getZ() ? cModelAabbMax.getZ() : cBodyAabbMax.getZ());
115 const btTransform& cMoveToTransform =
116 btTransform(btQuaternion(c_orientation.
GetX(),
117 c_orientation.
GetZ(),
118 -c_orientation.
GetY(),
119 c_orientation.
GetW()),
120 btVector3(c_position.
GetX(),
122 -c_position.
GetY()));
125 const btTransform& cOriginAnchorTransform =
135 cOriginAnchorTransform.inverse() *
m_cMultiBody.getBaseWorldTransform());
137 btAlignedObjectArray<btQuaternion> vecRotations;
138 btAlignedObjectArray<btVector3> vecTranslations;
139 m_cMultiBody.updateCollisionObjectWorldTransforms(vecRotations, vecTranslations);
155 cOriginAnchorPosition.
Rotate(cOriginAnchorOrientation);
156 cOriginAnchorPosition += sBaseAnchor.
Position;
158 s_anchor.
Position = cOriginAnchorPosition;
168 const std::shared_ptr<btCollisionShape>& ptr_shape,
169 const SData& s_data) :
172 m_unLinkIndex(un_link_index),
173 m_cMultiBodyLink(nullptr, 0) {}
180 m_cMultiBodyLink.~btMultiBodyLinkCollider();
182 btMultiBody& cMultiBody = m_cModel.GetMultiBody();
183 new (&m_cMultiBodyLink) btMultiBodyLinkCollider(&cMultiBody, m_unLinkIndex);
185 m_cMultiBodyLink.setCollisionShape(m_ptrShape.get());
186 m_cMultiBodyLink.setWorldTransform(m_sData.StartTransform *
187 m_sData.InverseCenterOfMassOffset);
188 m_cMultiBodyLink.setFriction(m_sData.Friction);
189 m_cMultiBodyLink.setUserPointer(&m_cModel);
190 cMultiBody.getLink(m_unLinkIndex).m_collider = &m_cMultiBodyLink;
197 c_world.addCollisionObject(&m_cMultiBodyLink,
198 btBroadphaseProxy::DefaultFilter,
199 btBroadphaseProxy::AllFilter);
206 c_world.removeCollisionObject(&m_cMultiBodyLink);
213 btMultiBody& cMultiBody = m_cModel.GetMultiBody();
214 cMultiBody.addLinkForce(m_unLinkIndex, c_force);
221 const btVector3& c_offset) {
222 btMultiBody& cMultiBody = m_cModel.GetMultiBody();
223 cMultiBody.addLinkForce(m_unLinkIndex, c_force);
224 cMultiBody.addLinkTorque(m_unLinkIndex, c_offset.cross(c_force));
231 btMultiBody& cMultiBody = m_cModel.GetMultiBody();
232 cMultiBody.addLinkTorque(m_unLinkIndex, c_torque);
239 return m_cMultiBodyLink.getWorldTransform();
246 return m_unLinkIndex;
254 const std::shared_ptr<btCollisionShape>& ptr_shape,
255 const SData& s_data) :
256 CLink(c_model, -1, ps_anchor, ptr_shape, s_data) {}
263 m_cMultiBodyLink.~btMultiBodyLinkCollider();
265 btMultiBody& cMultiBody = m_cModel.GetMultiBody();
266 new (&m_cMultiBodyLink) btMultiBodyLinkCollider(&cMultiBody, -1);
268 m_cMultiBodyLink.setCollisionShape(m_ptrShape.get());
269 m_cMultiBodyLink.setWorldTransform(m_sData.StartTransform *
270 m_sData.InverseCenterOfMassOffset);
271 m_cMultiBodyLink.setFriction(m_sData.Friction);
272 m_cMultiBodyLink.setUserPointer(&m_cModel);
274 cMultiBody.setBaseWorldTransform(m_sData.StartTransform * m_sData.InverseCenterOfMassOffset);
275 cMultiBody.setBaseCollider(&m_cMultiBodyLink);
282 btMultiBody& cMultiBody = m_cModel.GetMultiBody();
283 cMultiBody.addBaseForce(c_force);
290 const btVector3& c_offset) {
291 btMultiBody& cMultiBody = m_cModel.GetMultiBody();
292 cMultiBody.addBaseForce(c_force);
293 cMultiBody.addBaseTorque(c_offset.cross(c_force));
300 btMultiBody& cMultiBody = m_cModel.GetMultiBody();
301 cMultiBody.addBaseTorque(c_torque);
unsigned int UInt32
32-bit unsigned integer.
The namespace containing all the ARGoS related code.
Basic class for an entity that contains other entities.
const SAnchor & GetOriginAnchor() const
Returns a const reference to the origin anchor associated to this entity.
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.
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 RegisterAnchorMethod(const SAnchor &s_anchor, void(MODEL::*pt_method)(SAnchor &))
Registers an anchor method.
CEmbodiedEntity & GetEmbodiedEntity()
Returns the embodied entity associated to this physics model.
const SBoundingBox & GetBoundingBox() const
Returns an axis-aligned box that contains the physics model.
CQuaternion Inverse() const
CVector3 & Rotate(const CQuaternion &c_quaternion)
Rotates this vector by the given quaternion.
Real GetX() const
Returns the x coordinate of this vector.
void Set(const Real f_x, const Real f_y, const Real f_z)
Sets the vector contents from Cartesian coordinates.
Real GetY() const
Returns the y coordinate of this vector.
Real GetZ() const
Returns the z coordinate of this vector.
std::vector< std::shared_ptr< CAbstractBody > > m_vecBodies
virtual void UpdateEntityStatus()
Updates the status of the associated entity.
virtual void UpdateOriginAnchor(SAnchor &s_anchor)
virtual void RemoveFromWorld(btMultiBodyDynamicsWorld &c_world)
virtual void CalculateBoundingBox()
Calculates the axis-aligned box that contains the entire physics model.
virtual void AddToWorld(btMultiBodyDynamicsWorld &c_world)
virtual void MoveTo(const CVector3 &c_position, const CQuaternion &c_orientation)
CDynamics3DMultiBodyObjectModel(CDynamics3DEngine &c_engine, CComposableEntity &c_entity, UInt32 un_num_links, bool b_fixed_base)
virtual void ApplyForce(const btVector3 &c_force)
virtual void ApplyTorque(const btVector3 &c_torque)
CLink(CDynamics3DMultiBodyObjectModel &c_model, UInt32 un_link_index, SAnchor *ps_anchor, const std::shared_ptr< btCollisionShape > &ptr_shape, const SData &s_data)
virtual btTransform & GetTransform()
virtual void RemoveFromWorld(btMultiBodyDynamicsWorld &c_world)
virtual void AddToWorld(btMultiBodyDynamicsWorld &c_world)
CBase(CDynamics3DMultiBodyObjectModel &c_model, SAnchor *ps_anchor, const std::shared_ptr< btCollisionShape > &ptr_shape, const SData &s_data)
virtual void ApplyTorque(const btVector3 &c_torque)
virtual void ApplyForce(const btVector3 &c_force)