AnimatLab  2
Test
VsUniversal.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 "VsSphere.h"
14 #include "VsStructure.h"
15 #include "VsSimulator.h"
16 #include "VsOsgUserData.h"
17 #include "VsOsgUserDataVisitor.h"
18 #include "VsDragger.h"
19 #include "VsUniversal.h"
20 
21 
22 namespace VortexAnimatSim
23 {
24  namespace Environment
25  {
26  namespace Joints
27  {
28 
36 {
37  SetThisPointers();
38  m_vxSocket = NULL;
39 }
40 
48 {
49  try
50  {
51  DeleteGraphics();
52  DeletePhysics();
53  }
54  catch(...)
55  {Std_TraceMsg(0, "Caught Error in desctructor of VsUniversal/\r\n", "", -1, false, true);}
56 }
57 
58 void VsUniversal::DeletePhysics()
59 {
60  if(!m_vxSocket)
61  return;
62 
63  if(GetVsSimulator() && GetVsSimulator()->Universe())
64  {
65  GetVsSimulator()->Universe()->removeConstraint(m_vxSocket);
66  delete m_vxSocket;
67 
68  if(m_lpChild && m_lpParent)
70  }
71 
72  m_vxSocket = NULL;
73  m_vxJoint = NULL;
74 }
75 
76 void VsUniversal::SetupPhysics()
77 {
78  if(m_vxSocket)
79  DeletePhysics();
80 
81  if(!m_lpParent)
82  THROW_ERROR(Al_Err_lParentNotDefined, Al_Err_strParentNotDefined);
83 
84  if(!m_lpChild)
85  THROW_ERROR(Al_Err_lChildNotDefined, Al_Err_strChildNotDefined);
86 
87  VsRigidBody *lpVsParent = dynamic_cast<VsRigidBody *>(m_lpParent);
88  if(!lpVsParent)
89  THROW_ERROR(Vs_Err_lUnableToConvertToVsRigidBody, Vs_Err_strUnableToConvertToVsRigidBody);
90 
91  VsRigidBody *lpVsChild = dynamic_cast<VsRigidBody *>(m_lpChild);
92  if(!lpVsChild)
93  THROW_ERROR(Vs_Err_lUnableToConvertToVsRigidBody, Vs_Err_strUnableToConvertToVsRigidBody);
94 
95  CStdFPoint vGlobal = this->GetOSGWorldCoords();
96 
97  Vx::VxReal44 vMT;
98  VxOSG::copyOsgMatrix_to_VxReal44(this->GetOSGWorldMatrix(true), vMT);
99  Vx::VxTransform vTrans(vMT);
100  Vx::VxReal3 vxRot;
101  vTrans.getRotationEulerAngles(vxRot);
102 
103  CStdFPoint vLocalRot(vxRot[0], vxRot[1], vxRot[2]); //= m_lpThisMI->Rotation();
104 
105  VxVector3 pos((double) vGlobal.x, (double) vGlobal.y, (double) vGlobal.z);
106  VxVector3 axis = NormalizeAxis(vLocalRot);
107 
108  //m_vxSocket = new VxUniversal(lpVsParent->Part(), lpVsChild->Part(), pos.v, VxVector3(1, 0, 0), VxVector3(0, 1, 0));
109  m_vxSocket = new VxHomokinetic(lpVsParent->Part(), lpVsChild->Part(), pos.v, axis.v);
110  m_vxSocket->setName(m_strID.c_str());
111 
112  GetVsSimulator()->Universe()->addConstraint(m_vxSocket);
113 
114  //Disable collisions between this object and its parent
116 
117  m_vxJoint = m_vxSocket;
118  m_iCoordID = -1; //Not used fo
119 }
120 
122 {
123  SetupGraphics();
124  SetupPhysics();
125 }
126 
127 #pragma region DataAccesMethods
128 
129 
130 bool VsUniversal::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
131 {
132  if(VsJoint::Physics_SetData(strDataType, strValue))
133  return true;
134 
135  if(BallSocket::SetData(strDataType, strValue, false))
136  return true;
137 
138  //If it was not one of those above then we have a problem.
139  if(bThrowError)
140  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
141 
142  return false;
143 }
144 
145 void VsUniversal::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
146 {
147  VsJoint::Physics_QueryProperties(aryProperties);
148  BallSocket::QueryProperties(aryProperties);
149 }
150 
151 #pragma endregion
152 
153  } //Joints
154  } // Environment
155 } //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
std::string m_strID
The unique Id for this object.
Definition: AnimatBase.h:55
Declares the vs universal class.
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.
Vx::VxHomokinetic * m_vxSocket
The vortex socket class.
Definition: VsUniversal.h:20
virtual void SetupGraphics()
Sets up the graphics for the joint.
Definition: VsJoint.cpp:248
virtual void CreateJoint()
Creates the joint.
Declares the vortex structure class.