dynamics3d_box_model.cpp
Go to the documentation of this file.
1 
7 #include "dynamics3d_box_model.h"
8 
9 #include <argos3/plugins/simulator/entities/box_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  CBoxEntity& c_box) :
21  CDynamics3DSingleBodyObjectModel(c_engine, c_box),
22  m_ptrBody(nullptr) {
23  /* Fetch a collision shape for this model */
24  const std::shared_ptr<btCollisionShape>& ptrShape =
26  btVector3(c_box.GetSize().GetX() * 0.5f,
27  c_box.GetSize().GetZ() * 0.5f,
28  c_box.GetSize().GetY() * 0.5f));
29  /* Get the origin anchor */
30  SAnchor& sAnchor = c_box.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_box.GetSize().GetZ() * 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 box is movable calculate its mass and inertia */
50  if(c_box.GetEmbodiedEntity().IsMovable()) {
51  fMass = c_box.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()
Definition: box_entity.h:64
Real GetMass() const
Definition: box_entity.h:86
const CVector3 & GetSize() const
Definition: box_entity.h:80
CDynamics3DBoxModel(CDynamics3DEngine &c_engine, CBoxEntity &c_box)
btScalar GetDefaultFriction() const
std::vector< std::shared_ptr< CAbstractBody > > m_vecBodies
CDynamics3DEngine & GetEngine()
static std::shared_ptr< btCollisionShape > RequestBox(const btVector3 &c_half_extents)