Bullet Collision Detection & Physics Library: btVoronoiSimplexSolver.h Source File

Bullet Collision Detection & Physics Library

btVoronoiSimplexSolver.h
Go to the documentation of this file.
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
18 #ifndef BT_VORONOI_SIMPLEX_SOLVER_H
19 #define BT_VORONOI_SIMPLEX_SOLVER_H
20
21 #include "btSimplexSolverInterface.h"
22
23
24
25 #define VORONOI_SIMPLEX_MAX_VERTS 5
26
28 #define BT_USE_EQUAL_VERTEX_THRESHOLD
29
30 #ifdef BT_USE_DOUBLE_PRECISION
31 #define VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD 1e-12f
32 #else
33 #define VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD 0.0001f
34 #endif//BT_USE_DOUBLE_PRECISION
35
36 struct btUsageBitfield{
37 btUsageBitfield()
38 {
39 reset();
40 }
41
42 void reset()
43 {
44 usedVertexA = false;
45 usedVertexB = false;
46 usedVertexC = false;
47 usedVertexD = false;
48 }
49 unsigned short usedVertexA : 1;
50 unsigned short usedVertexB : 1;
51 unsigned short usedVertexC : 1;
52 unsigned short usedVertexD : 1;
53 unsigned short unused1 : 1;
54 unsigned short unused2 : 1;
55 unsigned short unused3 : 1;
56 unsigned short unused4 : 1;
57 };
58
59
60 struct btSubSimplexClosestResult
61 {
62 btVector3 m_closestPointOnSimplex;
63 //MASK for m_usedVertices
64 //stores the simplex vertex-usage, using the MASK,
65 // if m_usedVertices & MASK then the related vertex is used
66 btUsageBitfield m_usedVertices;
67 btScalar m_barycentricCoords[4];
68 bool m_degenerate;
69
70 void reset()
71 {
72 m_degenerate = false;
73 setBarycentricCoordinates();
74 m_usedVertices.reset();
75 }
76 bool isValid()
77 {
78 bool valid = (m_barycentricCoords[0] >= btScalar(0.)) &&
79 (m_barycentricCoords[1] >= btScalar(0.)) &&
80 (m_barycentricCoords[2] >= btScalar(0.)) &&
81 (m_barycentricCoords[3] >= btScalar(0.));
82
83
84 return valid;
85 }
86 void setBarycentricCoordinates(btScalar a=btScalar(0.),btScalar b=btScalar(0.),btScalar c=btScalar(0.),btScalar d=btScalar(0.))
87 {
88 m_barycentricCoords[0] = a;
89 m_barycentricCoords[1] = b;
90 m_barycentricCoords[2] = c;
91 m_barycentricCoords[3] = d;
92 }
93
94 };
95
98 #ifdef NO_VIRTUAL_INTERFACE
99 ATTRIBUTE_ALIGNED16(class) btVoronoiSimplexSolver
100 #else
101 ATTRIBUTE_ALIGNED16(class) btVoronoiSimplexSolver : public btSimplexSolverInterface
102 #endif
103 {
104 public:
105
106 BT_DECLARE_ALIGNED_ALLOCATOR();
107
108 int m_numVertices;
109
110 btVector3 m_simplexVectorW[VORONOI_SIMPLEX_MAX_VERTS];
111 btVector3 m_simplexPointsP[VORONOI_SIMPLEX_MAX_VERTS];
112 btVector3 m_simplexPointsQ[VORONOI_SIMPLEX_MAX_VERTS];
113
114
115
116 btVector3 m_cachedP1;
117 btVector3 m_cachedP2;
118 btVector3 m_cachedV;
119 btVector3 m_lastW;
120
121 btScalar m_equalVertexThreshold;
122 bool m_cachedValidClosest;
123
124
125 btSubSimplexClosestResult m_cachedBC;
126
127 bool m_needsUpdate;
128
129 void removeVertex(int index);
130 void reduceVertices (const btUsageBitfield& usedVerts);
131 bool updateClosestVectorAndPoints();
132
133 bool closestPtPointTetrahedron(const btVector3& p, const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& d, btSubSimplexClosestResult& finalResult);
134 int pointOutsideOfPlane(const btVector3& p, const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& d);
135 bool closestPtPointTriangle(const btVector3& p, const btVector3& a, const btVector3& b, const btVector3& c,btSubSimplexClosestResult& result);
136
137 public:
138
139 btVoronoiSimplexSolver()
140 : m_equalVertexThreshold(VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD)
141 {
142 }
143 void reset();
144
145 void addVertex(const btVector3& w, const btVector3& p, const btVector3& q);
146
147 void setEqualVertexThreshold(btScalar threshold)
148 {
149 m_equalVertexThreshold = threshold;
150 }
151
152 btScalar getEqualVertexThreshold() const
153 {
154 return m_equalVertexThreshold;
155 }
156
157 bool closest(btVector3& v);
158
159 btScalar maxVertex();
160
161 bool fullSimplex() const
162 {
163 return (m_numVertices == 4);
164 }
165
166 int getSimplex(btVector3 *pBuf, btVector3 *qBuf, btVector3 *yBuf) const;
167
168 bool inSimplex(const btVector3& w);
169
170 void backup_closest(btVector3& v) ;
171
172 bool emptySimplex() const ;
173
174 void compute_points(btVector3& p1, btVector3& p2) ;
175
176 int numVertices() const
177 {
178 return m_numVertices;
179 }
180
181
182 };
183
184 #endif //BT_VORONOI_SIMPLEX_SOLVER_H
185
btUsageBitfield::usedVertexA
unsigned short usedVertexA
Definition: btVoronoiSimplexSolver.h:49
btSubSimplexClosestResult::m_closestPointOnSimplex
btVector3 m_closestPointOnSimplex
Definition: btVoronoiSimplexSolver.h:62
btSubSimplexClosestResult::reset
void reset()
Definition: btVoronoiSimplexSolver.h:70
btUsageBitfield::usedVertexD
unsigned short usedVertexD
Definition: btVoronoiSimplexSolver.h:52
btUsageBitfield
Definition: btVoronoiSimplexSolver.h:36
btUsageBitfield::unused3
unsigned short unused3
Definition: btVoronoiSimplexSolver.h:55
btVoronoiSimplexSolver::fullSimplex
bool fullSimplex() const
Definition: btVoronoiSimplexSolver.h:161
btSubSimplexClosestResult
Definition: btVoronoiSimplexSolver.h:60
btUsageBitfield::reset
void reset()
Definition: btVoronoiSimplexSolver.h:42
VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD
#define VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD
Definition: btVoronoiSimplexSolver.h:33
btUsageBitfield::usedVertexB
unsigned short usedVertexB
Definition: btVoronoiSimplexSolver.h:50
btSubSimplexClosestResult::isValid
bool isValid()
Definition: btVoronoiSimplexSolver.h:76
btVoronoiSimplexSolver::m_cachedV
btVector3 m_cachedV
Definition: btVoronoiSimplexSolver.h:118
btVoronoiSimplexSolver::m_lastW
btVector3 m_lastW
Definition: btVoronoiSimplexSolver.h:119
btVoronoiSimplexSolver::m_equalVertexThreshold
btScalar m_equalVertexThreshold
Definition: btVoronoiSimplexSolver.h:121
btVoronoiSimplexSolver::m_cachedValidClosest
bool m_cachedValidClosest
Definition: btVoronoiSimplexSolver.h:122
btVoronoiSimplexSolver::m_numVertices
int m_numVertices
Definition: btVoronoiSimplexSolver.h:108
btSimplexSolverInterface
#define btSimplexSolverInterface
Definition: btSimplexSolverInterface.h:26
btVoronoiSimplexSolver
btVoronoiSimplexSolver is an implementation of the closest point distance algorithm from a 1-4 points...
Definition: btVoronoiSimplexSolver.h:99
btVoronoiSimplexSolver::setEqualVertexThreshold
void setEqualVertexThreshold(btScalar threshold)
Definition: btVoronoiSimplexSolver.h:147
btSubSimplexClosestResult::setBarycentricCoordinates
void setBarycentricCoordinates(btScalar a=btScalar(0.), btScalar b=btScalar(0.), btScalar c=btScalar(0.), btScalar d=btScalar(0.))
Definition: btVoronoiSimplexSolver.h:86
btUsageBitfield::unused2
unsigned short unused2
Definition: btVoronoiSimplexSolver.h:54
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:82
btVoronoiSimplexSolver::m_needsUpdate
bool m_needsUpdate
Definition: btVoronoiSimplexSolver.h:127
btVoronoiSimplexSolver::m_cachedBC
btSubSimplexClosestResult m_cachedBC
Definition: btVoronoiSimplexSolver.h:125
btVoronoiSimplexSolver::numVertices
int numVertices() const
Definition: btVoronoiSimplexSolver.h:176
btUsageBitfield::unused4
unsigned short unused4
Definition: btVoronoiSimplexSolver.h:56
btUsageBitfield::unused1
unsigned short unused1
Definition: btVoronoiSimplexSolver.h:53
BT_DECLARE_ALIGNED_ALLOCATOR
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:403
btUsageBitfield::usedVertexC
unsigned short usedVertexC
Definition: btVoronoiSimplexSolver.h:51
btVoronoiSimplexSolver::btVoronoiSimplexSolver
btVoronoiSimplexSolver()
Definition: btVoronoiSimplexSolver.h:139
btSubSimplexClosestResult::m_usedVertices
btUsageBitfield m_usedVertices
Definition: btVoronoiSimplexSolver.h:66
btVoronoiSimplexSolver::m_cachedP1
btVector3 m_cachedP1
Definition: btVoronoiSimplexSolver.h:116
VORONOI_SIMPLEX_MAX_VERTS
#define VORONOI_SIMPLEX_MAX_VERTS
Definition: btVoronoiSimplexSolver.h:25
btVoronoiSimplexSolver::getEqualVertexThreshold
btScalar getEqualVertexThreshold() const
Definition: btVoronoiSimplexSolver.h:152
btSimplexSolverInterface.h
btVoronoiSimplexSolver::m_cachedP2
btVector3 m_cachedP2
Definition: btVoronoiSimplexSolver.h:117
btUsageBitfield::btUsageBitfield
btUsageBitfield()
Definition: btVoronoiSimplexSolver.h:37
btSubSimplexClosestResult::m_degenerate
bool m_degenerate
Definition: btVoronoiSimplexSolver.h:68
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292