AnimatLab  2
Test
BlBallSocket.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 #include "BlJoint.h"
9 #include "BlMotorizedJoint.h"
10 #include "BlRigidBody.h"
11 #include "BlBallSocket.h"
12 #include "BlSimulator.h"
13 
14 namespace BulletAnimatSim
15 {
16  namespace Environment
17  {
18  namespace Joints
19  {
20 
28 {
29  SetThisPointers();
30  m_btSocket = NULL;
31 }
32 
40 {
41 
42  try
43  {
44  DeleteGraphics();
45  DeletePhysics(false);
46  }
47  catch(...)
48  {Std_TraceMsg(0, "Caught Error in desctructor of BlBallSocket\r\n", "", -1, false, true);}
49 }
50 
51 void BlBallSocket::SetupPhysics()
52 {
53  if(m_btJoint)
54  DeletePhysics(false);
55 
56  InitBaseJointPointers(m_lpParent, m_lpChild, m_aryRelaxations, -1);
57 
58  btTransform mtJointRelParent, mtJointRelChild;
59  CalculateRelativeJointMatrices(mtJointRelParent, mtJointRelChild);
60 
61  m_btSocket = new btConeTwistConstraint(*m_lpBlParent->Part(), *m_lpBlChild->Part(), mtJointRelParent, mtJointRelChild);
62 
63  GetBlSimulator()->DynamicsWorld()->addConstraint(m_btSocket, true);
64  m_btSocket->setDbgDrawSize(btScalar(5.f));
65 
66  if(m_lpBlParent && m_lpBlParent->Part())
67  m_lpBlParent->Part()->setSleepingThresholds(0, 0);
68 
69  if(m_lpBlChild && m_lpBlChild->Part())
70  m_lpBlChild->Part()->setSleepingThresholds(0, 0);
71 
72  m_btJoint = m_btSocket;
73 
74  BallSocket::Initialize();
75  BlJoint::Initialize();
76 }
77 
79 {
80  SetupGraphics();
81  SetupPhysics();
82 }
83 
84 void BlBallSocket::Physics_ResetSimulation()
85 {
86  BlJoint::Physics_ResetSimulation();
87 
88  if(m_btSocket)
89  m_btSocket->internalSetAppliedImpulse(0);
90 }
91 
92 #pragma region DataAccesMethods
93 
94 bool BlBallSocket::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
95 {
96  if(BlJoint::Physics_SetData(strDataType, strValue))
97  return true;
98 
99  if(BallSocket::SetData(strDataType, strValue, false))
100  return true;
101 
102  //If it was not one of those above then we have a problem.
103  if(bThrowError)
104  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
105 
106  return false;
107 }
108 
109 void BlBallSocket::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
110 {
111  BlJoint::Physics_QueryProperties(aryProperties);
112  BallSocket::QueryProperties(aryProperties);
113 }
114 
115 #pragma endregion
116 
117  } //Joints
118  } // Environment
119 } //BulletAnimatSim
Declares the vortex ball socket class.
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
btConeTwistConstraint * m_btSocket
The bullet socket class.
Definition: BlBallSocket.h:33
RigidBody * m_lpChild
The child rigid body for this joint.
Definition: Joint.h:44
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
ConstraintRelaxation * m_aryRelaxations[6]
The relaxations for the constraints.
Definition: Joint.h:64
virtual void CreateJoint()
Creates the joint.