AnimatLab  2
Test
BlDistanceJoint.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 "BlDistanceJoint.h"
14 
15 namespace BulletAnimatSim
16 {
17  namespace Environment
18  {
19  namespace Joints
20  {
21 
29 {
30  SetThisPointers();
31  m_btDistance = NULL;
32 }
33 
41 {
42  try
43  {
44  DeleteGraphics();
45  DeletePhysics(false);
46  }
47  catch(...)
48  {Std_TraceMsg(0, "Caught Error in desctructor of BlDistanceJoint/\r\n", "", -1, false, true);}
49 }
50 
60 {
61 }
62 
63 void BlDistanceJoint::SetupPhysics()
64 {
65  //FIX PHYSICS
66  if(m_btJoint)
67  DeletePhysics(false);
68 
69  InitBaseJointPointers(m_lpParent, m_lpChild, m_aryRelaxations, -1);
70 
71  //Need to calculate the matrix transform for the joint relative to the child also.
72  osg::Matrix jointMT = this->GetOSGWorldMatrix();
73  osg::Matrix parentMT = m_lpBlParent->GetOSGWorldMatrix();
74  osg::Matrix osgJointRelParent = jointMT * osg::Matrix::inverse(parentMT);
75 
76  btTransform tmJointRelParent = osgbCollision::asBtTransform(osgJointRelParent);
77  btTransform tmJointRelChild = osgbCollision::asBtTransform(m_osgMT->getMatrix());
78 
79  m_btDistance = new btGeneric6DofConstraint(*m_lpBlParent->Part(), *m_lpBlChild->Part(), tmJointRelParent, tmJointRelChild, true);
80 
81  GetBlSimulator()->DynamicsWorld()->addConstraint(m_btDistance, true);
82  m_btDistance->setDbgDrawSize(btScalar(5.f));
83 
84  //m_btDistance->set
85 
86  m_btJoint = m_btDistance;
87 
88  Joint::Initialize();
89  BlJoint::Initialize();
90 }
91 
93 {
94  SetupGraphics();
95  SetupPhysics();
96 }
97 
98 #pragma region DataAccesMethods
99 
100 
101 bool BlDistanceJoint::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
102 {
103  if(BlJoint::Physics_SetData(strDataType, strValue))
104  return true;
105 
106  if(Joint::SetData(strDataType, strValue, false))
107  return true;
108 
109  //If it was not one of those above then we have a problem.
110  if(bThrowError)
111  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
112 
113  return false;
114 }
115 
116 void BlDistanceJoint::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
117 {
118  BlJoint::Physics_QueryProperties(aryProperties);
119  Joint::QueryProperties(aryProperties);
120 }
121 
122 #pragma endregion
123 
124  } //Joints
125  } // Environment
126 } //BulletAnimatSim
virtual void SetupGraphics()
Sets up the graphics for the joint.
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
btGeneric6DofConstraint * m_btDistance
The bullet socket class.
Declares the vortex distance joint class.
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