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 | #include "btSphereTriangleCollisionAlgorithm.h" |
---|
18 | #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h" |
---|
19 | #include "BulletCollision/CollisionShapes/btSphereShape.h" |
---|
20 | #include "BulletCollision/CollisionDispatch/btCollisionObject.h" |
---|
21 | #include "SphereTriangleDetector.h" |
---|
22 | |
---|
23 | |
---|
24 | btSphereTriangleCollisionAlgorithm::btSphereTriangleCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1,bool swapped) |
---|
25 | : btActivatingCollisionAlgorithm(ci,col0,col1), |
---|
26 | m_ownManifold(false), |
---|
27 | m_manifoldPtr(mf), |
---|
28 | m_swapped(swapped) |
---|
29 | { |
---|
30 | if (!m_manifoldPtr) |
---|
31 | { |
---|
32 | m_manifoldPtr = m_dispatcher->getNewManifold(col0,col1); |
---|
33 | m_ownManifold = true; |
---|
34 | } |
---|
35 | } |
---|
36 | |
---|
37 | btSphereTriangleCollisionAlgorithm::~btSphereTriangleCollisionAlgorithm() |
---|
38 | { |
---|
39 | if (m_ownManifold) |
---|
40 | { |
---|
41 | if (m_manifoldPtr) |
---|
42 | m_dispatcher->releaseManifold(m_manifoldPtr); |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | void btSphereTriangleCollisionAlgorithm::processCollision (btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) |
---|
47 | { |
---|
48 | if (!m_manifoldPtr) |
---|
49 | return; |
---|
50 | |
---|
51 | btCollisionObject* sphereObj = m_swapped? col1 : col0; |
---|
52 | btCollisionObject* triObj = m_swapped? col0 : col1; |
---|
53 | |
---|
54 | btSphereShape* sphere = (btSphereShape*)sphereObj->getCollisionShape(); |
---|
55 | btTriangleShape* triangle = (btTriangleShape*)triObj->getCollisionShape(); |
---|
56 | |
---|
57 | /// report a contact. internally this will be kept persistent, and contact reduction is done |
---|
58 | resultOut->setPersistentManifold(m_manifoldPtr); |
---|
59 | SphereTriangleDetector detector(sphere,triangle, m_manifoldPtr->getContactBreakingThreshold()); |
---|
60 | |
---|
61 | btDiscreteCollisionDetectorInterface::ClosestPointInput input; |
---|
62 | input.m_maximumDistanceSquared = btScalar(1e30);///@todo: tighter bounds |
---|
63 | input.m_transformA = sphereObj->getWorldTransform(); |
---|
64 | input.m_transformB = triObj->getWorldTransform(); |
---|
65 | |
---|
66 | bool swapResults = m_swapped; |
---|
67 | |
---|
68 | detector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw,swapResults); |
---|
69 | |
---|
70 | if (m_ownManifold) |
---|
71 | resultOut->refreshContactPoints(); |
---|
72 | |
---|
73 | } |
---|
74 | |
---|
75 | btScalar btSphereTriangleCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) |
---|
76 | { |
---|
77 | (void)resultOut; |
---|
78 | (void)dispatchInfo; |
---|
79 | (void)col0; |
---|
80 | (void)col1; |
---|
81 | |
---|
82 | //not yet |
---|
83 | return btScalar(1.); |
---|
84 | } |
---|