AnimatLab  2
Test
VsSphere.cpp
1 // VsSphere.cpp: implementation of the VsSphere 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 "VsSphere.h"
12 #include "VsStructure.h"
13 #include "VsSimulator.h"
14 #include "VsOsgUserData.h"
15 #include "VsOsgUserDataVisitor.h"
16 #include "VsDragger.h"
17 
18 namespace VortexAnimatSim
19 {
20  namespace Environment
21  {
22  namespace Bodies
23  {
24 
26 // Construction/Destruction
28 
29 VsSphere::VsSphere()
30 {
31  SetThisPointers();
32 }
33 
34 VsSphere::~VsSphere()
35 {
36  try
37  {
38  DeleteGraphics();
39  DeletePhysics();
40  }
41  catch(...)
42  {Std_TraceMsg(0, "Caught Error in desctructor of VsSphere/\r\n", "", -1, false, true);}
43 }
44 
45 void VsSphere::CreateGraphicsGeometry()
46 {
48 }
49 
50 void VsSphere::CalculateEstimatedMassAndVolume()
51 {
52  float fltVolume = (4/3.0) * osg::PI * m_fltRadius * m_fltRadius * m_fltRadius;
53  m_fltEstimatedVolume = fltVolume*pow(m_lpSim->DistanceUnits(), (float) 3.0);;
55 }
56 
57 void VsSphere::CreatePhysicsGeometry()
58 {
59  if(IsCollisionObject())
60  m_vxGeometry = new VxSphere(m_fltRadius);
61 
62  CalculateEstimatedMassAndVolume();
63 }
64 
66 {
67  CreateGeometry();
68 
69  VsRigidBody::CreateItem();
70  Sphere::CreateParts();
71  VsRigidBody::SetBody();
72 }
73 
75 {
78 
79  Sphere::CreateJoints();
80  VsRigidBody::Initialize();
81 }
82 
83 void VsSphere::ResizePhysicsGeometry()
84 {
85  if(m_vxGeometry)
86  {
87  VxSphere *vxSphere = dynamic_cast<VxSphere *>(m_vxGeometry);
88 
89  if(!vxSphere)
90  THROW_TEXT_ERROR(Vs_Err_lGeometryMismatch, Vs_Err_strGeometryMismatch, m_lpThisAB->Name());
91 
92  vxSphere->setRadius(m_fltRadius);
93 
94  CalculateEstimatedMassAndVolume();
95  }
96 }
97 
98  } //Bodies
99  } // Environment
100 } //VortexAnimatSim
virtual bool IsCollisionObject()
Query if this object is collision object.
Definition: RigidBody.cpp:468
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: VsSphere.cpp:65
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
osg::Geometry * CreateSphereGeometry(int latres, int longres, float radius)
float m_fltRadius
The radius of the sphere.
Definition: Sphere.h:28
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: VsSphere.cpp:74
virtual int LongtitudeSegments()
Gets the longtitude segments.
Definition: Sphere.cpp:127
virtual int LatitudeSegments()
Gets the latitude segments.
Definition: Sphere.cpp:102
Declares the vortex structure class.