AnimatLab  2
Test
BlAnimatCollisionDispatcher.cpp
1 // BlAnimatCollisionDispatcher.cpp: implementation of the BlAnimatCollisionDispatcher class.
2 //
4 
5 #include "StdAfx.h"
6 #include "BlJoint.h"
7 #include "BlRigidBody.h"
8 #include "BlSimulator.h"
9 
10 namespace BulletAnimatSim
11 {
12 
14 // Construction/Destruction
16 
17 BlAnimatCollisionDispatcher::BlAnimatCollisionDispatcher(btCollisionConfiguration* collisionConfiguration, BlSimulator *lpSim) :
18  btCollisionDispatcher(collisionConfiguration),
19  m_lpSim(lpSim)
20 {
21  //setNearCallback(AnimatNearCallback);
22 }
23 
24 BlAnimatCollisionDispatcher::~BlAnimatCollisionDispatcher()
25 {
26 
27 try
28 {
29  m_lpSim = NULL;
30 }
31 catch(...)
32 {Std_TraceMsg(0, "Caught Error in desctructor of BlAnimatCollisionDispatcher\r\n", "", -1, false, true);}
33 }
34 
35 bool BlAnimatCollisionDispatcher::needsCollision(const btCollisionObject* body0, const btCollisionObject* body1)
36 {
37  btAssert(body0);
38  btAssert(body1);
39 
40 #ifdef BT_DEBUG
41  if (!(m_dispatcherFlags & btCollisionDispatcher::CD_STATIC_STATIC_REPORTED))
42  {
43  //broadphase filtering already deals with this
44  if (body0->isStaticOrKinematicObject() && body1->isStaticOrKinematicObject())
45  {
46  m_dispatcherFlags |= btCollisionDispatcher::CD_STATIC_STATIC_REPORTED;
47  printf("warning btCollisionDispatcher::needsCollision: static-static collision!\n");
48  }
49  }
50 #endif //BT_DEBUG
51 
52  if ((!body0->isActive()) && (!body1->isActive()))
53  return false;
54  else if (!body0->checkCollideWith(body1))
55  return false;
56 
57  BlBulletData *lpData1 = (BlBulletData *) body0->getUserPointer();
58  BlBulletData *lpData2 = (BlBulletData *) body1->getUserPointer();
59 
60  if(lpData1 && lpData2)
61  {
63  //if(lpData1->m_bExclusionProcessing || lpData2->m_bExclusionProcessing)
64  // lpData1 = lpData1;
65 
66  if(lpData1->m_bExclusionProcessing && lpData1->m_lpBody && lpData2->m_lpBody && !lpData1->m_lpBody->NeedCollision(lpData2->m_lpBody))
67  return false;
68 
69  if(lpData2->m_bExclusionProcessing && lpData2->m_lpBody && lpData1->m_lpBody && !lpData2->m_lpBody->NeedCollision(lpData1->m_lpBody))
70  return false;
71  }
72 
73  return true ;
74 
75 }
76 //
77 //bool BlAnimatCollisionDispatcher::IsContactObject(btCollisionObject* body0, btCollisionObject* body1)
78 //{
79 // if( ((body0->getCollisionFlags() & AnimatCollisionTypes::CONTACT_SENSOR) || (body1->getCollisionFlags() & AnimatCollisionTypes::CONTACT_SENSOR)) ||
80 // ((body0->getCollisionFlags() & AnimatCollisionTypes::RECEPTIVE_FIELD_SENSOR) || (body1->getCollisionFlags() & AnimatCollisionTypes::RECEPTIVE_FIELD_SENSOR)) )
81 // return true;
82 //
83 // return false;
84 //}
85 //
86 //
88 //void BlAnimatCollisionDispatcher::AnimatNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo)
89 //{
90 // btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
91 // btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;
92 //
93 // if (dispatcher.needsCollision(colObj0,colObj1))
94 // {
95 // //dispatcher will keep algorithms persistent in the collision pair
96 // if (!collisionPair.m_algorithm)
97 // {
98 // collisionPair.m_algorithm = dispatcher.findAlgorithm(colObj0,colObj1);
99 // }
100 //
101 // if (collisionPair.m_algorithm)
102 // {
103 // btManifoldResult contactPointResult(colObj0,colObj1);
104 //
105 // if (dispatchInfo.m_dispatchFunc == btDispatcherInfo::DISPATCH_DISCRETE)
106 // {
107 // //discrete collision detection query
108 // collisionPair.m_algorithm->processCollision(colObj0,colObj1,dispatchInfo,&contactPointResult);
109 // } else
110 // {
111 // //continuous collision detection query, time of impact (toi)
112 // btScalar toi = collisionPair.m_algorithm->calculateTimeOfImpact(colObj0,colObj1,dispatchInfo,&contactPointResult);
113 // if (dispatchInfo.m_timeOfImpact > toi)
114 // dispatchInfo.m_timeOfImpact = toi;
115 //
116 // }
117 // }
118 // }
119 //
120 //}
121 
122 } //BulletAnimatSim
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
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.