• 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 
17 #ifndef BT_MANIFOLD_RESULT_H
18 #define BT_MANIFOLD_RESULT_H
19 
20 class btCollisionObject;
21 struct btCollisionObjectWrapper;
22 
23 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
24 class btManifoldPoint;
25 
26 #include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
27 
28 #include "LinearMath/btTransform.h"
29 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
30 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
31 
32 typedef bool (*ContactAddedCallback)(btManifoldPoint& cp,	const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0,const btCollisionObjectWrapper* colObj1Wrap,int partId1,int index1);
33 extern ContactAddedCallback		gContactAddedCallback;
34 
35 //#define DEBUG_PART_INDEX 1
36 
37 
38 ///btManifoldResult is a helper class to manage  contact results.
39 class btManifoldResult : public btDiscreteCollisionDetectorInterface::Result
40 {
41 protected:
42 
43 	btPersistentManifold* m_manifoldPtr;
44 
45 	const btCollisionObjectWrapper* m_body0Wrap;
46 	const btCollisionObjectWrapper* m_body1Wrap;
47 	int	m_partId0;
48 	int m_partId1;
49 	int m_index0;
50 	int m_index1;
51 
52 
53 public:
54 
btManifoldResult()55 	btManifoldResult()
56 #ifdef DEBUG_PART_INDEX
57 		:
58 	m_partId0(-1),
59 	m_partId1(-1),
60 	m_index0(-1),
61 	m_index1(-1)
62 #endif //DEBUG_PART_INDEX
63 	{
64 	}
65 
66 	btManifoldResult(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
67 
~btManifoldResult()68 	virtual ~btManifoldResult() {};
69 
setPersistentManifold(btPersistentManifold * manifoldPtr)70 	void	setPersistentManifold(btPersistentManifold* manifoldPtr)
71 	{
72 		m_manifoldPtr = manifoldPtr;
73 	}
74 
getPersistentManifold()75 	const btPersistentManifold*	getPersistentManifold() const
76 	{
77 		return m_manifoldPtr;
78 	}
getPersistentManifold()79 	btPersistentManifold*	getPersistentManifold()
80 	{
81 		return m_manifoldPtr;
82 	}
83 
setShapeIdentifiersA(int partId0,int index0)84 	virtual void setShapeIdentifiersA(int partId0,int index0)
85 	{
86 		m_partId0=partId0;
87 		m_index0=index0;
88 	}
89 
setShapeIdentifiersB(int partId1,int index1)90 	virtual void setShapeIdentifiersB(	int partId1,int index1)
91 	{
92 		m_partId1=partId1;
93 		m_index1=index1;
94 	}
95 
96 
97 	virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth);
98 
refreshContactPoints()99 	SIMD_FORCE_INLINE	void refreshContactPoints()
100 	{
101 		btAssert(m_manifoldPtr);
102 		if (!m_manifoldPtr->getNumContacts())
103 			return;
104 
105 		bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject();
106 
107 		if (isSwapped)
108 		{
109 			m_manifoldPtr->refreshContactPoints(m_body1Wrap->getCollisionObject()->getWorldTransform(),m_body0Wrap->getCollisionObject()->getWorldTransform());
110 		} else
111 		{
112 			m_manifoldPtr->refreshContactPoints(m_body0Wrap->getCollisionObject()->getWorldTransform(),m_body1Wrap->getCollisionObject()->getWorldTransform());
113 		}
114 	}
115 
getBody0Wrap()116 	const btCollisionObjectWrapper* getBody0Wrap() const
117 	{
118 		return m_body0Wrap;
119 	}
getBody1Wrap()120 	const btCollisionObjectWrapper* getBody1Wrap() const
121 	{
122 		return m_body1Wrap;
123 	}
124 
setBody0Wrap(const btCollisionObjectWrapper * obj0Wrap)125 	void setBody0Wrap(const btCollisionObjectWrapper* obj0Wrap)
126 	{
127 		m_body0Wrap = obj0Wrap;
128 	}
129 
setBody1Wrap(const btCollisionObjectWrapper * obj1Wrap)130 	void setBody1Wrap(const btCollisionObjectWrapper* obj1Wrap)
131 	{
132 		m_body1Wrap = obj1Wrap;
133 	}
134 
getBody0Internal()135 	const btCollisionObject* getBody0Internal() const
136 	{
137 		return m_body0Wrap->getCollisionObject();
138 	}
139 
getBody1Internal()140 	const btCollisionObject* getBody1Internal() const
141 	{
142 		return m_body1Wrap->getCollisionObject();
143 	}
144 
145 	/// in the future we can let the user override the methods to combine restitution and friction
146 	static btScalar	calculateCombinedRestitution(const btCollisionObject* body0,const btCollisionObject* body1);
147 	static btScalar	calculateCombinedFriction(const btCollisionObject* body0,const btCollisionObject* body1);
148 };
149 
150 #endif //BT_MANIFOLD_RESULT_H
151