AnimatLab  2
Test
BlBox.cpp
1 // BlBox.cpp: implementation of the BlBox class.
2 //
4 
5 #include "StdAfx.h"
6 #include "BlJoint.h"
7 #include "BlMotorizedJoint.h"
8 #include "BlRigidBody.h"
9 #include "BlBox.h"
10 #include "BlSimulator.h"
11 
12 namespace BulletAnimatSim
13 {
14  namespace Environment
15  {
16  namespace Bodies
17  {
18 
20 // Construction/Destruction
22 
23 BlBox::BlBox()
24 {
25  SetThisPointers();
26 }
27 
28 BlBox::~BlBox()
29 {
30  try
31  {
32  DeleteGraphics();
33  DeletePhysics(false);
34  }
35  catch(...)
36  {Std_TraceMsg(0, "Caught Error in desctructor of BlBox\r\n", "", -1, false, true);}
37 }
38 
39 void BlBox::CreateGraphicsGeometry()
40 {
41  m_osgGeometry = CreateBoxGeometry(Length(), Height(), Width(), LengthSegmentSize(), HeightSegmentSize(), WidthSegmentSize());
42 }
43 
44 void BlBox::CreatePhysicsGeometry()
45 {
47  //int i=5;
48  //if(Std_ToLower(m_strID) == "b42f968f-0639-4a69-9974-9e0f411d40d8") // && m_lpSim->Time() > 1.8
49  // i=6;
50 
51  if(IsCollisionObject())
52  {
53  DeleteCollisionGeometry();
54 
55  CalculateVolumeAndAreas();
56  m_eBodyType = BOX_SHAPE_PROXYTYPE;
57  m_btCollisionShape = new btBoxShape( btVector3( (m_fltLength/2.0f), (m_fltHeight/2.0f), (m_fltWidth/2.0f) ) );
58  }
59 }
60 
61 void BlBox::CalculateVolumeAndAreas()
62 {
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  Box::CreateParts();
81 }
82 
84 {
87 
88  Box::CreateJoints();
89  BlRigidBody::Initialize();
90 }
91 
92 
93  } //Bodies
94  } // Environment
95 } //BulletAnimatSim
virtual void CreateParts()
Allows the rigid body to create its parts using the chosen physics engine.
Definition: BlBox.cpp:75
virtual bool IsCollisionObject()
Query if this object is collision object.
Definition: RigidBody.cpp:468
virtual float WidthSegmentSize()
Gets the width segment size.
Definition: Box.cpp:204
float m_fltMass
The mass of the object.
Definition: RigidBody.h:85
virtual void CreateJoints()
Allows the rigid body to create its joints using the chosen physics engine.
Definition: BlBox.cpp:83
float m_fltVolume
The volume for the rigid body.
Definition: RigidBody.h:91
virtual float Width()
Gets the width of the box.
Definition: Box.cpp:82
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
virtual void CreateJoint()
Creates the joint.
Definition: Joint.cpp:602
float m_fltLength
The length dimension of the box.
Definition: Box.h:46
float m_fltDensity
Uniform density for the rigid body.
Definition: RigidBody.h:79
virtual float Length()
Gets the length of the box.
Definition: Box.cpp:69
virtual float LengthSegmentSize()
Gets the length segment size.
Definition: Box.cpp:194
float m_fltWidth
The width dimension of the box.
Definition: Box.h:52
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_fltHeight
The height dimension of the box.
Definition: Box.h:58
virtual float HeightSegmentSize()
Gets the height segment size.
Definition: Box.cpp:214
virtual float Height()
Gets the height of the box.
Definition: Box.cpp:95