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