AnimatLab  2
Test
BlCone.cpp
1 // BlCone.cpp: implementation of the BlCone class.
2 //
4 
5 #include "StdAfx.h"
6 #include "BlOsgGeometry.h"
7 #include "BlJoint.h"
8 #include "BlRigidBody.h"
9 #include "BlCone.h"
10 #include "BlSimulator.h"
11 
12 namespace BulletAnimatSim
13 {
14  namespace Environment
15  {
16  namespace Bodies
17  {
18 
20 // Construction/Destruction
22 
23 BlCone::BlCone()
24 {
25  SetThisPointers();
26 }
27 
28 BlCone::~BlCone()
29 {
30  try
31  {
32  DeleteGraphics();
33  DeletePhysics(false);
34  }
35  catch(...)
36  {Std_TraceMsg(0, "Caught Error in desctructor of BlCone\r\n", "", -1, false, true);}
37 }
38 
39 void BlCone::CreateGraphicsGeometry()
40 {
41  m_osgGeometry = CreateConeGeometry(m_fltHeight, m_fltUpperRadius, m_fltLowerRadius, m_iSides, true, true, true);
42 }
43 
44 void BlCone::CreatePhysicsGeometry()
45 {
46  if(IsCollisionObject())
47  {
48  DeleteCollisionGeometry();
49 
50  CalculateVolumeAndAreas();
51 
52  m_eBodyType = CONVEX_HULL_SHAPE_PROXYTYPE;
53  btConvexHullShape *btHull = OsgMeshToConvexHull(m_osgNode.get(), true, -1);
54  m_btCollisionShape = btHull;
55  //m_bDisplayDebugCollisionGraphic = false;
56  }
57 }
58 
59 void BlCone::CalculateVolumeAndAreas()
60 {
62 
63  //First get the large and small radius
64  float fltLargeDiam = 2*STD_MAX(m_fltLowerRadius, m_fltUpperRadius);
65  float fltSmallDiam = 2*STD_MIN(m_fltLowerRadius, m_fltUpperRadius);
66 
67  //Now get the side profile area by geting the area of the rectangle of the two radii, and then subtracting 2 traingles from the large radius to small radius.
68  float fltProfileRect = fltLargeDiam * m_fltHeight;
69  float fltTriHeight = (fltLargeDiam - fltSmallDiam) / 2.0;
70  float fltTriBase = m_fltHeight;
71  float fltProfileTriangle = 0.5f * fltTriBase * fltTriHeight;
72 
73  float fltProfileArea = fltProfileRect - (2*fltProfileRect);
74 
75  m_vArea.x = fltProfileArea;
76  m_vArea.y = fltProfileArea;
77  m_vArea.z = 2*osg::PI*fltLargeDiam*fltSmallDiam;
78 
79  if(m_fltMass < 0)
80  {
81  float fltMass = m_fltVolume * m_fltDensity;
82  Mass(fltMass, false, false);
83  }
84 }
85 
87 {
88  CreateGeometry();
89 
90  BlRigidBody::CreateItem();
91  Cone::CreateParts();
92 }
93 
95 {
98 
99  Cone::CreateJoints();
100  BlRigidBody::Initialize();
101 }
102 
103 
104  } //Bodies
105  } // Environment
106 } //BulletAnimatSim
virtual void CreateParts()
Allows the rigid body to create its parts using the chosen physics engine.
Definition: BlCone.cpp:86
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_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: BlCone.cpp:94
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
virtual void CreateJoint()
Creates the joint.
Definition: Joint.cpp:602
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
osg::Geometry ANIMAT_OSG_PORT * CreateConeGeometry(float height, float topradius, float botradius, int sides, bool doSide, bool doTop, bool doBottom)
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.
float m_fltUpperRadius
The upper radius of the cone.
Definition: Cone.h:31