dynamics3d_cylinder_model.cpp
Go to the documentation of this file.
1 
8 
9 #include <argos3/plugins/simulator/entities/cylinder_entity.h>
10 #include <argos3/plugins/simulator/physics_engines/dynamics3d/dynamics3d_engine.h>
11 #include <argos3/plugins/simulator/physics_engines/dynamics3d/dynamics3d_single_body_object_model.h>
12 #include <argos3/plugins/simulator/physics_engines/dynamics3d/dynamics3d_shape_manager.h>
13 
14 namespace argos {
15 
16  /****************************************/
17  /****************************************/
18 
20  CCylinderEntity& c_cylinder) :
21  CDynamics3DSingleBodyObjectModel(c_engine, c_cylinder),
22  m_ptrBody(nullptr) {
23  /* Fetch a collision shape for this model */
24  const std::shared_ptr<btCollisionShape>& ptrShape =
26  btVector3(c_cylinder.GetRadius(),
27  c_cylinder.GetHeight() * 0.5f,
28  c_cylinder.GetRadius()));
29  /* Get the origin anchor */
30  SAnchor& sAnchor = c_cylinder.GetEmbodiedEntity().GetOriginAnchor();
31  const CQuaternion& cOrientation = sAnchor.Orientation;
32  const CVector3& cPosition = sAnchor.Position;
33  /* Calculate the start transform */
34  const btTransform& cStartTransform = btTransform(
35  btQuaternion(cOrientation.GetX(),
36  cOrientation.GetZ(),
37  -cOrientation.GetY(),
38  cOrientation.GetW()),
39  btVector3(cPosition.GetX(),
40  cPosition.GetZ(),
41  -cPosition.GetY()));
42  /* Calculate the center of mass offset */
43  const btTransform& cCenterOfMassOffset = btTransform(
44  btQuaternion(0.0f, 0.0f, 0.0f, 1.0f),
45  btVector3(0.0f, -c_cylinder.GetHeight() * 0.5f, 0.0f));
46  /* Initialize mass and inertia to zero (static object) */
47  Real fMass = 0.0f;
48  btVector3 cInertia(0.0f, 0.0f, 0.0f);
49  /* If the cylinder is movable calculate its mass and inertia */
50  if(c_cylinder.GetEmbodiedEntity().IsMovable()) {
51  fMass = c_cylinder.GetMass();
52  ptrShape->calculateLocalInertia(fMass, cInertia);
53  }
54  /* Use the default friction */
55  btScalar fFriction = GetEngine().GetDefaultFriction();
56  /* Set up body data */
57  CBody::SData sData(cStartTransform, cCenterOfMassOffset, cInertia, fMass, fFriction);
58  /* Create the body */
59  m_ptrBody = std::make_shared<CBody>(*this, &sAnchor, ptrShape, sData);
60  /* Transfer the body to the base class */
61  m_vecBodies.push_back(m_ptrBody);
62  /* Finalize model with a reset */
63  Reset();
64  }
65 
66  /****************************************/
67  /****************************************/
68 
70 
71  /****************************************/
72  /****************************************/
73 
74 }
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
REGISTER_STANDARD_DYNAMICS3D_OPERATIONS_ON_ENTITY(CEPuckEntity, CDynamics3DEPuckModel)
bool IsMovable() const
Returns true if the entity is movable.
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.
Definition: physics_model.h:38
CQuaternion Orientation
The orientation of the anchor wrt the global coordinate system.
Definition: physics_model.h:53
CVector3 Position
The position of the anchor wrt the global coordinate system.
Definition: physics_model.h:51
Real GetW() const
Definition: quaternion.h:49
Real GetX() const
Definition: quaternion.h:53
Real GetZ() const
Definition: quaternion.h:61
Real GetY() const
Definition: quaternion.h:57
A 3D vector class.
Definition: vector3.h:31
Real GetX() const
Returns the x coordinate of this vector.
Definition: vector3.h:105
Real GetY() const
Returns the y coordinate of this vector.
Definition: vector3.h:121
Real GetZ() const
Returns the z coordinate of this vector.
Definition: vector3.h:137
CEmbodiedEntity & GetEmbodiedEntity()
CDynamics3DCylinderModel(CDynamics3DEngine &c_engine, CCylinderEntity &c_cylinder)
btScalar GetDefaultFriction() const
std::vector< std::shared_ptr< CAbstractBody > > m_vecBodies
CDynamics3DEngine & GetEngine()
static std::shared_ptr< btCollisionShape > RequestCylinder(const btVector3 &c_half_extents)