AnimatLab  2
Test
VsEllipsoid.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 "VsEllipsoid.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 VsEllipsoid::~VsEllipsoid()
38 {
39  try
40  {
41  DeleteGraphics();
42  DeletePhysics();
43  }
44  catch(...)
45  {Std_TraceMsg(0, "Caught Error in desctructor of VsEllipsoid/\r\n", "", -1, false, true);}
46 }
47 
48 void VsEllipsoid::CreateGraphicsGeometry()
49 {
51 }
52 
53 void VsEllipsoid::CalculateEstimatedMassAndVolume()
54 {
55  float fltVolume = (4/3.0)*osg::PI*m_fltMajorRadius*m_fltMajorRadius*m_fltMinorRadius;
56 
57  m_fltEstimatedVolume = fltVolume*pow(m_lpSim->DistanceUnits(), (float) 3.0);;
59 }
60 
61 void VsEllipsoid::CreatePhysicsGeometry()
62 {
63  if(IsCollisionObject())
64  {
65  //For the moment build a test node to generate the mesh from.
66  osg::ref_ptr<osg::Geometry> osgGeometry = CreateEllipsoidGeometry(m_iLatSegments, m_iLongSegments, m_fltMajorRadius, m_fltMinorRadius);
67  osg::ref_ptr<osg::Geode> osgNode = new osg::Geode;
68  osgNode->addDrawable(m_osgGeometry.get());
69 
70  m_vxGeometry = GetVsSimulator()->CreateConvexMeshFromOsg(osgNode.get());
71  }
72 
73  CalculateEstimatedMassAndVolume();
74 }
75 
77 {
78  CreateGeometry();
79 
80  VsRigidBody::CreateItem();
81  Ellipsoid::CreateParts();
82  VsRigidBody::SetBody();
83 }
84 
86 {
89 
90  Ellipsoid::CreateJoints();
91  VsRigidBody::Initialize();
92 }
93 
94 void VsEllipsoid::ResizePhysicsGeometry()
95 {
96  if(m_vxGeometry && m_vxCollisionGeometry && m_vxSensor)
97  {
98  if(!m_vxSensor->removeCollisionGeometry(m_vxCollisionGeometry))
99  THROW_PARAM_ERROR(Vs_Err_lRemovingCollisionGeometry, Vs_Err_strRemovingCollisionGeometry, "ID: ", m_strID);
100 
101  delete m_vxCollisionGeometry;
102  m_vxCollisionGeometry = NULL;
103 
104  CreatePhysicsGeometry();
105  int iMaterialID = m_lpSim->GetMaterialID(MaterialID());
106  CollisionGeometry(m_vxSensor->addGeometry(m_vxGeometry, iMaterialID, 0, m_lpThisRB->Density()));
107 
108  CalculateEstimatedMassAndVolume();
109  }
110 }
111 
112  } //Bodies
113  } // Environment
114 } //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
float m_fltMinorRadius
The radius of the minor axis of the ellipsoid.
Definition: Ellipsoid.h:31
virtual void CreateJoints()
Allows the rigid body to create its joints using the chosen physics engine.
Definition: VsEllipsoid.cpp:85
float m_fltMajorRadius
The radius of the major axis of the ellipsoid.
Definition: Ellipsoid.h:28
virtual void DistanceUnits(std::string strUnits)
Sets the distance units.
Definition: Simulator.cpp:1717
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
int m_iLatSegments
The number of segments used to draw in the latitude direction.
Definition: Ellipsoid.h:34
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
Declares the vortex ellipsoid class.
osg::Geometry * CreateEllipsoidGeometry(int latres, int longres, float rSemiMajorAxis, float rSemiMinorAxis)
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 CreateParts()
Allows the rigid body to create its parts using the chosen physics engine.
Definition: VsEllipsoid.cpp:76
virtual std::string MaterialID()
Gets the material ID for this part.
Definition: RigidBody.cpp:865
Declares the vortex structure class.
int m_iLongSegments
The number of segments used to draw in the longtitude direction.
Definition: Ellipsoid.h:37