Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00838_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/a00838_source.php on line 2
The ARGoS Website

dynamics3d_single_body_object_model.cpp
Go to the documentation of this file.
1 
8 
9 namespace argos {
10 
11  /****************************************/
12  /****************************************/
13 
15  CComposableEntity& c_entity) :
16  CDynamics3DModel(c_engine, c_entity) {
17  /* Single body models only contain one body */
18  m_vecBodies.reserve(1);
19  }
20 
21  /****************************************/
22  /****************************************/
23 
25  const CQuaternion& c_orientation) {
26  /* Calculate the transform */
27  const btTransform& cTransform = btTransform(
28  btQuaternion(c_orientation.GetX(),
29  c_orientation.GetZ(),
30  -c_orientation.GetY(),
31  c_orientation.GetW()),
32  btVector3(c_position.GetX(),
33  c_position.GetZ(),
34  -c_position.GetY()));
35  /* Move the body */
36  m_vecBodies[0]->GetTransform() =
37  cTransform * m_vecBodies[0]->GetData().InverseCenterOfMassOffset;
38  /* Synchronize with the entity in the space */
40  }
41 
42  /****************************************/
43  /****************************************/
44 
46  m_vecBodies[0]->Reset();
47  /* Synchronize with the entity in the space */
49  }
50 
51  /****************************************/
52  /****************************************/
53 
55  CAbstractBody* pcBody = m_vecBodies[0];
56  btCollisionShape& cShape = pcBody->GetShape();
57  btVector3 cAabbMin;
58  btVector3 cAabbMax;
59  /* Get the axis aligned bounding box for the current body */
60  cShape.getAabb(pcBody->GetTransform(), cAabbMin, cAabbMax);
61  /* Write back the bounding box swapping the coordinate systems and the Y component */
62  GetBoundingBox().MinCorner.Set(cAabbMin.getX(), -cAabbMax.getZ(), cAabbMin.getY());
63  GetBoundingBox().MaxCorner.Set(cAabbMax.getX(), -cAabbMin.getZ(), cAabbMax.getY());
64  }
65 
66  /****************************************/
67  /****************************************/
68 
69  void CDynamics3DSingleBodyObjectModel::AddToWorld(btMultiBodyDynamicsWorld& c_world) {
70  m_vecBodies[0]->AddToWorld(c_world);
71  }
72 
73  /****************************************/
74  /****************************************/
75 
76  void CDynamics3DSingleBodyObjectModel::RemoveFromWorld(btMultiBodyDynamicsWorld& c_world) {
77  m_vecBodies[0]->RemoveFromWorld(c_world);
78  }
79 
80  /****************************************/
81  /****************************************/
82 
84  btRigidBody::btRigidBodyConstructionInfo cInfo(m_sData.Mass,
85  nullptr,
86  &GetShape(),
87  m_sData.Inertia);
88  cInfo.m_friction = m_sData.Friction;
89  cInfo.m_startWorldTransform = m_sData.StartTransform *
90  m_sData.InverseCenterOfMassOffset;
91  /* Call the destructor */
92  m_cRigidBody.~btRigidBody();
93  /* Rerun the constructor */
94  new (&m_cRigidBody) btRigidBody(cInfo);
95  m_cRigidBody.setUserPointer(&m_cModel);
96  }
97 
98  /****************************************/
99  /****************************************/
100 
102  SAnchor& s_anchor,
103  std::shared_ptr<btCollisionShape>& ptr_shape,
104  const SData& s_data) :
105  CAbstractBody(c_model, s_anchor, ptr_shape, s_data),
106  m_cRigidBody(0.0f, nullptr, nullptr) {}
107 
108  /****************************************/
109  /****************************************/
110 
111  void CDynamics3DSingleBodyObjectModel::CBody::AddToWorld(btMultiBodyDynamicsWorld& c_world) {
112  c_world.addRigidBody(&m_cRigidBody);
113  }
114 
115  /****************************************/
116  /****************************************/
117 
118  void CDynamics3DSingleBodyObjectModel::CBody::RemoveFromWorld(btMultiBodyDynamicsWorld& c_world) {
119  c_world.removeRigidBody(&m_cRigidBody);
120  }
121 
122  /****************************************/
123  /****************************************/
124 
126  m_cRigidBody.applyCentralForce(c_force);
127  }
128 
129  /****************************************/
130  /****************************************/
131 
133  const btVector3& c_offset) {
134  m_cRigidBody.applyForce(c_force, c_offset);
135  }
136 
137  /****************************************/
138  /****************************************/
139 
141  m_cRigidBody.applyTorque(c_torque);
142  }
143 
144  /****************************************/
145  /****************************************/
146 
148  return m_cRigidBody.getWorldTransform();
149  }
150 
151  /****************************************/
152  /****************************************/
153 }
A 3D vector class.
Definition: vector3.h:29
virtual btTransform & GetTransform()=0
Real GetX() const
Definition: quaternion.h:53
Real GetX() const
Returns the x coordinate of this vector.
Definition: vector3.h:93
CBody(CDynamics3DModel &c_model, SAnchor &s_anchor, std::shared_ptr< btCollisionShape > &ptr_shape, const SData &s_data)
Real GetZ() const
Definition: quaternion.h:61
Real GetY() const
Returns the y coordinate of this vector.
Definition: vector3.h:109
virtual void MoveTo(const CVector3 &c_position, const CQuaternion &c_orientation)
std::vector< CAbstractBody * > m_vecBodies
virtual void AddToWorld(btMultiBodyDynamicsWorld &c_world)
void Set(const Real f_x, const Real f_y, const Real f_z)
Sets the vector contents from Cartesian coordinates.
Definition: vector3.h:143
Basic class for an entity that contains other entities.
virtual void CalculateBoundingBox()
Calculates the axis-aligned box that contains the entire physics model.
virtual void RemoveFromWorld(btMultiBodyDynamicsWorld &c_world)
An anchor related to the body of an entity.
Definition: physics_model.h:38
virtual void RemoveFromWorld(btMultiBodyDynamicsWorld &c_world)
Real GetW() const
Definition: quaternion.h:49
CDynamics3DSingleBodyObjectModel(CDynamics3DEngine &c_engine, CComposableEntity &c_entity)
virtual void AddToWorld(btMultiBodyDynamicsWorld &c_world)
const SBoundingBox & GetBoundingBox() const
Returns an axis-aligned box that contains the physics model.
Real GetY() const
Definition: quaternion.h:57
virtual void UpdateEntityStatus()
Updates the status of the associated entity.
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