AnimatLab  2
Test
BlSphere.cpp
1 // BlSphere.cpp: implementation of the BlSphere class.
2 //
4 
5 #include "StdAfx.h"
6 #include "BlJoint.h"
7 #include "BlMotorizedJoint.h"
8 #include "BlRigidBody.h"
9 #include "BlSphere.h"
10 #include "BlSimulator.h"
11 
12 namespace BulletAnimatSim
13 {
14  namespace Environment
15  {
16  namespace Bodies
17  {
18 
20 // Construction/Destruction
22 
23 BlSphere::BlSphere()
24 {
25  SetThisPointers();
26 }
27 
28 BlSphere::~BlSphere()
29 {
30  try
31  {
32  DeleteGraphics();
33  DeletePhysics(false);
34  }
35  catch(...)
36  {Std_TraceMsg(0, "Caught Error in desctructor of BlSphere/\r\n", "", -1, false, true);}
37 }
38 
39 void BlSphere::CreateGraphicsGeometry()
40 {
42 }
43 
44 void BlSphere::CreatePhysicsGeometry()
45 {
46  if(IsCollisionObject())
47  {
48  DeleteCollisionGeometry();
49 
50  CalculateVolumeAndAreas();
51  m_eBodyType = SPHERE_SHAPE_PROXYTYPE;
52  m_btCollisionShape = new btSphereShape( m_fltRadius );
53  }
54 }
55 
56 void BlSphere::CalculateVolumeAndAreas()
57 {
58  m_fltVolume = (4/3.0) * osg::PI * m_fltRadius * m_fltRadius * m_fltRadius;
59  m_vArea.x = m_vArea.y = m_vArea.z = osg::PI * m_fltRadius * m_fltRadius;
60 
61  if(m_fltMass < 0)
62  {
63  float fltMass = m_fltVolume * m_fltDensity;
64  Mass(fltMass, false, false);
65  }
66 }
67 
69 {
70  CreateGeometry();
71 
72  BlRigidBody::CreateItem();
73  Sphere::CreateParts();
74 }
75 
77 {
80 
81  Sphere::CreateJoints();
82  BlRigidBody::Initialize();
83 }
84 
85  } //Bodies
86  } // Environment
87 } //BulletAnimatSim
virtual bool IsCollisionObject()
Query if this object is collision object.
Definition: RigidBody.cpp:468
virtual void CreateJoints()
Allows the rigid body to create its joints using the chosen physics engine.
Definition: BlSphere.cpp:76
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
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_fltRadius
The radius of the sphere.
Definition: Sphere.h:28
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: BlSphere.cpp:68
virtual int LongtitudeSegments()
Gets the longtitude segments.
Definition: Sphere.cpp:127
virtual int LatitudeSegments()
Gets the latitude segments.
Definition: Sphere.cpp:102
osg::Geometry ANIMAT_OSG_PORT * CreateSphereGeometry(int latres, int longres, float radius)