AnimatLab  2
Test
BlCylinder.cpp
1 // BlCylinder.cpp: implementation of the BlCylinder class.
2 //
4 
5 #include "StdAfx.h"
6 #include "BlJoint.h"
7 #include "BlMotorizedJoint.h"
8 #include "BlRigidBody.h"
9 #include "BlCylinder.h"
10 #include "BlSimulator.h"
11 
12 namespace BulletAnimatSim
13 {
14  namespace Environment
15  {
16  namespace Bodies
17  {
18 
20 // Construction/Destruction
22 
23 BlCylinder::BlCylinder()
24 {
25  SetThisPointers();
26 }
27 
28 BlCylinder::~BlCylinder()
29 {
30  try
31  {
32  DeleteGraphics();
33  DeletePhysics(false);
34  }
35  catch(...)
36  {Std_TraceMsg(0, "Caught Error in desctructor of BlCylinder\r\n", "", -1, false, true);}
37 }
38 
39 void BlCylinder::CreateGraphicsGeometry()
40 {
41  m_osgGeometry = CreateConeGeometry(m_fltHeight, m_fltRadius, m_fltRadius, m_iSides, true, true, true);
42 
43  //We need to setup a geometry rotation to make the cylinder graphics geometry match the physics geometry.
44  CStdFPoint vPos(0, 0, 0), vRot(-(osg::PI/2), 0, 0);
45  GeometryRotationMatrix(SetupMatrix(vPos, vRot));
46 }
47 
48 void BlCylinder::CreatePhysicsGeometry()
49 {
50  if(IsCollisionObject())
51  {
52  DeleteCollisionGeometry();
53 
54  CalculateVolumeAndAreas();
55  m_eBodyType = CYLINDER_SHAPE_PROXYTYPE;
56  m_btCollisionShape = new btCylinderShapeZ( btVector3( m_fltRadius, m_fltRadius, (m_fltHeight/2.0f) ) );
57  }
58 }
59 
60 void BlCylinder::CalculateVolumeAndAreas()
61 {
63 
64  m_vArea.x = (2*m_fltRadius)*m_fltHeight;
65  m_vArea.y = (2*m_fltRadius)*m_fltHeight;
66  m_vArea.z = osg::PI * m_fltRadius * m_fltRadius;
67 
68  if(m_fltMass < 0)
69  {
70  float fltMass = m_fltVolume * m_fltDensity;
71  Mass(fltMass, false, false);
72  }
73 }
74 
76 {
77  CreateGeometry();
78 
79  BlRigidBody::CreateItem();
80  Cylinder::CreateParts();
81 }
82 
84 {
87 
88  Cylinder::CreateJoints();
89  BlRigidBody::Initialize();
90 }
91 
92  } //Bodies
93  } // Environment
94 } //BulletAnimatSim
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
int m_iSides
The number of sides used to draw the cylinder.
Definition: Cylinder.h:34
float m_fltMass
The mass of the object.
Definition: RigidBody.h:85
float m_fltVolume
The volume for the rigid body.
Definition: RigidBody.h:91
virtual void CreateJoints()
Allows the rigid body to create its joints using the chosen physics engine.
Definition: BlCylinder.cpp:83
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
float m_fltHeight
The height of the cylinder.
Definition: Cylinder.h:31
virtual void CreateJoint()
Creates the joint.
Definition: Joint.cpp:602
float m_fltDensity
Uniform density for the rigid body.
Definition: RigidBody.h:79
osg::Geometry ANIMAT_OSG_PORT * CreateConeGeometry(float height, float topradius, float botradius, int sides, bool doSide, bool doTop, bool doBottom)
virtual void CreateParts()
Allows the rigid body to create its parts using the chosen physics engine.
Definition: BlCylinder.cpp:75
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.