Normand Briere
2016-02-27 28ab4dad99d24372ea58b09a00eafbce1291c278
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
 * Java port of Bullet (c) 2008 Martin Dvorak <jezek2@advel.cz>
 *
 * Bullet Continuous Collision Detection and Physics Library
 * Copyright (c) 2003-2008 Erwin Coumans  http://www.bulletphysics.com/
 *
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from
 * the use of this software.
 * 
 * Permission is granted to anyone to use this software for any purpose, 
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 * 
 * 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.
 * 2. Altered source versions must be plainly marked as such, and must not be
 *    misrepresented as being the original software.
 * 3. This notice may not be removed or altered from any source distribution.
 */
 
package com.bulletphysics.collision.dispatch;
 
import com.bulletphysics.collision.broadphase.BroadphaseNativeType;
import com.bulletphysics.collision.narrowphase.ConvexPenetrationDepthSolver;
import com.bulletphysics.collision.narrowphase.GjkEpaPenetrationDepthSolver;
import com.bulletphysics.collision.narrowphase.VoronoiSimplexSolver;
import com.bulletphysics.extras.gimpact.GImpactCollisionAlgorithm;
import static com.bulletphysics.collision.broadphase.BroadphaseNativeType.*;
 
/**
 * Default implementation of {@link CollisionConfiguration}. Provides all core
 * collision algorithms. Some extra algorithms (like {@link GImpactCollisionAlgorithm GImpact})
 * must be registered manually by calling appropriate register method.
 * 
 * @author jezek2
 */
public class DefaultCollisionConfiguration extends CollisionConfiguration {
 
   //default simplex/penetration depth solvers
   protected VoronoiSimplexSolver simplexSolver;
   protected ConvexPenetrationDepthSolver pdSolver;
   
   //default CreationFunctions, filling the m_doubleDispatch table
   protected CollisionAlgorithmCreateFunc convexConvexCreateFunc;
   protected CollisionAlgorithmCreateFunc convexConcaveCreateFunc;
   protected CollisionAlgorithmCreateFunc swappedConvexConcaveCreateFunc;
   protected CollisionAlgorithmCreateFunc compoundCreateFunc;
   protected CollisionAlgorithmCreateFunc swappedCompoundCreateFunc;
   protected CollisionAlgorithmCreateFunc emptyCreateFunc;
   protected CollisionAlgorithmCreateFunc sphereSphereCF;
   protected CollisionAlgorithmCreateFunc sphereBoxCF;
   protected CollisionAlgorithmCreateFunc boxSphereCF;
   protected CollisionAlgorithmCreateFunc boxBoxCF;
   protected CollisionAlgorithmCreateFunc sphereTriangleCF;
   protected CollisionAlgorithmCreateFunc triangleSphereCF;
   protected CollisionAlgorithmCreateFunc planeConvexCF;
   protected CollisionAlgorithmCreateFunc convexPlaneCF;
   
