This commit is contained in:
@@ -71,13 +71,34 @@ struct BroadphaseProxy
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool IsPolyhedral(int proxyType)
|
||||||
|
{
|
||||||
|
return (proxyType < IMPLICIT_CONVEX_SHAPES_START_HERE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool IsConvex(int proxyType)
|
||||||
|
{
|
||||||
|
return (proxyType < CONCAVE_SHAPES_START_HERE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool IsConcave(int proxyType)
|
||||||
|
{
|
||||||
|
return ((proxyType > CONCAVE_SHAPES_START_HERE) &&
|
||||||
|
(proxyType < CONCAVE_SHAPES_END_HERE));
|
||||||
|
}
|
||||||
|
static inline bool IsCompound(int proxyType)
|
||||||
|
{
|
||||||
|
return (proxyType == COMPOUND_SHAPE_PROXYTYPE);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CollisionAlgorithm;
|
class CollisionAlgorithm;
|
||||||
|
|
||||||
struct BroadphaseProxy;
|
struct BroadphaseProxy;
|
||||||
|
|
||||||
#define SIMPLE_MAX_ALGORITHMS 2
|
//Increase SIMPLE_MAX_ALGORITHMS to allow multiple Dispatchers caching their own algorithms
|
||||||
|
#define SIMPLE_MAX_ALGORITHMS 1
|
||||||
|
|
||||||
/// contains a pair of aabb-overlapping objects
|
/// contains a pair of aabb-overlapping objects
|
||||||
struct BroadphasePair
|
struct BroadphasePair
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ subject to the following restrictions:
|
|||||||
typedef std::vector<struct CollisionObject*> CollisionObjectArray;
|
typedef std::vector<struct CollisionObject*> CollisionObjectArray;
|
||||||
class CollisionAlgorithm;
|
class CollisionAlgorithm;
|
||||||
struct BroadphaseProxy;
|
struct BroadphaseProxy;
|
||||||
|
struct CollisionAlgorithmConstructionInfo;
|
||||||
|
|
||||||
|
|
||||||
struct CollisionAlgorithmCreateFunc
|
struct CollisionAlgorithmCreateFunc
|
||||||
@@ -34,7 +34,7 @@ struct CollisionAlgorithmCreateFunc
|
|||||||
}
|
}
|
||||||
virtual ~CollisionAlgorithmCreateFunc(){};
|
virtual ~CollisionAlgorithmCreateFunc(){};
|
||||||
|
|
||||||
virtual CollisionAlgorithm* CreateCollisionAlgorithm(BroadphaseProxy& proxy0,BroadphaseProxy& proxy1)
|
virtual CollisionAlgorithm* CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo& ci, BroadphaseProxy* proxy0,BroadphaseProxy* proxy1)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,17 +40,37 @@ CollisionDispatcher::CollisionDispatcher ():
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
//default CreationFunctions, filling the m_doubleDispatch table
|
||||||
|
m_convexConvexCreateFunc = new ConvexConvexAlgorithm::CreateFunc;
|
||||||
|
m_convexConcaveCreateFunc = new ConvexConcaveCollisionAlgorithm::CreateFunc;
|
||||||
|
m_swappedConvexConcaveCreateFunc = new ConvexConcaveCollisionAlgorithm::SwappedCreateFunc;
|
||||||
|
m_compoundCreateFunc = new CompoundCollisionAlgorithm::CreateFunc;
|
||||||
|
m_swappedCompoundCreateFunc = new CompoundCollisionAlgorithm::SwappedCreateFunc;
|
||||||
|
m_emptyCreateFunc = new EmptyAlgorithm::CreateFunc;
|
||||||
|
|
||||||
for (i=0;i<MAX_BROADPHASE_COLLISION_TYPES;i++)
|
for (i=0;i<MAX_BROADPHASE_COLLISION_TYPES;i++)
|
||||||
{
|
{
|
||||||
for (int j=0;j<MAX_BROADPHASE_COLLISION_TYPES;j++)
|
for (int j=0;j<MAX_BROADPHASE_COLLISION_TYPES;j++)
|
||||||
{
|
{
|
||||||
m_doubleDispatch[i][j] = 0;
|
m_doubleDispatch[i][j] = InternalFindCreateFunc(i,j);
|
||||||
|
assert(m_doubleDispatch[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
CollisionDispatcher::~CollisionDispatcher()
|
||||||
|
{
|
||||||
|
delete m_convexConvexCreateFunc;
|
||||||
|
delete m_convexConcaveCreateFunc;
|
||||||
|
delete m_swappedConvexConcaveCreateFunc;
|
||||||
|
delete m_compoundCreateFunc;
|
||||||
|
delete m_swappedCompoundCreateFunc;
|
||||||
|
delete m_emptyCreateFunc;
|
||||||
|
}
|
||||||
|
|
||||||
PersistentManifold* CollisionDispatcher::GetNewManifold(void* b0,void* b1)
|
PersistentManifold* CollisionDispatcher::GetNewManifold(void* b0,void* b1)
|
||||||
{
|
{
|
||||||
gNumManifold++;
|
gNumManifold++;
|
||||||
@@ -97,6 +117,56 @@ void CollisionDispatcher::ReleaseManifold(PersistentManifold* manifold)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CollisionAlgorithm* CollisionDispatcher::FindAlgorithm(BroadphaseProxy& proxy0,BroadphaseProxy& proxy1)
|
||||||
|
{
|
||||||
|
#define USE_DISPATCH_REGISTRY_ARRAY 1
|
||||||
|
#ifdef USE_DISPATCH_REGISTRY_ARRAY
|
||||||
|
CollisionObject* body0 = (CollisionObject*)proxy0.m_clientObject;
|
||||||
|
CollisionObject* body1 = (CollisionObject*)proxy1.m_clientObject;
|
||||||
|
CollisionAlgorithmConstructionInfo ci;
|
||||||
|
ci.m_dispatcher = this;
|
||||||
|
CollisionAlgorithm* algo = m_doubleDispatch[body0->m_collisionShape->GetShapeType()][body1->m_collisionShape->GetShapeType()]
|
||||||
|
->CreateCollisionAlgorithm(ci,&proxy0,&proxy1);
|
||||||
|
#else
|
||||||
|
CollisionAlgorithm* algo = InternalFindAlgorithm(proxy0,proxy1);
|
||||||
|
#endif //USE_DISPATCH_REGISTRY_ARRAY
|
||||||
|
return algo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CollisionAlgorithmCreateFunc* CollisionDispatcher::InternalFindCreateFunc(int proxyType0,int proxyType1)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (BroadphaseProxy::IsConvex(proxyType0) && BroadphaseProxy::IsConvex(proxyType1))
|
||||||
|
{
|
||||||
|
return m_convexConvexCreateFunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BroadphaseProxy::IsConvex(proxyType0) && BroadphaseProxy::IsConcave(proxyType1))
|
||||||
|
{
|
||||||
|
return m_convexConcaveCreateFunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BroadphaseProxy::IsConvex(proxyType1) && BroadphaseProxy::IsConcave(proxyType0))
|
||||||
|
{
|
||||||
|
return m_swappedConvexConcaveCreateFunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BroadphaseProxy::IsCompound(proxyType0))
|
||||||
|
{
|
||||||
|
return m_compoundCreateFunc;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
if (BroadphaseProxy::IsCompound(proxyType1))
|
||||||
|
{
|
||||||
|
return m_swappedCompoundCreateFunc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//failed to find an algorithm
|
||||||
|
return m_emptyCreateFunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CollisionAlgorithm* CollisionDispatcher::InternalFindAlgorithm(BroadphaseProxy& proxy0,BroadphaseProxy& proxy1)
|
CollisionAlgorithm* CollisionDispatcher::InternalFindAlgorithm(BroadphaseProxy& proxy0,BroadphaseProxy& proxy1)
|
||||||
|
|||||||
@@ -40,20 +40,26 @@ class CollisionDispatcher : public Dispatcher
|
|||||||
|
|
||||||
std::vector<PersistentManifold*> m_manifoldsPtr;
|
std::vector<PersistentManifold*> m_manifoldsPtr;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool m_useIslands;
|
bool m_useIslands;
|
||||||
|
|
||||||
ManifoldResult m_defaultManifoldResult;
|
ManifoldResult m_defaultManifoldResult;
|
||||||
|
|
||||||
CollisionAlgorithmCreateFunc* m_doubleDispatch[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES];
|
CollisionAlgorithmCreateFunc* m_doubleDispatch[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES];
|
||||||
|
|
||||||
|
CollisionAlgorithmCreateFunc* InternalFindCreateFunc(int proxyType0,int proxyType1);
|
||||||
|
|
||||||
|
//default CreationFunctions, filling the m_doubleDispatch table
|
||||||
|
CollisionAlgorithmCreateFunc* m_convexConvexCreateFunc;
|
||||||
|
CollisionAlgorithmCreateFunc* m_convexConcaveCreateFunc;
|
||||||
|
CollisionAlgorithmCreateFunc* m_swappedConvexConcaveCreateFunc;
|
||||||
|
CollisionAlgorithmCreateFunc* m_compoundCreateFunc;
|
||||||
|
CollisionAlgorithmCreateFunc* m_swappedCompoundCreateFunc;
|
||||||
|
CollisionAlgorithmCreateFunc* m_emptyCreateFunc;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
///RegisterCollisionCreateFunc allows registration of custom/alternative collision create functions
|
||||||
|
void RegisterCollisionCreateFunc(int proxyType0,int proxyType1, CollisionAlgorithmCreateFunc* createFunc);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int GetNumManifolds() const
|
int GetNumManifolds() const
|
||||||
{
|
{
|
||||||
@@ -73,7 +79,7 @@ public:
|
|||||||
int m_count;
|
int m_count;
|
||||||
|
|
||||||
CollisionDispatcher ();
|
CollisionDispatcher ();
|
||||||
virtual ~CollisionDispatcher() {};
|
virtual ~CollisionDispatcher();
|
||||||
|
|
||||||
virtual PersistentManifold* GetNewManifold(void* b0,void* b1);
|
virtual PersistentManifold* GetNewManifold(void* b0,void* b1);
|
||||||
|
|
||||||
@@ -89,11 +95,7 @@ public:
|
|||||||
virtual void ClearManifold(PersistentManifold* manifold);
|
virtual void ClearManifold(PersistentManifold* manifold);
|
||||||
|
|
||||||
|
|
||||||
CollisionAlgorithm* FindAlgorithm(BroadphaseProxy& proxy0,BroadphaseProxy& proxy1)
|
CollisionAlgorithm* FindAlgorithm(BroadphaseProxy& proxy0,BroadphaseProxy& proxy1);
|
||||||
{
|
|
||||||
CollisionAlgorithm* algo = InternalFindAlgorithm(proxy0,proxy1);
|
|
||||||
return algo;
|
|
||||||
}
|
|
||||||
|
|
||||||
CollisionAlgorithm* InternalFindAlgorithm(BroadphaseProxy& proxy0,BroadphaseProxy& proxy1);
|
CollisionAlgorithm* InternalFindAlgorithm(BroadphaseProxy& proxy0,BroadphaseProxy& proxy1);
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ subject to the following restrictions:
|
|||||||
class Dispatcher;
|
class Dispatcher;
|
||||||
#include "BroadphaseCollision/BroadphaseProxy.h"
|
#include "BroadphaseCollision/BroadphaseProxy.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "CollisionCreateFunc.h"
|
||||||
|
|
||||||
/// CompoundCollisionAlgorithm supports collision between CompoundCollisionShapes and other collision shapes
|
/// CompoundCollisionAlgorithm supports collision between CompoundCollisionShapes and other collision shapes
|
||||||
/// Place holder, not fully implemented yet
|
/// Place holder, not fully implemented yet
|
||||||
@@ -51,6 +51,22 @@ public:
|
|||||||
|
|
||||||
float CalculateTimeOfImpact(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const DispatcherInfo& dispatchInfo);
|
float CalculateTimeOfImpact(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const DispatcherInfo& dispatchInfo);
|
||||||
|
|
||||||
|
struct CreateFunc :public CollisionAlgorithmCreateFunc
|
||||||
|
{
|
||||||
|
virtual CollisionAlgorithm* CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo& ci, BroadphaseProxy* proxy0,BroadphaseProxy* proxy1)
|
||||||
|
{
|
||||||
|
return new CompoundCollisionAlgorithm(ci,proxy0,proxy1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SwappedCreateFunc :public CollisionAlgorithmCreateFunc
|
||||||
|
{
|
||||||
|
virtual CollisionAlgorithm* CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo& ci, BroadphaseProxy* proxy0,BroadphaseProxy* proxy1)
|
||||||
|
{
|
||||||
|
return new CompoundCollisionAlgorithm(ci,proxy1,proxy0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //COMPOUND_COLLISION_ALGORITHM_H
|
#endif //COMPOUND_COLLISION_ALGORITHM_H
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ subject to the following restrictions:
|
|||||||
#include "NarrowPhaseCollision/PersistentManifold.h"
|
#include "NarrowPhaseCollision/PersistentManifold.h"
|
||||||
class Dispatcher;
|
class Dispatcher;
|
||||||
#include "BroadphaseCollision/BroadphaseProxy.h"
|
#include "BroadphaseCollision/BroadphaseProxy.h"
|
||||||
|
#include "CollisionCreateFunc.h"
|
||||||
|
|
||||||
///For each triangle in the concave mesh that overlaps with the AABB of a convex (m_convexProxy), ProcessTriangle is called.
|
///For each triangle in the concave mesh that overlaps with the AABB of a convex (m_convexProxy), ProcessTriangle is called.
|
||||||
class ConvexTriangleCallback : public TriangleCallback
|
class ConvexTriangleCallback : public TriangleCallback
|
||||||
@@ -90,6 +90,22 @@ public:
|
|||||||
|
|
||||||
void ClearCache();
|
void ClearCache();
|
||||||
|
|
||||||
|
struct CreateFunc :public CollisionAlgorithmCreateFunc
|
||||||
|
{
|
||||||
|
virtual CollisionAlgorithm* CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo& ci, BroadphaseProxy* proxy0,BroadphaseProxy* proxy1)
|
||||||
|
{
|
||||||
|
return new ConvexConcaveCollisionAlgorithm(ci,proxy0,proxy1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SwappedCreateFunc :public CollisionAlgorithmCreateFunc
|
||||||
|
{
|
||||||
|
virtual CollisionAlgorithm* CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo& ci, BroadphaseProxy* proxy0,BroadphaseProxy* proxy1)
|
||||||
|
{
|
||||||
|
return new ConvexConcaveCollisionAlgorithm(ci,proxy1,proxy0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //CONVEX_CONCAVE_COLLISION_ALGORITHM_H
|
#endif //CONVEX_CONCAVE_COLLISION_ALGORITHM_H
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ subject to the following restrictions:
|
|||||||
#include "NarrowPhaseCollision/PersistentManifold.h"
|
#include "NarrowPhaseCollision/PersistentManifold.h"
|
||||||
#include "BroadphaseCollision/BroadphaseProxy.h"
|
#include "BroadphaseCollision/BroadphaseProxy.h"
|
||||||
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
|
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
|
||||||
|
#include "CollisionCreateFunc.h"
|
||||||
|
|
||||||
class ConvexPenetrationDepthSolver;
|
class ConvexPenetrationDepthSolver;
|
||||||
|
|
||||||
@@ -68,6 +69,15 @@ public:
|
|||||||
return m_manifoldPtr;
|
return m_manifoldPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct CreateFunc :public CollisionAlgorithmCreateFunc
|
||||||
|
{
|
||||||
|
virtual CollisionAlgorithm* CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo& ci, BroadphaseProxy* proxy0,BroadphaseProxy* proxy1)
|
||||||
|
{
|
||||||
|
return new ConvexConvexAlgorithm(0,ci,proxy0,proxy1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //CONVEX_CONVEX_ALGORITHM_H
|
#endif //CONVEX_CONVEX_ALGORITHM_H
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ subject to the following restrictions:
|
|||||||
#ifndef EMPTY_ALGORITH
|
#ifndef EMPTY_ALGORITH
|
||||||
#define EMPTY_ALGORITH
|
#define EMPTY_ALGORITH
|
||||||
#include "BroadphaseCollision/CollisionAlgorithm.h"
|
#include "BroadphaseCollision/CollisionAlgorithm.h"
|
||||||
|
#include "CollisionCreateFunc.h"
|
||||||
|
|
||||||
#define ATTRIBUTE_ALIGNED(a)
|
#define ATTRIBUTE_ALIGNED(a)
|
||||||
|
|
||||||
@@ -32,8 +33,13 @@ public:
|
|||||||
|
|
||||||
virtual float CalculateTimeOfImpact(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const DispatcherInfo& dispatchInfo);
|
virtual float CalculateTimeOfImpact(BroadphaseProxy* proxy0,BroadphaseProxy* proxy1,const DispatcherInfo& dispatchInfo);
|
||||||
|
|
||||||
|
struct CreateFunc :public CollisionAlgorithmCreateFunc
|
||||||
|
{
|
||||||
|
virtual CollisionAlgorithm* CreateCollisionAlgorithm(CollisionAlgorithmConstructionInfo& ci, BroadphaseProxy* proxy0,BroadphaseProxy* proxy1)
|
||||||
|
{
|
||||||
|
return new EmptyAlgorithm(ci);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} ATTRIBUTE_ALIGNED(16);
|
} ATTRIBUTE_ALIGNED(16);
|
||||||
|
|
||||||
|
|||||||
@@ -48,23 +48,22 @@ public:
|
|||||||
///result is conservative
|
///result is conservative
|
||||||
void CalculateTemporalAabb(const SimdTransform& curTrans,const SimdVector3& linvel,const SimdVector3& angvel,SimdScalar timeStep, SimdVector3& temporalAabbMin,SimdVector3& temporalAabbMax);
|
void CalculateTemporalAabb(const SimdTransform& curTrans,const SimdVector3& linvel,const SimdVector3& angvel,SimdScalar timeStep, SimdVector3& temporalAabbMin,SimdVector3& temporalAabbMax);
|
||||||
|
|
||||||
bool IsPolyhedral() const
|
inline bool IsPolyhedral() const
|
||||||
{
|
{
|
||||||
return (GetShapeType() < IMPLICIT_CONVEX_SHAPES_START_HERE);
|
return BroadphaseProxy::IsPolyhedral(GetShapeType());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsConvex() const
|
inline bool IsConvex() const
|
||||||
{
|
{
|
||||||
return (GetShapeType() < CONCAVE_SHAPES_START_HERE);
|
return BroadphaseProxy::IsConvex(GetShapeType());
|
||||||
}
|
}
|
||||||
bool IsConcave() const
|
inline bool IsConcave() const
|
||||||
{
|
{
|
||||||
return ((GetShapeType() > CONCAVE_SHAPES_START_HERE) &&
|
return BroadphaseProxy::IsConcave(GetShapeType());
|
||||||
(GetShapeType() < CONCAVE_SHAPES_END_HERE));
|
|
||||||
}
|
}
|
||||||
bool IsCompound() const
|
inline bool IsCompound() const
|
||||||
{
|
{
|
||||||
return (GetShapeType() == COMPOUND_SHAPE_PROXYTYPE);
|
return BroadphaseProxy::IsCompound(GetShapeType());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void setLocalScaling(const SimdVector3& scaling) =0;
|
virtual void setLocalScaling(const SimdVector3& scaling) =0;
|
||||||
|
|||||||
Reference in New Issue
Block a user