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  btCollisionShape& cShape = m_vecBodies[0]->GetShape();
56  btVector3 cAabbMin;
57  btVector3 cAabbMax;
58  /* Get the axis aligned bounding box for the current body */
59  cShape.getAabb(m_vecBodies[0]->GetTransform(), cAabbMin, cAabbMax);
60  /* Write back the bounding box swapping the coordinate systems and the Y component */
61  GetBoundingBox().MinCorner.Set(cAabbMin.getX(), -cAabbMax.getZ(), cAabbMin.getY());
62  GetBoundingBox().MaxCorner.Set(cAabbMax.getX(), -cAabbMin.getZ(), cAabbMax.getY());
63  }
64 
65  /****************************************/
66  /****************************************/
67 
68  void CDynamics3DSingleBodyObjectModel::AddToWorld(btMultiBodyDynamicsWorld& c_world) {
69  m_vecBodies[0]->AddToWorld(c_world);
70  }
71 
72  /****************************************/
73  /****************************************/
74 
75  void CDynamics3DSingleBodyObjectModel::RemoveFromWorld(btMultiBodyDynamicsWorld& c_world) {
76  m_vecBodies[0]->RemoveFromWorld(c_world);
77  }
78 
79  /****************************************/
80  /****************************************/
81 
83  btRigidBody::btRigidBodyConstructionInfo cInfo(m_sData.Mass,
84  nullptr,
85  &GetShape(),
87  cInfo.m_friction = m_sData.Friction;
88  cInfo.m_startWorldTransform = m_sData.StartTransform *
90  /* Call the destructor */
91  m_cRigidBody.~btRigidBody();
92  /* Rerun the constructor */
93  new (&m_cRigidBody) btRigidBody(cInfo);
94  m_cRigidBody.setUserPointer(&m_cModel);
95  }
96 
97  /****************************************/
98  /****************************************/
99 
101  SAnchor* ps_anchor,
102  const std::shared_ptr<btCollisionShape>& ptr_shape,
103  const SData& s_data) :
104  CAbstractBody(c_model, ps_anchor, ptr_shape, s_data),
105  m_cRigidBody(0.0f, nullptr, nullptr) {}
106 
107  /****************************************/
108  /****************************************/
109 
110  void CDynamics3DSingleBodyObjectModel::CBody::AddToWorld(btMultiBodyDynamicsWorld& c_world) {
111  c_world.addRigidBody(&m_cRigidBody);
112  }
113 
114  /****************************************/
115  /****************************************/
116 
117  void CDynamics3DSingleBodyObjectModel::CBody::RemoveFromWorld(btMultiBodyDynamicsWorld& c_world) {
118  c_world.removeRigidBody(&m_cRigidBody);
119  }
120 
121  /****************************************/
122  /****************************************/
123 
125  m_cRigidBody.applyCentralForce(c_force);
126  }
127 
128  /****************************************/
129  /****************************************/
130 
132  const btVector3& c_offset) {
133  m_cRigidBody.applyForce(c_force, c_offset);
134  }
135 
136  /****************************************/
137  /****************************************/
138 
140  m_cRigidBody.applyTorque(c_torque);
141  }
142 
143  /****************************************/
144  /****************************************/
145 
147  return m_cRigidBody.getWorldTransform();
148  }
149 
150  /****************************************/
151  /****************************************/
152 }
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
Basic class for an entity that contains other entities.
An anchor related to the body of an entity.
Definition: physics_model.h:38
const SBoundingBox & GetBoundingBox() const
Returns an axis-aligned box that contains the physics model.
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
void Set(const Real f_x, const Real f_y, const Real f_z)
Sets the vector contents from Cartesian coordinates.
Definition: vector3.h:155
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
std::vector< std::shared_ptr< CAbstractBody > > m_vecBodies
virtual void UpdateEntityStatus()
Updates the status of the associated entity.
virtual void CalculateBoundingBox()
Calculates the axis-aligned box that contains the entire physics model.
virtual void AddToWorld(btMultiBodyDynamicsWorld &c_world)
virtual void MoveTo(const CVector3 &c_position, const CQuaternion &c_orientation)
CDynamics3DSingleBodyObjectModel(CDynamics3DEngine &c_engine, CComposableEntity &c_entity)
virtual void RemoveFromWorld(btMultiBodyDynamicsWorld &c_world)
virtual void AddToWorld(btMultiBodyDynamicsWorld &c_world)
virtual void RemoveFromWorld(btMultiBodyDynamicsWorld &c_world)
CBody(CDynamics3DModel &c_model, SAnchor *ps_anchor, const std::shared_ptr< btCollisionShape > &ptr_shape, const SData &s_data)