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_DISCRETE_COLLISION_DETECTOR1_INTERFACE_H |
---|
18 | #define BT_DISCRETE_COLLISION_DETECTOR1_INTERFACE_H |
---|
19 | |
---|
20 | #include "LinearMath/btTransform.h" |
---|
21 | #include "LinearMath/btVector3.h" |
---|
22 | class btStackAlloc; |
---|
23 | |
---|
24 | /// This interface is made to be used by an iterative approach to do TimeOfImpact calculations |
---|
25 | /// This interface allows to query for closest points and penetration depth between two (convex) objects |
---|
26 | /// the closest point is on the second object (B), and the normal points from the surface on B towards A. |
---|
27 | /// distance is between closest points on B and closest point on A. So you can calculate closest point on A |
---|
28 | /// by taking closestPointInA = closestPointInB + m_distance * m_normalOnSurfaceB |
---|
29 | struct btDiscreteCollisionDetectorInterface |
---|
30 | { |
---|
31 | |
---|
32 | struct Result |
---|
33 | { |
---|
34 | |
---|
35 | virtual ~Result(){} |
---|
36 | |
---|
37 | ///setShapeIdentifiersA/B provides experimental support for per-triangle material / custom material combiner |
---|
38 | virtual void setShapeIdentifiersA(int partId0,int index0)=0; |
---|
39 | virtual void setShapeIdentifiersB(int partId1,int index1)=0; |
---|
40 | virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth)=0; |
---|
41 | }; |
---|
42 | |
---|
43 | struct ClosestPointInput |
---|
44 | { |
---|
45 | ClosestPointInput() |
---|
46 | :m_maximumDistanceSquared(btScalar(BT_LARGE_FLOAT)), |
---|
47 | m_stackAlloc(0) |
---|
48 | { |
---|
49 | } |
---|
50 | |
---|
51 | btTransform m_transformA; |
---|
52 | btTransform m_transformB; |
---|
53 | btScalar m_maximumDistanceSquared; |
---|
54 | btStackAlloc* m_stackAlloc; |
---|
55 | }; |
---|
56 | |
---|
57 | virtual ~btDiscreteCollisionDetectorInterface() {}; |
---|
58 | |
---|
59 | // |
---|
60 | // give either closest points (distance > 0) or penetration (distance) |
---|
61 | // the normal always points from B towards A |
---|
62 | // |
---|
63 | virtual void getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults=false) = 0; |
---|
64 | |
---|
65 | }; |
---|
66 | |
---|
67 | struct btStorageResult : public btDiscreteCollisionDetectorInterface::Result |
---|
68 | { |
---|
69 | btVector3 m_normalOnSurfaceB; |
---|
70 | btVector3 m_closestPointInB; |
---|
71 | btScalar m_distance; //negative means penetration ! |
---|
72 | |
---|
73 | btStorageResult() : m_distance(btScalar(BT_LARGE_FLOAT)) |
---|
74 | { |
---|
75 | |
---|
76 | } |
---|
77 | virtual ~btStorageResult() {}; |
---|
78 | |
---|
79 | virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth) |
---|
80 | { |
---|
81 | if (depth < m_distance) |
---|
82 | { |
---|
83 | m_normalOnSurfaceB = normalOnBInWorld; |
---|
84 | m_closestPointInB = pointInWorld; |
---|
85 | m_distance = depth; |
---|
86 | } |
---|
87 | } |
---|
88 | }; |
---|
89 | |
---|
90 | #endif //BT_DISCRETE_COLLISION_DETECTOR1_INTERFACE_H |
---|
91 | |
---|