AnimatLab  2
Test
VsTorus.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 "VsRigidBody.h"
12 #include "VsTorus.h"
13 #include "VsStructure.h"
14 #include "VsSimulator.h"
15 #include "VsOsgUserData.h"
16 #include "VsOsgUserDataVisitor.h"
17 #include "VsDragger.h"
18 
19 namespace VortexAnimatSim
20 {
21  namespace Environment
22  {
23  namespace Bodies
24  {
25 
33 {
34  SetThisPointers();
35 }
36 
37 VsTorus::~VsTorus()
38 {
39  try
40  {
41  DeleteGraphics();
42  DeletePhysics();
43  }
44  catch(...)
45  {Std_TraceMsg(0, "Caught Error in desctructor of VsTorus/\r\n", "", -1, false, true);}
46 }
47 
48 void VsTorus::CreateGraphicsGeometry()
49 {
50  m_osgGeometry = CreateTorusGeometry(m_fltInsideRadius, m_fltOutsideRadius, m_iSides, m_iRings);
51 }
52 
53 void VsTorus::CreatePhysicsGeometry()
54 {
55  if(IsCollisionObject())
56  {
57  //For the moment build a test node to generate the mesh from.
58  osg::ref_ptr<osg::Geometry> osgGeometry = CreateTorusGeometry(m_fltInsideRadius, m_fltOutsideRadius, m_iSides, m_iRings);
59  osg::ref_ptr<osg::Geode> osgNode = new osg::Geode;
60  osgNode->addDrawable(m_osgGeometry.get());
61 
62  m_vxGeometry = GetVsSimulator()->CreatTriangleMeshFromOsg(osgNode.get());
63  }
64 }
65 
67 {
68  CreateGeometry();
69 
70  VsRigidBody::CreateItem();
71  Torus::CreateParts();
72  VsRigidBody::SetBody();
73 }
74 
76 {
79 
80  Torus::CreateJoints();
81  VsRigidBody::Initialize();
82 }
83 
84 void VsTorus::ResizePhysicsGeometry()
85 {
86  if(m_vxGeometry && m_vxCollisionGeometry && m_vxSensor)
87  {
88  if(!m_vxSensor->removeCollisionGeometry(m_vxCollisionGeometry))
89  THROW_PARAM_ERROR(Vs_Err_lRemovingCollisionGeometry, Vs_Err_strRemovingCollisionGeometry, "ID: ", m_strID);
90 
91  delete m_vxCollisionGeometry;
92  m_vxCollisionGeometry = NULL;
93 
94  CreatePhysicsGeometry();
95  int iMaterialID = m_lpSim->GetMaterialID(MaterialID());
96  CollisionGeometry(m_vxSensor->addGeometry(m_vxGeometry, iMaterialID, 0, m_lpThisRB->Density()));
97  }
98 }
99 
100  } //Bodies
101  } // Environment
102 } //VortexAnimatSim
virtual void CreateParts()
Allows the rigid body to create its parts using the chosen physics engine.
Definition: VsTorus.cpp:66
virtual bool IsCollisionObject()
Query if this object is collision object.
Definition: RigidBody.cpp:468
Declares the vortex Torus class.
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
float m_fltInsideRadius
The inside radius of the torus.
Definition: Torus.h:31
int m_iRings
The number of rings used to draw the torus.
Definition: Torus.h:37
virtual void CreateJoint()
Creates the joint.
Definition: Joint.cpp:602
std::string m_strID
The unique Id for this object.
Definition: AnimatBase.h:55
virtual int GetMaterialID(std::string strID)
Gets a material identifier from the physics engine for the specified unique ID.
Definition: Simulator.cpp:1434
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.
float m_fltOutsideRadius
The outside radius of the torus.
Definition: Torus.h:28
int m_iSides
The number of sides used to draw the torus.
Definition: Torus.h:34
virtual void CreateJoints()
Allows the rigid body to create its joints using the chosen physics engine.
Definition: VsTorus.cpp:75
virtual std::string MaterialID()
Gets the material ID for this part.
Definition: RigidBody.cpp:865
Declares the vortex structure class.