AnimatLab  2
Test
VsCylinder.cpp
1 // VsCylinder.cpp: implementation of the VsCylinder class.
2 //
4 
5 #include "StdAfx.h"
6 #include "VsMovableItem.h"
7 #include "VsBody.h"
8 #include "VsJoint.h"
9 #include "VsMotorizedJoint.h"
10 #include "VsRigidBody.h"
11 #include "VsCylinder.h"
12 #include "VsSimulator.h"
13 #include "VsDragger.h"
14 
15 namespace VortexAnimatSim
16 {
17  namespace Environment
18  {
19  namespace Bodies
20  {
21 
23 // Construction/Destruction
25 
26 VsCylinder::VsCylinder()
27 {
28  SetThisPointers();
29 }
30 
31 VsCylinder::~VsCylinder()
32 {
33  try
34  {
35  DeleteGraphics();
36  DeletePhysics();
37  }
38  catch(...)
39  {Std_TraceMsg(0, "Caught Error in desctructor of VsCylinder\r\n", "", -1, false, true);}
40 }
41 
42 void VsCylinder::CreateGraphicsGeometry()
43 {
44  m_osgGeometry = CreateConeGeometry(m_fltHeight, m_fltRadius, m_fltRadius, m_iSides, true, true, true);
45 
46  //We need to setup a geometry rotation to make the cylinder graphics geometry match the physics geometry.
47  CStdFPoint vPos(0, 0, 0), vRot(-(osg::PI/2), 0, 0);
48  GeometryRotationMatrix(SetupMatrix(vPos, vRot));
49 }
50 
51 void VsCylinder::CalculateEstimatedMassAndVolume()
52 {
53  float fltVolume = osg::PI * m_fltRadius * m_fltRadius * m_fltHeight;
54 
55  m_fltEstimatedVolume = fltVolume*pow(m_lpSim->DistanceUnits(), (float) 3.0);;
57 }
58 
59 void VsCylinder::CreatePhysicsGeometry()
60 {
61  if(IsCollisionObject())
62  m_vxGeometry = new VxCylinder(m_fltRadius, m_fltHeight);
63 
64  CalculateEstimatedMassAndVolume();
65 }
66 
68 {
69  CreateGeometry();
70 
71  VsRigidBody::CreateItem();
72  Cylinder::CreateParts();
73  VsRigidBody::SetBody();
74 }
75 
77 {
80 
81  Cylinder::CreateJoints();
82  VsRigidBody::Initialize();
83 }
84 
85 void VsCylinder::ResizePhysicsGeometry()
86 {
87  if(m_vxGeometry)
88  {
89  VxCylinder *vxCylinder = dynamic_cast<VxCylinder *>(m_vxGeometry);
90 
91  if(!vxCylinder)
92  THROW_TEXT_ERROR(Vs_Err_lGeometryMismatch, Vs_Err_strGeometryMismatch, m_lpThisAB->Name());
93 
94  vxCylinder->setRadius(m_fltRadius);
95  vxCylinder->setHeight(m_fltHeight);
96 
97  CalculateEstimatedMassAndVolume();
98  }
99 }
100 
101  } //Bodies
102  } // Environment
103 } //VortexAnimatSim
virtual bool IsCollisionObject()
Query if this object is collision object.
Definition: RigidBody.cpp:468
float m_fltRadius
The radius of the cylinder.
Definition: Cylinder.h:28
float m_fltEstimatedVolume
The estimated volume. See m_fltEstimatedMass desciption.
Definition: VsRigidBody.h:92
int m_iSides
The number of sides used to draw the cylinder.
Definition: Cylinder.h:34
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
virtual void DistanceUnits(std::string strUnits)
Sets the distance units.
Definition: Simulator.cpp:1717
osg::Geometry * CreateConeGeometry(float height, float topradius, float botradius, int sides, bool doSide, bool doTop, bool doBottom)
float m_fltHeight
The height of the cylinder.
Definition: Cylinder.h:31
virtual void CreateJoint()
Creates the joint.
Definition: Joint.cpp:602
virtual float DisplayMassUnits()
Gets the density mass units.
Definition: Simulator.cpp:1810
float m_fltDensity
Uniform density for the rigid body.
Definition: RigidBody.h:79
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 CreateJoints()
Allows the rigid body to create its joints using the chosen physics engine.
Definition: VsCylinder.cpp:76
virtual void CreateParts()
Allows the rigid body to create its parts using the chosen physics engine.
Definition: VsCylinder.cpp:67