• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 #ifndef BT_CONVEX_CONCAVE_COLLISION_ALGORITHM_H
17 #define BT_CONVEX_CONCAVE_COLLISION_ALGORITHM_H
18 
19 #include "btActivatingCollisionAlgorithm.h"
20 #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
21 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
22 #include "BulletCollision/CollisionShapes/btTriangleCallback.h"
23 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
24 class btDispatcher;
25 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
26 #include "btCollisionCreateFunc.h"
27 
28 ///For each triangle in the concave mesh that overlaps with the AABB of a convex (m_convexProxy), processTriangle is called.
29 class btConvexTriangleCallback : public btTriangleCallback
30 {
31 	const btCollisionObjectWrapper* m_convexBodyWrap;
32 	const btCollisionObjectWrapper* m_triBodyWrap;
33 
34 	btVector3	m_aabbMin;
35 	btVector3	m_aabbMax ;
36 
37 
38 	btManifoldResult* m_resultOut;
39 	btDispatcher*	m_dispatcher;
40 	const btDispatcherInfo* m_dispatchInfoPtr;
41 	btScalar m_collisionMarginTriangle;
42 
43 public:
44 int	m_triangleCount;
45 
46 	btPersistentManifold*	m_manifoldPtr;
47 
48 	btConvexTriangleCallback(btDispatcher* dispatcher,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
49 
50 	void	setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,const btCollisionObjectWrapper* convexBodyWrap, const btCollisionObjectWrapper* triBodyWrap, btManifoldResult* resultOut);
51 
clearWrapperData()52 	void	clearWrapperData()
53 	{
54 		m_convexBodyWrap = 0;
55 		m_triBodyWrap = 0;
56 	}
57 	virtual ~btConvexTriangleCallback();
58 
59 	virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex);
60 
61 	void clearCache();
62 
getAabbMin()63 	SIMD_FORCE_INLINE const btVector3& getAabbMin() const
64 	{
65 		return m_aabbMin;
66 	}
getAabbMax()67 	SIMD_FORCE_INLINE const btVector3& getAabbMax() const
68 	{
69 		return m_aabbMax;
70 	}
71 
72 };
73 
74 
75 
76 
77 /// btConvexConcaveCollisionAlgorithm  supports collision between convex shapes and (concave) trianges meshes.
78 class btConvexConcaveCollisionAlgorithm  : public btActivatingCollisionAlgorithm
79 {
80 
81 	bool	m_isSwapped;
82 
83 	btConvexTriangleCallback m_btConvexTriangleCallback;
84 
85 
86 
87 public:
88 
89 	btConvexConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
90 
91 	virtual ~btConvexConcaveCollisionAlgorithm();
92 
93 	virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
94 
95 	btScalar	calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
96 
97 	virtual	void	getAllContactManifolds(btManifoldArray&	manifoldArray);
98 
99 	void	clearCache();
100 
101 	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
102 	{
CreateCollisionAlgorithmCreateFunc103 		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
104 		{
105 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvexConcaveCollisionAlgorithm));
106 			return new(mem) btConvexConcaveCollisionAlgorithm(ci,body0Wrap,body1Wrap,false);
107 		}
108 	};
109 
110 	struct SwappedCreateFunc :public 	btCollisionAlgorithmCreateFunc
111 	{
CreateCollisionAlgorithmSwappedCreateFunc112 		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
113 		{
114 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvexConcaveCollisionAlgorithm));
115 			return new(mem) btConvexConcaveCollisionAlgorithm(ci,body0Wrap,body1Wrap,true);
116 		}
117 	};
118 
119 };
120 
121 #endif //BT_CONVEX_CONCAVE_COLLISION_ALGORITHM_H
122