AnimatLab  2
Test
VsCone.cpp
1 // VsCone.cpp: implementation of the VsCone class.
2 //
4 
5 #include "StdAfx.h"
6 #include "VsMovableItem.h"
7 #include "VsBody.h"
8 #include "VsJoint.h"
9 #include "VsRigidBody.h"
10 #include "VsCone.h"
11 #include "VsStructure.h"
12 #include "VsSimulator.h"
13 #include "VsOsgUserData.h"
14 #include "VsOsgUserDataVisitor.h"
15 #include "VsDragger.h"
16 
17 namespace VortexAnimatSim
18 {
19  namespace Environment
20  {
21  namespace Bodies
22  {
23 
25 // Construction/Destruction
27 
28 VsCone::VsCone()
29 {
30  SetThisPointers();
31 }
32 
33 VsCone::~VsCone()
34 {
35  try
36  {
37  DeleteGraphics();
38  DeletePhysics();
39  }
40  catch(...)
41  {Std_TraceMsg(0, "Caught Error in desctructor of VsCone\r\n", "", -1, false, true);}
42 }
43 
44 void VsCone::CalculateEstimatedMassAndVolume()
45 {
47  m_fltEstimatedVolume = fltVolume*pow(m_lpSim->DistanceUnits(), (float) 3.0);;
49 }
50 
51 void VsCone::CreateGraphicsGeometry()
52 {
53  m_osgGeometry = CreateConeGeometry(m_fltHeight, m_fltUpperRadius, m_fltLowerRadius, m_iSides, true, true, true);
54 }
55 
56 void VsCone::CreatePhysicsGeometry()
57 {
58  if(IsCollisionObject())
59  {
60  //For the moment build a test node to generate the mesh from.
61  osg::ref_ptr<osg::Geometry> osgGeometry = CreateConeGeometry(m_fltHeight, m_fltUpperRadius, m_fltLowerRadius, m_iSides, true, true, true);
62  osg::ref_ptr<osg::Geode> osgNode = new osg::Geode;
63  osgNode->addDrawable(m_osgGeometry.get());
64 
65  m_vxGeometry = VxConvexMesh::createFromNode(osgNode.get());
66  }
67 
68  CalculateEstimatedMassAndVolume();
69 }
70 
72 {
73  CreateGeometry();
74 
75  VsRigidBody::CreateItem();
76  Cone::CreateParts();
77  VsRigidBody::SetBody();
78 }
79 
81 {
84 
85  Cone::CreateJoints();
86  VsRigidBody::Initialize();
87 }
88 
89 void VsCone::ResizePhysicsGeometry()
90 {
91  if(m_vxGeometry && m_vxCollisionGeometry && m_vxSensor)
92  {
93  if(!m_vxSensor->removeCollisionGeometry(m_vxCollisionGeometry))
94  THROW_PARAM_ERROR(Vs_Err_lRemovingCollisionGeometry, Vs_Err_strRemovingCollisionGeometry, "ID: ", m_strID);
95 
96  delete m_vxCollisionGeometry;
97  m_vxCollisionGeometry = NULL;
98 
99  CreatePhysicsGeometry();
100  int iMaterialID = m_lpSim->GetMaterialID(MaterialID());
101  CollisionGeometry(m_vxSensor->addGeometry(m_vxGeometry, iMaterialID, 0, m_lpThisRB->Density()));
102 
103  CalculateEstimatedMassAndVolume();
104  }
105 }
106 
107  } //Bodies
108  } // Environment
109 } //VortexAnimatSim
virtual bool IsCollisionObject()
Query if this object is collision object.
Definition: RigidBody.cpp:468
float m_fltLowerRadius
The lower radius of the cone.
Definition: Cone.h:28
int m_iSides
The number of sides used to draw the cone.
Definition: Cone.h:37
float m_fltEstimatedVolume
The estimated volume. See m_fltEstimatedMass desciption.
Definition: VsRigidBody.h:92
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
virtual void CreateParts()
Allows the rigid body to create its parts using the chosen physics engine.
Definition: VsCone.cpp:71
osg::Geometry * CreateConeGeometry(float height, float topradius, float botradius, int sides, bool doSide, bool doTop, bool doBottom)
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
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
float m_fltHeight
The height of the cone.
Definition: Cone.h:34
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: VsCone.cpp:80
virtual std::string MaterialID()
Gets the material ID for this part.
Definition: RigidBody.cpp:865
float m_fltUpperRadius
The upper radius of the cone.
Definition: Cone.h:31
Declares the vortex structure class.