AnimatLab  2
Test
VsDistanceJoint.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 "VsDistanceJoint.h"
20 
21 namespace VortexAnimatSim
22 {
23  namespace Environment
24  {
25  namespace Joints
26  {
27 
35 {
36  SetThisPointers();
37  m_vxDistance = NULL;
38 }
39 
47 {
48  try
49  {
50  DeleteGraphics();
51  DeletePhysics();
52  }
53  catch(...)
54  {Std_TraceMsg(0, "Caught Error in desctructor of VsDistanceJoint/\r\n", "", -1, false, true);}
55 }
56 
66 {
67 }
68 
69 void VsDistanceJoint::DeletePhysics()
70 {
71  if(!m_vxDistance)
72  return;
73 
74  if(GetVsSimulator() && GetVsSimulator()->Universe())
75  {
76  GetVsSimulator()->Universe()->removeConstraint(m_vxDistance);
77  delete m_vxDistance;
78 
79  if(m_lpChild && m_lpParent)
81  }
82 
83  m_vxDistance = NULL;
84  m_vxJoint = NULL;
85 }
86 
87 void VsDistanceJoint::SetupPhysics()
88 {
89  if(m_vxDistance)
90  DeletePhysics();
91 
92  if(!m_lpParent)
93  THROW_ERROR(Al_Err_lParentNotDefined, Al_Err_strParentNotDefined);
94 
95  if(!m_lpChild)
96  THROW_ERROR(Al_Err_lChildNotDefined, Al_Err_strChildNotDefined);
97 
98  VsRigidBody *lpVsParent = dynamic_cast<VsRigidBody *>(m_lpParent);
99  if(!lpVsParent)
100  THROW_ERROR(Vs_Err_lUnableToConvertToVsRigidBody, Vs_Err_strUnableToConvertToVsRigidBody);
101 
102  VsRigidBody *lpVsChild = dynamic_cast<VsRigidBody *>(m_lpChild);
103  if(!lpVsChild)
104  THROW_ERROR(Vs_Err_lUnableToConvertToVsRigidBody, Vs_Err_strUnableToConvertToVsRigidBody);
105 
107 
108  m_vxDistance = new VxDistanceJoint(lpVsParent->Part(), lpVsChild->Part(), fltDistance);
109  m_vxDistance->setName(m_strID.c_str());
110 
111  GetVsSimulator()->Universe()->addConstraint(m_vxDistance);
112 
113  //Disable collisions between this object and its parent
115 
116  m_vxJoint = m_vxDistance;
117  m_iCoordID = -1; //Not used fo
118 }
119 
121 {
122  SetupGraphics();
123  SetupPhysics();
124 }
125 
126 #pragma region DataAccesMethods
127 
128 
129 bool VsDistanceJoint::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
130 {
131  if(VsJoint::Physics_SetData(strDataType, strValue))
132  return true;
133 
134  if(Joint::SetData(strDataType, strValue, false))
135  return true;
136 
137  //If it was not one of those above then we have a problem.
138  if(bThrowError)
139  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
140 
141  return false;
142 }
143 
144 void VsDistanceJoint::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
145 {
146  VsJoint::Physics_QueryProperties(aryProperties);
147  Joint::QueryProperties(aryProperties);
148 }
149 
150 #pragma endregion
151 
152  } //Joints
153  } // Environment
154 } //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
virtual void SetupGraphics()
Sets up the graphics for the joint.
virtual CStdFPoint AbsolutePosition()
Gets the absolute position of this body part.
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.
Declares the vortex distance joint class.
Vx::VxDistanceJoint * m_vxDistance
The vortex socket class.
double Std_CalculateDistance(CStdIPoint &ptA, CStdIPoint &ptB)
Calculates the distance between two points.
Declares the vortex structure class.