AnimatLab  2
Test
BlPlane.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 #include "BlJoint.h"
9 #include "BlMotorizedJoint.h"
10 #include "BlRigidBody.h"
11 #include "BlPlane.h"
12 #include "BlSimulator.h"
13 
14 namespace BulletAnimatSim
15 {
16  namespace Environment
17  {
18  namespace Bodies
19  {
20 
28 {
29  SetThisPointers();
30  m_bCullBackfaces = true; //we want back face culling on by default for planes.
31 }
32 
40 {
41  try
42  {
43  DeleteGraphics();
44  DeletePhysics(false);
45  }
46  catch(...)
47  {Std_TraceMsg(0, "Caught Error in desctructor of BlPlane/\r\n", "", -1, false, true);}
48 }
49 
50 void BlPlane::CreateGraphicsGeometry()
51 {
52  m_osgGeometry = CreatePlaneGeometry(CornerX(), CornerY(), m_ptSize.x, m_ptSize.y, GridX(), GridY(), false);
53 }
54 
55 void BlPlane::CreatePhysicsGeometry()
56 {
57  if(IsCollisionObject())
58  {
59  DeleteCollisionGeometry();
60 
61  m_fltMass = 0; //Plane is always a static object.
62 
63  if(m_osgMT.valid())
64  OsgMovableItem::UpdatePositionAndRotationFromMatrix(m_osgMT->getMatrix());
65 
66  CStdFPoint vPos = m_lpStructure->Position();
67  m_eBodyType = STATIC_PLANE_PROXYTYPE;
68  m_btCollisionShape = new btStaticPlaneShape(btVector3(0,1,0), vPos.y);
69  }
70 }
71 
73 {
74  CreateGeometry();
75 
76  //Create the geometry and osg drawable nodes.
77  m_eControlType = DynamicsControlType::ControlNode; //This is not a dynamic part.
78 
79  BlRigidBody::CreateItem();
80  Plane::CreateParts();
81 }
82 
83 void BlPlane::CreateDynamicPart()
84 {
85  BlSimulator *lpSim = GetBlSimulator();
86 
87  if(lpSim && m_lpThisRB && m_lpThisAB)
88  {
89  //m_btCollisionShape = new btStaticPlaneShape(btVector3(0,1,0), 1);
90  btRigidBody::btRigidBodyConstructionInfo rbInfo( 0., NULL, m_btCollisionShape, btVector3(0,0,0) );
91 
92  rbInfo.m_friction = m_lpMaterial->FrictionLinearPrimary();
93  rbInfo.m_rollingFriction = m_lpMaterial->FrictionAngularPrimaryConverted();
94  rbInfo.m_restitution = m_lpMaterial->Restitution();
95  rbInfo.m_linearDamping = m_lpThisRB->LinearVelocityDamping();
96  rbInfo.m_angularDamping = m_lpThisRB->AngularVelocityDamping();
97 
98  m_btPart = new btRigidBody(rbInfo);
99 
100  if(!m_lpBulletData)
101  m_lpBulletData = new BlBulletData(this, false);
102  m_btPart->setUserPointer((void *) m_lpBulletData);
103 
104  lpSim->DynamicsWorld()->addRigidBody( m_btPart, AnimatCollisionTypes::RIGID_BODY, ALL_COLLISIONS );
105 
106  m_osgbMotion = dynamic_cast<osgbDynamics::MotionState *>(m_btPart->getMotionState());
107  }
108 }
109 
110 //
111 //void BlPlane::ResizePhysicsGeometry()
112 //{
113 //}
114 
115 //Planes can never have fluid interactions/dynamics.
116 void BlPlane::Physics_FluidDataChanged()
117 {}
118 
119  } //Bodies
120  } // Environment
121 } //BulletAnimatSim
Declares the vortex plane class.
virtual float FrictionAngularPrimaryConverted()
Gets the angular primary friction coefficient converted to match vortex values.
virtual void CreateParts()
Allows the rigid body to create its parts using the chosen physics engine.
Definition: BlPlane.cpp:72
virtual bool IsCollisionObject()
Query if this object is collision object.
Definition: RigidBody.cpp:468
virtual float GridY()
Gets the length of a segment for the y dimension of the plane.
Definition: Plane.cpp:118
float m_fltMass
The mass of the object.
Definition: RigidBody.h:85
virtual float CornerX()
Gets the corner x coordinate.
Definition: Plane.cpp:78
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
AnimatSim::Environment::Structure * m_lpStructure
The pointer to this items parent Structure. If this is not relevant for this object then this is NULL...
Definition: AnimatBase.h:46
virtual float GridX()
Gets the width of a segment for the x dimension of the plane.
Definition: Plane.cpp:104
virtual CStdFPoint Position()
Gets the local position. (m_oPosition)
Definition: Structure.cpp:118
virtual float Restitution()
Gets the restitution for collisions between RigidBodies with these two materials. ...
virtual float FrictionLinearPrimary()
Gets the primary friction coefficient.
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.
BlMaterialType * m_lpMaterial
The pointer to the material for this body.
Definition: BlRigidBody.h:131
virtual float CornerY()
Gets the corner y coordinate.
Definition: Plane.cpp:90