2006-02-21 05:36:56 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2002-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute and sell this software
|
|
|
|
* and its documentation for any purpose is hereby granted without fee,
|
|
|
|
* provided that the above copyright notice appear in all copies.
|
|
|
|
* Erwin Coumans makes no representations about the suitability
|
|
|
|
* of this software for any purpose.
|
|
|
|
* It is provided "as is" without express or implied warranty.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COLLISION__DISPATCHER_H
|
|
|
|
#define COLLISION__DISPATCHER_H
|
|
|
|
|
|
|
|
#include "BroadphaseCollision/Dispatcher.h"
|
2005-07-16 09:58:01 +00:00
|
|
|
#include "NarrowPhaseCollision/PersistentManifold.h"
|
|
|
|
#include "CollisionDispatch/UnionFind.h"
|
|
|
|
#include "BroadphaseCollision/BroadphaseProxy.h"
|
2006-02-21 05:36:56 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2005-07-16 09:58:01 +00:00
|
|
|
|
2005-07-29 18:14:41 +00:00
|
|
|
class IDebugDraw;
|
2005-07-16 09:58:01 +00:00
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
|
2005-07-16 09:58:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct CollisionAlgorithmCreateFunc
|
|
|
|
{
|
|
|
|
bool m_swapped;
|
|
|
|
|
|
|
|
CollisionAlgorithmCreateFunc()
|
|
|
|
:m_swapped(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual CollisionAlgorithm* CreateCollisionAlgorithm(BroadphaseProxy& proxy0,BroadphaseProxy& proxy1)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
2006-02-21 05:36:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
///CollisionDispatcher supports algorithms that handle ConvexConvex and ConvexConcave collision pairs.
|
2005-07-16 09:58:01 +00:00
|
|
|
///Time of Impact, Closest Points and Penetration Depth.
|
2006-02-21 05:36:56 +00:00
|
|
|
class CollisionDispatcher : public Dispatcher
|
2005-07-16 09:58:01 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
std::vector<PersistentManifold*> m_manifoldsPtr;
|
|
|
|
|
|
|
|
UnionFind m_unionFind;
|
2006-02-21 05:36:56 +00:00
|
|
|
|
|
|
|
bool m_useIslands;
|
2005-07-16 09:58:01 +00:00
|
|
|
|
2005-08-03 18:22:30 +00:00
|
|
|
|
2005-07-16 09:58:01 +00:00
|
|
|
CollisionAlgorithmCreateFunc* m_doubleDispatch[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES];
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
UnionFind& GetUnionFind() { return m_unionFind;}
|
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
struct IslandCallback
|
|
|
|
{
|
|
|
|
virtual void ProcessIsland(PersistentManifold** manifolds,int numManifolds) = 0;
|
|
|
|
};
|
2005-07-16 09:58:01 +00:00
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
|
|
|
|
int GetNumManifolds() const
|
|
|
|
{
|
|
|
|
return m_manifoldsPtr.size();
|
|
|
|
}
|
2005-07-16 09:58:01 +00:00
|
|
|
|
|
|
|
PersistentManifold* GetManifoldByIndexInternal(int index)
|
|
|
|
{
|
2006-02-21 05:36:56 +00:00
|
|
|
return m_manifoldsPtr[index];
|
2005-07-16 09:58:01 +00:00
|
|
|
}
|
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
const PersistentManifold* GetManifoldByIndexInternal(int index) const
|
|
|
|
{
|
|
|
|
return m_manifoldsPtr[index];
|
|
|
|
}
|
2005-07-16 09:58:01 +00:00
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
void InitUnionFind(int n)
|
2005-07-16 09:58:01 +00:00
|
|
|
{
|
|
|
|
if (m_useIslands)
|
2006-02-21 05:36:56 +00:00
|
|
|
m_unionFind.reset(n);
|
2005-07-16 09:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FindUnions();
|
|
|
|
|
|
|
|
int m_count;
|
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
CollisionDispatcher ();
|
2005-07-16 09:58:01 +00:00
|
|
|
|
|
|
|
virtual PersistentManifold* GetNewManifold(void* b0,void* b1);
|
|
|
|
|
|
|
|
virtual void ReleaseManifold(PersistentManifold* manifold);
|
|
|
|
|
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
virtual void BuildAndProcessIslands(int numBodies, IslandCallback* callback);
|
|
|
|
|
|
|
|
|
2005-07-16 09:58:01 +00:00
|
|
|
CollisionAlgorithm* FindAlgorithm(BroadphaseProxy& proxy0,BroadphaseProxy& proxy1)
|
|
|
|
{
|
|
|
|
CollisionAlgorithm* algo = InternalFindAlgorithm(proxy0,proxy1);
|
|
|
|
return algo;
|
|
|
|
}
|
|
|
|
|
|
|
|
CollisionAlgorithm* InternalFindAlgorithm(BroadphaseProxy& proxy0,BroadphaseProxy& proxy1);
|
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
virtual bool NeedsCollision(BroadphaseProxy& proxy0,BroadphaseProxy& proxy1);
|
2005-08-03 18:22:30 +00:00
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
|
|
|
|
virtual int GetUniqueId() { return RIGIDBODY_DISPATCHER;}
|
2005-08-03 18:22:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2005-07-16 09:58:01 +00:00
|
|
|
};
|
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
#endif //COLLISION__DISPATCHER_H
|
2005-07-16 09:58:01 +00:00
|
|
|
|