[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / Bullet3OpenCL / NarrowphaseCollision / b3ContactCache.h
1
2 /*
3 Bullet Continuous Collision Detection and Physics Library
4 Copyright (c) 2003-2013 Erwin Coumans  http://bulletphysics.org
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 use of this software.
8 Permission is granted to anyone to use this software for any purpose, 
9 including commercial applications, and to alter it and redistribute it freely, 
10 subject to the following restrictions:
11
12 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.
13 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
14 3. This notice may not be removed or altered from any source distribution.
15 */
16
17 #ifndef B3_CONTACT_CACHE_H
18 #define B3_CONTACT_CACHE_H
19
20 #include "Bullet3Common/b3Vector3.h"
21 #include "Bullet3Common/b3Transform.h"
22 #include "Bullet3Common/b3AlignedAllocator.h"
23
24 ///maximum contact breaking and merging threshold
25 extern b3Scalar gContactBreakingThreshold;
26
27 #define MANIFOLD_CACHE_SIZE 4
28
29 ///b3ContactCache is a contact point cache, it stays persistent as long as objects are overlapping in the broadphase.
30 ///Those contact points are created by the collision narrow phase.
31 ///The cache can be empty, or hold 1,2,3 or 4 points. Some collision algorithms (GJK) might only add one point at a time.
32 ///updates/refreshes old contact points, and throw them away if necessary (distance becomes too large)
33 ///reduces the cache to 4 points, when more then 4 points are added, using following rules:
34 ///the contact point with deepest penetration is always kept, and it tries to maximuze the area covered by the points
35 ///note that some pairs of objects might have more then one contact manifold.
36 B3_ATTRIBUTE_ALIGNED16(class)
37 b3ContactCache
38 {
39         /// sort cached points so most isolated points come first
40         int sortCachedPoints(const b3Vector3& pt);
41
42 public:
43         B3_DECLARE_ALIGNED_ALLOCATOR();
44
45         int addManifoldPoint(const b3Vector3& newPoint);
46
47         /*void replaceContactPoint(const b3Vector3& newPoint,int insertIndex)
48         {
49                 b3Assert(validContactDistance(newPoint));
50                 m_pointCache[insertIndex] = newPoint;
51         }
52         */
53
54         static bool validContactDistance(const b3Vector3& pt);
55
56         /// calculated new worldspace coordinates and depth, and reject points that exceed the collision margin
57         static void refreshContactPoints(const b3Transform& trA, const b3Transform& trB, struct b3Contact4Data& newContactCache);
58
59         static void removeContactPoint(struct b3Contact4Data & newContactCache, int i);
60 };
61
62 #endif  //B3_CONTACT_CACHE_H