9 #include <argos3/core/simulator/physics_engine/physics_model.h>
10 #include <argos3/core/simulator/entity/composable_entity.h>
11 #include <argos3/core/utility/math/vector3.h>
12 #include <argos3/core/utility/math/quaternion.h>
13 #include <argos3/plugins/simulator/physics_engines/dynamics3d/dynamics3d_engine.h>
21 const btTransform& c_center_of_mass_offset,
22 const btVector3& c_inertia,
25 const std::vector<SDipole>& vec_dipoles) :
26 StartTransform(c_start_transform),
27 InverseStartTransform(c_start_transform.inverse()),
28 CenterOfMassOffset(c_center_of_mass_offset),
29 InverseCenterOfMassOffset(c_center_of_mass_offset.inverse()),
33 Dipoles(vec_dipoles) {}
40 const std::shared_ptr<btCollisionShape>& ptr_shape,
41 const SData& s_data) :
65 return *(m_ptrShape.get());
79 if(m_psAnchor !=
nullptr) {
81 btTransform cTransform =
82 GetTransform() * m_sData.CenterOfMassOffset;
84 const btVector3& cPosition = cTransform.getOrigin();
85 const btQuaternion& cOrientation = cTransform.getRotation();
87 m_psAnchor->Position.Set(cPosition.getX(), -cPosition.getZ(), cPosition.getY());
89 m_psAnchor->Orientation.Set(cOrientation.getW(),
103 m_cComposableEntity(c_entity) {}
110 m_cEngine.
GetWorld().performDiscreteCollisionDetection();
112 const btCollisionDispatcher& cDispatcher =
115 for(
SInt32 i = 0; i < cDispatcher.getNumManifolds(); i++) {
116 const btPersistentManifold* pcContactManifold =
117 cDispatcher.getManifoldByIndexInternal(i);
118 const auto* pcModelA =
119 static_cast<const CDynamics3DModel*
>(pcContactManifold->getBody0()->getUserPointer());
120 const auto* pcModelB =
121 static_cast<const CDynamics3DModel*
>(pcContactManifold->getBody1()->getUserPointer());
123 if(pcModelA == pcModelB) {
127 if((pcModelA ==
nullptr) || (pcModelB ==
nullptr)) {
131 if((pcModelA ==
this) || (pcModelB ==
this)) {
134 for(
SInt32 j = 0; j < pcContactManifold->getNumContacts(); j++) {
135 const btManifoldPoint& cManifoldPoint = pcContactManifold->getContactPoint(j);
136 if (cManifoldPoint.getDistance() < 0.0f) {
150 for(
const std::shared_ptr<CAbstractBody>& ptr_body :
m_vecBodies) {
151 ptr_body->UpdateAnchor();
signed int SInt32
32-bit signed integer.
The namespace containing all the ARGoS related code.
Basic class for an entity that contains other entities.
This entity is a link to a body in the physics engine.
An anchor related to the body of an entity.
virtual void UpdateEntityStatus()
Updates the status of the associated entity.
btMultiBodyDynamicsWorld & GetWorld()
btCollisionDispatcher & GetDispatcher()
virtual bool IsCollidingWithSomething() const
Returns true if this model is colliding with another model.
std::vector< std::shared_ptr< CAbstractBody > > m_vecBodies
virtual void UpdateEntityStatus()
Updates the status of the associated entity.
CDynamics3DModel(CDynamics3DEngine &c_engine, CComposableEntity &c_entity)
btCollisionShape & GetShape()
CDynamics3DModel & m_cModel
CDynamics3DModel & GetModel()
std::shared_ptr< btCollisionShape > m_ptrShape
CAbstractBody(CDynamics3DModel &c_model, SAnchor *ps_anchor, const std::shared_ptr< btCollisionShape > &ptr_shape, const SData &s_data)
const SData & GetData() const
SData(const btTransform &c_start_transform, const btTransform &c_center_of_mass_offset, const btVector3 &c_inertia, btScalar f_mass, btScalar f_friction, const std::vector< SDipole > &vec_dipoles=std::vector< SDipole >())