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

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

btVoronoiSimplexSolver.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#ifndef BT_VORONOI_SIMPLEX_SOLVER_H
17#define BT_VORONOI_SIMPLEX_SOLVER_H
18
19#include "btSimplexSolverInterface.h"
20
21#define VORONOI_SIMPLEX_MAX_VERTS 5
22
24#define BT_USE_EQUAL_VERTEX_THRESHOLD
25
26#ifdef BT_USE_DOUBLE_PRECISION
27#define VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD 1e-12f
28#else
29#define VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD 0.0001f
30#endif //BT_USE_DOUBLE_PRECISION
31
32 struct btUsageBitfield
33{
34 btUsageBitfield()
35 {
36 reset();
37 }
38
39 void reset()
40 {
41 usedVertexA = false;
42 usedVertexB = false;
43 usedVertexC = false;
44 usedVertexD = false;
45 }
46 unsigned short usedVertexA : 1;
47 unsigned short usedVertexB : 1;
48 unsigned short usedVertexC : 1;
49 unsigned short usedVertexD : 1;
50 unsigned short unused1 : 1;
51 unsigned short unused2 : 1;
52 unsigned short unused3 : 1;
53 unsigned short unused4 : 1;
54};
55
56 struct btSubSimplexClosestResult
57{
58 btVector3 m_closestPointOnSimplex;
59 //MASK for m_usedVertices
60 //stores the simplex vertex-usage, using the MASK,
61 // if m_usedVertices & MASK then the related vertex is used
62 btUsageBitfield m_usedVertices;
63 btScalar m_barycentricCoords[4];
64 bool m_degenerate;
65
66 void reset()
67 {
68 m_degenerate = false;
69 setBarycentricCoordinates();
70 m_usedVertices.reset();
71 }
72 bool isValid()
73 {
74 bool valid = (m_barycentricCoords[0] >= btScalar(0.)) &&
75 (m_barycentricCoords[1] >= btScalar(0.)) &&
76 (m_barycentricCoords[2] >= btScalar(0.)) &&
77 (m_barycentricCoords[3] >= btScalar(0.));
78
79 return valid;
80 }
81 void setBarycentricCoordinates(btScalar a = btScalar(0.), btScalar b = btScalar(0.), btScalar c = btScalar(0.), btScalar d = btScalar(0.))
82 {
83 m_barycentricCoords[0] = a;
84 m_barycentricCoords[1] = b;
85 m_barycentricCoords[2] = c;
86 m_barycentricCoords[3] = d;
87 }
88};
89
92#ifdef NO_VIRTUAL_INTERFACE
93 ATTRIBUTE_ALIGNED16(class)
94 btVoronoiSimplexSolver
95#else
96 ATTRIBUTE_ALIGNED16(class)
97 btVoronoiSimplexSolver : public btSimplexSolverInterface
98#endif
99{
100public:
101 BT_DECLARE_ALIGNED_ALLOCATOR();
102
103 int m_numVertices;
104
105 btVector3 m_simplexVectorW[VORONOI_SIMPLEX_MAX_VERTS];
106 btVector3 m_simplexPointsP[VORONOI_SIMPLEX_MAX_VERTS];
107 btVector3 m_simplexPointsQ[VORONOI_SIMPLEX_MAX_VERTS];
108
109 btVector3 m_cachedP1;
110 btVector3 m_cachedP2;
111 btVector3 m_cachedV;
112 btVector3 m_lastW;
113
114 btScalar m_equalVertexThreshold;
115 bool m_cachedValidClosest;
116
117 btSubSimplexClosestResult m_cachedBC;
118
119 bool m_needsUpdate;
120
121 void removeVertex(int index);
122 void reduceVertices(const btUsageBitfield& usedVerts);
123 bool updateClosestVectorAndPoints();
124
125 bool closestPtPointTetrahedron(const btVector3& p, const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& d, btSubSimplexClosestResult& finalResult);
126 int pointOutsideOfPlane(const btVector3& p, const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& d);
127 bool closestPtPointTriangle(const btVector3& p, const btVector3& a, const btVector3& b, const btVector3& c, btSubSimplexClosestResult& result);
128
129public:
130 btVoronoiSimplexSolver()
131 : m_equalVertexThreshold(VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD)
132 {
133 }
134 void reset();
135
136 void addVertex(const btVector3& w, const btVector3& p, const btVector3& q);
137
138 void setEqualVertexThreshold(btScalar threshold)
139 {
140 m_equalVertexThreshold = threshold;
141 }
142
143 btScalar getEqualVertexThreshold() const
144 {
145 return m_equalVertexThreshold;
146 }
147
148 bool closest(btVector3 & v);
149
150 btScalar maxVertex();
151
152 bool fullSimplex() const
153 {
154 return (m_numVertices == 4);
155 }
156
157 int getSimplex(btVector3 * pBuf, btVector3 * qBuf, btVector3 * yBuf) const;
158
159 bool inSimplex(const btVector3& w);
160
161 void backup_closest(btVector3 & v);
162
163 bool emptySimplex() const;
164
165 void compute_points(btVector3 & p1, btVector3 & p2);
166
167 int numVertices() const
168 {
169 return m_numVertices;
170 }
171};
172
173#endif //BT_VORONOI_SIMPLEX_SOLVER_H
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition btScalar.h:99
btSimplexSolverInterface.h
btSimplexSolverInterface
#define btSimplexSolverInterface
Definition btSimplexSolverInterface.h:24
VORONOI_SIMPLEX_MAX_VERTS
#define VORONOI_SIMPLEX_MAX_VERTS
Definition btVoronoiSimplexSolver.h:21
VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD
#define VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD
Definition btVoronoiSimplexSolver.h:29
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
btVoronoiSimplexSolver
btVoronoiSimplexSolver is an implementation of the closest point distance algorithm from a 1-4 points...
Definition btVoronoiSimplexSolver.h:99
btVoronoiSimplexSolver::m_numVertices
int m_numVertices
Definition btVoronoiSimplexSolver.h:103
btVoronoiSimplexSolver::fullSimplex
bool fullSimplex() const
Definition btVoronoiSimplexSolver.h:152
btVoronoiSimplexSolver::m_lastW
btVector3 m_lastW
Definition btVoronoiSimplexSolver.h:112
btVoronoiSimplexSolver::m_cachedBC
btSubSimplexClosestResult m_cachedBC
Definition btVoronoiSimplexSolver.h:117
btVoronoiSimplexSolver::BT_DECLARE_ALIGNED_ALLOCATOR
BT_DECLARE_ALIGNED_ALLOCATOR()
btVoronoiSimplexSolver::numVertices
int numVertices() const
Definition btVoronoiSimplexSolver.h:167
btVoronoiSimplexSolver::m_cachedValidClosest
bool m_cachedValidClosest
Definition btVoronoiSimplexSolver.h:115
btVoronoiSimplexSolver::m_needsUpdate
bool m_needsUpdate
Definition btVoronoiSimplexSolver.h:119
btVoronoiSimplexSolver::getEqualVertexThreshold
btScalar getEqualVertexThreshold() const
Definition btVoronoiSimplexSolver.h:143
btVoronoiSimplexSolver::btVoronoiSimplexSolver
btVoronoiSimplexSolver()
Definition btVoronoiSimplexSolver.h:130
btVoronoiSimplexSolver::m_cachedP1
btVector3 m_cachedP1
Definition btVoronoiSimplexSolver.h:109
btVoronoiSimplexSolver::m_equalVertexThreshold
btScalar m_equalVertexThreshold
Definition btVoronoiSimplexSolver.h:114
btVoronoiSimplexSolver::m_cachedP2
btVector3 m_cachedP2
Definition btVoronoiSimplexSolver.h:110
btVoronoiSimplexSolver::m_cachedV
btVector3 m_cachedV
Definition btVoronoiSimplexSolver.h:111
btVoronoiSimplexSolver::setEqualVertexThreshold
void setEqualVertexThreshold(btScalar threshold)
Definition btVoronoiSimplexSolver.h:138
btSubSimplexClosestResult
Definition btVoronoiSimplexSolver.h:57
btSubSimplexClosestResult::isValid
bool isValid()
Definition btVoronoiSimplexSolver.h:72
btSubSimplexClosestResult::reset
void reset()
Definition btVoronoiSimplexSolver.h:66
btSubSimplexClosestResult::setBarycentricCoordinates
void setBarycentricCoordinates(btScalar a=btScalar(0.), btScalar b=btScalar(0.), btScalar c=btScalar(0.), btScalar d=btScalar(0.))
Definition btVoronoiSimplexSolver.h:81
btSubSimplexClosestResult::m_degenerate
bool m_degenerate
Definition btVoronoiSimplexSolver.h:64
btSubSimplexClosestResult::m_usedVertices
btUsageBitfield m_usedVertices
Definition btVoronoiSimplexSolver.h:62
btSubSimplexClosestResult::m_barycentricCoords
btScalar m_barycentricCoords[4]
Definition btVoronoiSimplexSolver.h:63
btSubSimplexClosestResult::m_closestPointOnSimplex
btVector3 m_closestPointOnSimplex
Definition btVoronoiSimplexSolver.h:58
btUsageBitfield
Definition btVoronoiSimplexSolver.h:33
btUsageBitfield::usedVertexC
unsigned short usedVertexC
Definition btVoronoiSimplexSolver.h:48
btUsageBitfield::usedVertexB
unsigned short usedVertexB
Definition btVoronoiSimplexSolver.h:47
btUsageBitfield::unused4
unsigned short unused4
Definition btVoronoiSimplexSolver.h:53
btUsageBitfield::reset
void reset()
Definition btVoronoiSimplexSolver.h:39
btUsageBitfield::usedVertexA
unsigned short usedVertexA
Definition btVoronoiSimplexSolver.h:46
btUsageBitfield::unused1
unsigned short unused1
Definition btVoronoiSimplexSolver.h:50
btUsageBitfield::unused3
unsigned short unused3
Definition btVoronoiSimplexSolver.h:52
btUsageBitfield::unused2
unsigned short unused2
Definition btVoronoiSimplexSolver.h:51
btUsageBitfield::btUsageBitfield
btUsageBitfield()
Definition btVoronoiSimplexSolver.h:34
btUsageBitfield::usedVertexD
unsigned short usedVertexD
Definition btVoronoiSimplexSolver.h:49