AnimatLab  2
Test
VsBallSocket.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 #include "VsMovableItem.h"
9 #include "VsBody.h"
10 #include "VsJoint.h"
11 #include "VsMotorizedJoint.h"
12 #include "VsRigidBody.h"
13 #include "VsBallSocket.h"
14 #include "VsSimulator.h"
15 #include "VsDragger.h"
16 
17 namespace VortexAnimatSim
18 {
19  namespace Environment
20  {
21  namespace Joints
22  {
23 
31 {
32  SetThisPointers();
33  m_vxSocket = NULL;
34 }
35 
43 {
44 
45  try
46  {
47  DeleteGraphics();
48  DeletePhysics();
49  }
50  catch(...)
51  {Std_TraceMsg(0, "Caught Error in desctructor of VsBallSocket\r\n", "", -1, false, true);}
52 }
53 
54 void VsBallSocket::DeletePhysics()
55 {
56  if(!m_vxSocket)
57  return;
58 
59  if(GetVsSimulator() && GetVsSimulator()->Universe())
60  {
61  GetVsSimulator()->Universe()->removeConstraint(m_vxSocket);
62  delete m_vxSocket;
63 
64  if(m_lpChild && m_lpParent)
66  }
67 
68  m_vxSocket = NULL;
69  m_vxJoint = NULL;
70 }
71 
72 void VsBallSocket::SetupPhysics()
73 {
74  if(m_vxSocket)
75  DeletePhysics();
76 
77  if(!m_lpParent)
78  THROW_ERROR(Al_Err_lParentNotDefined, Al_Err_strParentNotDefined);
79 
80  if(!m_lpChild)
81  THROW_ERROR(Al_Err_lChildNotDefined, Al_Err_strChildNotDefined);
82 
83  VsRigidBody *lpVsParent = dynamic_cast<VsRigidBody *>(m_lpParent);
84  if(!lpVsParent)
85  THROW_ERROR(Vs_Err_lUnableToConvertToVsRigidBody, Vs_Err_strUnableToConvertToVsRigidBody);
86 
87  VsRigidBody *lpVsChild = dynamic_cast<VsRigidBody *>(m_lpChild);
88  if(!lpVsChild)
89  THROW_ERROR(Vs_Err_lUnableToConvertToVsRigidBody, Vs_Err_strUnableToConvertToVsRigidBody);
90 
91  CStdFPoint vGlobal = this->GetOSGWorldCoords();
92 
93  Vx::VxReal44 vMT;
94  VxOSG::copyOsgMatrix_to_VxReal44(this->GetOSGWorldMatrix(), vMT);
95  Vx::VxTransform vTrans(vMT);
96  Vx::VxReal3 vxRot;
97  vTrans.getRotationEulerAngles(vxRot);
98 
99  CStdFPoint vLocalRot(vxRot[0], vxRot[1], vxRot[2]); //= m_lpThisMI->Rotation();
100 
101  VxVector3 pos((double) vGlobal.x, (double) vGlobal.y, (double) vGlobal.z);
102  VxVector3 axis = NormalizeAxis(vLocalRot);
103 
104  m_vxSocket = new VxBallAndSocket(lpVsParent->Part(), lpVsChild->Part(), pos.v, axis.v);
105  m_vxSocket->setName(m_strID.c_str());
106 
107  GetVsSimulator()->Universe()->addConstraint(m_vxSocket);
108 
109  //Disable collisions between this object and its parent
111 
112  m_vxJoint = m_vxSocket;
113  m_iCoordID = -1; //Not used fo
114 }
115 
117 {
118  SetupGraphics();
119  SetupPhysics();
120 }
121 
122 #pragma region DataAccesMethods
123 
124 bool VsBallSocket::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
125 {
126  if(VsJoint::Physics_SetData(strDataType, strValue))
127  return true;
128 
129  if(BallSocket::SetData(strDataType, strValue, false))
130  return true;
131 
132  //If it was not one of those above then we have a problem.
133  if(bThrowError)
134  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
135 
136  return false;
137 }
138 
139 void VsBallSocket::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
140 {
141  VsJoint::Physics_QueryProperties(aryProperties);
142  BallSocket::QueryProperties(aryProperties);
143 }
144 
145 #pragma endregion
146 
147  } //Joints
148  } // Environment
149 } //VortexAnimatSim
virtual void DisableCollision(RigidBody *lpBody)
Disables collision between the past-in object and this object.
Definition: RigidBody.cpp:1374
virtual void EnableCollision(RigidBody *lpBody)
Enables collision between the past-in object and this object.
Definition: RigidBody.cpp:1343
A common class for all rigid body data specific to vortex.
Definition: VsRigidBody.h:55
virtual void CreateJoint()
Creates the joint.
std::string m_strID
The unique Id for this object.
Definition: AnimatBase.h:55
RigidBody * m_lpChild
The child rigid body for this joint.
Definition: Joint.h:44
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
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 SetupGraphics()
Sets up the graphics for the joint.
Definition: VsJoint.cpp:248
Vx::VxBallAndSocket * m_vxSocket
The vortex socket class.
Definition: VsBallSocket.h:33
Declares the vortex ball socket class.