AnimatLab  2
Test
VsRPRO.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 "VsRPRO.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 VsRPRO\r\n", "", -1, false, true);}
52 }
53 
54 void VsRPRO::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 VsRPRO::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 
97  VxVector3 vPos((double) vGlobal.x, (double) vGlobal.y, (double) vGlobal.z);
98 
99  m_vxSocket = new VxRPRO();
100  m_vxSocket->setName(m_strID.c_str());
101  m_vxSocket->setParts(lpVsParent->Part(), lpVsChild->Part());
102  m_vxSocket->setPosition(vPos);
103 
104  VxReal3 aryStrength;
105  aryStrength[0] = aryStrength[1] = aryStrength[2] = VX_INFINITY;
106 
107  Vx::VxQuaternion q;
108  m_vxSocket->setRelativeQuaternionFromPart();
109 
110  m_vxSocket->setLinearStrength(aryStrength);
111  m_vxSocket->setAngularStrength(aryStrength);
112 
113  GetVsSimulator()->Universe()->addConstraint(m_vxSocket);
114 
115  //Disable collisions between this object and its parent
117 
118  m_vxJoint = m_vxSocket;
119  m_iCoordID = -1; //Not used fo
120 }
121 
123 {
124  SetupGraphics();
125  SetupPhysics();
126 }
127 
128 #pragma region DataAccesMethods
129 
130 bool VsRPRO::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(RPRO::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 VsRPRO::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
146 {
147  VsJoint::Physics_QueryProperties(aryProperties);
148  RPRO::QueryProperties(aryProperties);
149 }
150 
151 #pragma endregion
152 
153  } //Joints
154  } // Environment
155 } //VortexAnimatSim
virtual void CreateJoint()
Creates the joint.
Definition: VsRPRO.cpp:122
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
Declares the vortex relative position, relative orientation class.
Vx::VxRPRO * m_vxSocket
The vortex socket class.
Definition: VsRPRO.h:27
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