1 /********************************************************************************
2 * ReactPhysics3D physics library, http://www.reactphysics3d.com *
3 * Copyright (c) 2010-2020 Daniel Chappuis *
4 *********************************************************************************
5 * *
6 * This software is provided 'as-is', without any express or implied warranty. *
7 * In no event will the authors be held liable for any damages arising from the *
8 * use of this software. *
9 * *
10 * Permission is granted to anyone to use this software for any purpose, *
11 * including commercial applications, and to alter it and redistribute it *
12 * freely, subject to the following restrictions: *
13 * *
14 * 1. The origin of this software must not be misrepresented; you must not claim *
15 * that you wrote the original software. If you use this software in a *
16 * product, an acknowledgment in the product documentation would be *
17 * appreciated but is not required. *
18 * *
19 * 2. Altered source versions must be plainly marked as such, and must not be *
20 * misrepresented as being the original software. *
21 * *
22 * 3. This notice may not be removed or altered from any source distribution. *
23 * *
24 ********************************************************************************/
25
26 // Libraries
27 #include <reactphysics3d/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.h>
28 #include <reactphysics3d/collision/narrowphase/GJK/GJKAlgorithm.h>
29 #include <reactphysics3d/collision/narrowphase/SAT/SATAlgorithm.h>
30 #include <reactphysics3d/collision/narrowphase/NarrowPhaseInfoBatch.h>
31
32 // We want to use the ReactPhysics3D namespace
33 using namespace reactphysics3d;
34
35 // Compute the narrow-phase collision detection between two convex polyhedra
36 // This technique is based on the "Robust Contact Creation for Physics Simulations" presentation
37 // by Dirk Gregorius.
testCollision(NarrowPhaseInfoBatch & narrowPhaseInfoBatch,uint batchStartIndex,uint batchNbItems,bool clipWithPreviousAxisIfStillColliding,MemoryAllocator & memoryAllocator)38 bool ConvexPolyhedronVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch,
39 uint batchStartIndex, uint batchNbItems,
40 bool clipWithPreviousAxisIfStillColliding, MemoryAllocator& memoryAllocator) {
41
42 // Run the SAT algorithm to find the separating axis and compute contact point
43 SATAlgorithm satAlgorithm(clipWithPreviousAxisIfStillColliding, memoryAllocator);
44
45 #ifdef IS_RP3D_PROFILING_ENABLED
46
47
48 satAlgorithm.setProfiler(mProfiler);
49
50 #endif
51
52 bool isCollisionFound = satAlgorithm.testCollisionConvexPolyhedronVsConvexPolyhedron(narrowPhaseInfoBatch, batchStartIndex, batchNbItems);
53
54 for (uint batchIndex = batchStartIndex; batchIndex < batchStartIndex + batchNbItems; batchIndex++) {
55
56 // Get the last frame collision info
57 LastFrameCollisionInfo* lastFrameCollisionInfo = narrowPhaseInfoBatch.lastFrameCollisionInfos[batchIndex];
58
59 lastFrameCollisionInfo->wasUsingSAT = true;
60 lastFrameCollisionInfo->wasUsingGJK = false;
61 }
62
63 return isCollisionFound;
64 }
65