   public DefaultCollisionConfiguration() {
       simplexSolver = new VoronoiSimplexSolver();
   
       //#define USE_EPA 1
       //#ifdef USE_EPA
       pdSolver = new GjkEpaPenetrationDepthSolver();
       //#else
       //pdSolver = new MinkowskiPenetrationDepthSolver();
       //#endif//USE_EPA    
 
       /*
       //default CreationFunctions, filling the m_doubleDispatch table
       */
       convexConvexCreateFunc = new ConvexConvexAlgorithm.CreateFunc(simplexSolver, pdSolver);
       convexConcaveCreateFunc = new ConvexConcaveCollisionAlgorithm.CreateFunc();
       swappedConvexConcaveCreateFunc = new ConvexConcaveCollisionAlgorithm.SwappedCreateFunc();
       compoundCreateFunc = new CompoundCollisionAlgorithm.CreateFunc();
       swappedCompoundCreateFunc = new CompoundCollisionAlgorithm.SwappedCreateFunc();
       emptyCreateFunc = new EmptyAlgorithm.CreateFunc();
 
       sphereSphereCF = new SphereSphereCollisionAlgorithm.CreateFunc();
       /*
       m_sphereBoxCF = new(mem) btSphereBoxCollisionAlgorithm::CreateFunc;
       m_boxSphereCF = new (mem)btSphereBoxCollisionAlgorithm::CreateFunc;
       m_boxSphereCF->m_swapped = true;
       m_sphereTriangleCF = new (mem)btSphereTriangleCollisionAlgorithm::CreateFunc;
       m_triangleSphereCF = new (mem)btSphereTriangleCollisionAlgorithm::CreateFunc;
       m_triangleSphereCF->m_swapped = true;
 
       mem = btAlignedAlloc(sizeof(btBoxBoxCollisionAlgorithm::CreateFunc),16);
       m_boxBoxCF = new(mem)btBoxBoxCollisionAlgorithm::CreateFunc;
       */
 
       // convex versus plane
       convexPlaneCF = new ConvexPlaneCollisionAlgorithm.CreateFunc();
       planeConvexCF = new ConvexPlaneCollisionAlgorithm.CreateFunc();
       planeConvexCF.swapped = true;
 
       /*
       ///calculate maximum element size, big enough to fit any collision algorithm in the memory pool
       int maxSize = sizeof(btConvexConvexAlgorithm);
       int maxSize2 = sizeof(btConvexConcaveCollisionAlgorithm);
       int maxSize3 = sizeof(btCompoundCollisionAlgorithm);
       int maxSize4 = sizeof(btEmptyAlgorithm);
 
       int    collisionAlgorithmMaxElementSize = btMax(maxSize,maxSize2);
       collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize3);
       collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize4);
 
       if (stackAlloc)
       {
           m_ownsStackAllocator = false;
           this->m_stackAlloc = stackAlloc;
       } else
       {
           m_ownsStackAllocator = true;
           void* mem = btAlignedAlloc(sizeof(btStackAlloc),16);
           m_stackAlloc = new(mem)btStackAlloc(DEFAULT_STACK_ALLOCATOR_SIZE);
       }
 
       if (persistentManifoldPool)
       {
           m_ownsPersistentManifoldPool = false;
           m_persistentManifoldPool = persistentManifoldPool;
       } else
       {
           m_ownsPersistentManifoldPool = true;
           void* mem = btAlignedAlloc(sizeof(btPoolAllocator),16);
           m_persistentManifoldPool = new (mem) btPoolAllocator(sizeof(btPersistentManifold),DEFAULT_MAX_OVERLAPPING_PAIRS);
       }
 
       if (collisionAlgorithmPool)
       {
           m_ownsCollisionAlgorithmPool = false;
           m_collisionAlgorithmPool = collisionAlgorithmPool;
       } else
       {
           m_ownsCollisionAlgorithmPool = true;
           void* mem = btAlignedAlloc(sizeof(btPoolAllocator),16);
           m_collisionAlgorithmPool = new(mem) btPoolAllocator(collisionAlgorithmMaxElementSize,DEFAULT_MAX_OVERLAPPING_PAIRS);
       }
       */
   }
   
   @Override
   public CollisionAlgorithmCreateFunc getCollisionAlgorithmCreateFunc(BroadphaseNativeType proxyType0, BroadphaseNativeType proxyType1) {
       if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE)) {
           return sphereSphereCF;
       }
 
       /*
       if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1==BOX_SHAPE_PROXYTYPE))
       {
           return    m_sphereBoxCF;
       }
 
       if ((proxyType0 == BOX_SHAPE_PROXYTYPE ) && (proxyType1==SPHERE_SHAPE_PROXYTYPE))
       {
           return    m_boxSphereCF;
       }
 
       if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE ) && (proxyType1==TRIANGLE_SHAPE_PROXYTYPE))
       {
           return    m_sphereTriangleCF;
       }
 
       if ((proxyType0 == TRIANGLE_SHAPE_PROXYTYPE  ) && (proxyType1==SPHERE_SHAPE_PROXYTYPE))
       {
           return    m_triangleSphereCF;
       }
 
       if ((proxyType0 == BOX_SHAPE_PROXYTYPE) && (proxyType1 == BOX_SHAPE_PROXYTYPE)) {
           return boxBoxCF;
       }
       */
 
       if (proxyType0.isConvex() && (proxyType1 == STATIC_PLANE_PROXYTYPE))
       {
           return convexPlaneCF;
       }
 
       if (proxyType1.isConvex() && (proxyType0 == STATIC_PLANE_PROXYTYPE))
       {
           return planeConvexCF;
       }
 
       if (proxyType0.isConvex() && proxyType1.isConvex()) {
           return convexConvexCreateFunc;
       }
 
       if (proxyType0.isConvex() && proxyType1.isConcave()) {
           return convexConcaveCreateFunc;
       }
 
       if (proxyType1.isConvex() && proxyType0.isConcave()) {
           return swappedConvexConcaveCreateFunc;
       }
 
       if (proxyType0.isCompound()) {
           return compoundCreateFunc;
       }
       else {
           if (proxyType1.isCompound()) {
               return swappedCompoundCreateFunc;
           }
       }
 
       // failed to find an algorithm
       return emptyCreateFunc;
   }
 
}