dynamics2d_stretchable_object_model.cpp
Go to the documentation of this file.
2 #include "dynamics2d_gripping.h"
3 
4 namespace argos {
5 
6  /****************************************/
7  /****************************************/
8 
10  CComposableEntity& c_entity) :
11  CDynamics2DSingleBodyObjectModel(c_engine, c_entity),
12  m_fMass(0.0f),
13  m_pcGrippable(nullptr),
14  m_ptLinearFriction(nullptr),
15  m_ptAngularFriction(nullptr) {}
16 
17  /****************************************/
18  /****************************************/
19 
21  if(m_pcGrippable != nullptr) delete m_pcGrippable;
22  if(m_ptLinearFriction != nullptr) {
23  cpSpaceRemoveConstraint(GetDynamics2DEngine().GetPhysicsSpace(), m_ptLinearFriction);
24  cpConstraintFree(m_ptLinearFriction);
25  }
26  if(m_ptAngularFriction != nullptr) {
27  cpSpaceRemoveConstraint(GetDynamics2DEngine().GetPhysicsSpace(), m_ptAngularFriction);
28  cpConstraintFree(m_ptAngularFriction);
29  }
30  }
31 
32  /****************************************/
33  /****************************************/
34 
36  const CQuaternion& c_orientation) {
37  if(m_pcGrippable != nullptr) {
38  /* Release all attached entities */
39  m_pcGrippable->ReleaseAll();
40  }
41  CDynamics2DSingleBodyObjectModel::MoveTo(c_position, c_orientation);
42  }
43 
44  /****************************************/
45  /****************************************/
46 
48  if(m_pcGrippable != nullptr) {
49  /* Release all attached entities */
50  m_pcGrippable->ReleaseAll();
51  }
53  }
54 
55  /****************************************/
56  /****************************************/
57 
59  Real f_max_force) {
60  m_ptLinearFriction =
61  cpSpaceAddConstraint(GetDynamics2DEngine().GetPhysicsSpace(),
62  cpPivotJointNew2(GetDynamics2DEngine().GetGroundBody(),
63  GetBody(),
64  cpvzero,
65  cpvzero));
66  m_ptLinearFriction->maxBias = f_max_bias;
67  m_ptLinearFriction->maxForce = f_max_force; // emulate linear friction
68  }
69 
70  /****************************************/
71  /****************************************/
72 
74  Real f_max_force) {
75  m_ptAngularFriction =
76  cpSpaceAddConstraint(GetDynamics2DEngine().GetPhysicsSpace(),
77  cpGearJointNew(GetDynamics2DEngine().GetGroundBody(),
78  GetBody(),
79  0.0f,
80  1.0f));
81  m_ptAngularFriction->maxBias = f_max_bias;
82  m_ptAngularFriction->maxForce = f_max_force; // emulate angular friction
83  }
84 
85  /****************************************/
86  /****************************************/
87 
88 }
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
Basic class for an entity that contains other entities.
A 3D vector class.
Definition: vector3.h:31
CDynamics2DEngine & GetDynamics2DEngine()
Returns the dynamics 2D engine state.
Base class for object models with a single body.
cpBody * GetBody()
Returns the body as non-const pointer.
virtual void MoveTo(const CVector3 &c_position, const CQuaternion &c_orientation)
virtual void MoveTo(const CVector3 &c_position, const CQuaternion &c_orientation)
CDynamics2DStretchableObjectModel(CDynamics2DEngine &c_engine, CComposableEntity &c_entity)
void SetLinearFriction(Real f_max_bias, Real f_max_force)
Sets the linear friction of this object.
void SetAngularFriction(Real f_max_bias, Real f_max_force)
Sets the angular friction of this object.