Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00819_source.php on line 2

Warning: include(): Failed opening 'php/utility.php' for inclusion (include_path='.:/usr/lib64/php') in /home/argos/argos3/doc/api/embedded/a00819_source.php on line 2
The ARGoS Website

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_pcBody(nullptr) {
23  /* Fetch a collision shape for this model */
24  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 the body */
57  CBody* m_pcBody = new CBody(*this,
58  sAnchor,
59  ptrShape,
60  CBody::SData(cStartTransform,
61  cCenterOfMassOffset,
62  cInertia,
63  fMass,
64  fFriction));
65  /* Transfer the body to the base class */
66  m_vecBodies.push_back(m_pcBody);
67  /* Synchronize with the entity in the space */
69  }
70 
71  /****************************************/
72  /****************************************/
73 
75  /* Delete the body */
76  delete m_pcBody;
77  }
78 
79  /****************************************/
80  /****************************************/
81 
83 
84  /****************************************/
85  /****************************************/
86 
87 }
A 3D vector class.
Definition: vector3.h:29
Real GetX() const
Definition: quaternion.h:53
CDynamics3DEngine & GetEngine()
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
Real GetX() const
Returns the x coordinate of this vector.
Definition: vector3.h:93
Real GetZ() const
Definition: quaternion.h:61
Real GetY() const
Returns the y coordinate of this vector.
Definition: vector3.h:109
CQuaternion Orientation
The orientation of the anchor wrt the global coordinate system.
Definition: physics_model.h:53
Real GetMass() const
Definition: box_entity.h:88
std::vector< CAbstractBody * > m_vecBodies
An anchor related to the body of an entity.
Definition: physics_model.h:38
CEmbodiedEntity & GetEmbodiedEntity()
Definition: box_entity.h:64
btScalar GetDefaultFriction() const
Real GetW() const
Definition: quaternion.h:49
REGISTER_STANDARD_DYNAMICS3D_OPERATIONS_ON_ENTITY(CPrototypeEntity, CDynamics3DPrototypeModel)
CVector3 Position
The position of the anchor wrt the global coordinate system.
Definition: physics_model.h:51
Real GetY() const
Definition: quaternion.h:57
virtual void UpdateEntityStatus()
Updates the status of the associated entity.
CDynamics3DBoxModel(CDynamics3DEngine &c_engine, CBoxEntity &c_box)
bool IsMovable() const
Returns true if the entity is movable.
const CVector3 & GetSize() const
Definition: box_entity.h:80
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
Real GetZ() const
Returns the z coordinate of this vector.
Definition: vector3.h:125
const SAnchor & GetOriginAnchor() const
Returns a const reference to the origin anchor associated to this entity.
static std::shared_ptr< btCollisionShape > RequestBox(const btVector3 &c_half_extents)