btVoronoiSimplexSolver.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef btVoronoiSimplexSolver_H
00019 #define btVoronoiSimplexSolver_H
00020
00021 #include "btSimplexSolverInterface.h"
00022
00023
00024
00025 #define VORONOI_SIMPLEX_MAX_VERTS 5
00026
00027 struct btUsageBitfield{
00028 btUsageBitfield()
00029 {
00030 reset();
00031 }
00032
00033 void reset()
00034 {
00035 usedVertexA = false;
00036 usedVertexB = false;
00037 usedVertexC = false;
00038 usedVertexD = false;
00039 }
00040 unsigned short usedVertexA : 1;
00041 unsigned short usedVertexB : 1;
00042 unsigned short usedVertexC : 1;
00043 unsigned short usedVertexD : 1;
00044 unsigned short unused1 : 1;
00045 unsigned short unused2 : 1;
00046 unsigned short unused3 : 1;
00047 unsigned short unused4 : 1;
00048 };
00049
00050
00051 struct btSubSimplexClosestResult
00052 {
00053 btVector3 m_closestPointOnSimplex;
00054
00055
00056
00057 btUsageBitfield m_usedVertices;
00058 btScalar m_barycentricCoords[4];
00059 bool m_degenerate;
00060
00061 void reset()
00062 {
00063 m_degenerate = false;
00064 setBarycentricCoordinates();
00065 m_usedVertices.reset();
00066 }
00067 bool isValid()
00068 {
00069 bool valid = (m_barycentricCoords[0] >= btScalar(0.)) &&
00070 (m_barycentricCoords[1] >= btScalar(0.)) &&
00071 (m_barycentricCoords[2] >= btScalar(0.)) &&
00072 (m_barycentricCoords[3] >= btScalar(0.));
00073
00074
00075 return valid;
00076 }
00077 void setBarycentricCoordinates(btScalar a=btScalar(0.),btScalar b=btScalar(0.),btScalar c=btScalar(0.),btScalar d=btScalar(0.))
00078 {
00079 m_barycentricCoords[0] = a;
00080 m_barycentricCoords[1] = b;
00081 m_barycentricCoords[2] = c;
00082 m_barycentricCoords[3] = d;
00083 }
00084
00085 };
00086
00089 #ifdef NO_VIRTUAL_INTERFACE
00090 class btVoronoiSimplexSolver
00091 #else
00092 class btVoronoiSimplexSolver : public btSimplexSolverInterface
00093 #endif
00094 {
00095 public:
00096
00097 int m_numVertices;
00098
00099 btVector3 m_simplexVectorW[VORONOI_SIMPLEX_MAX_VERTS];
00100 btVector3 m_simplexPointsP[VORONOI_SIMPLEX_MAX_VERTS];
00101 btVector3 m_simplexPointsQ[VORONOI_SIMPLEX_MAX_VERTS];
00102
00103
00104
00105 btVector3 m_cachedP1;
00106 btVector3 m_cachedP2;
00107 btVector3 m_cachedV;
00108 btVector3 m_lastW;
00109 bool m_cachedValidClosest;
00110
00111 btSubSimplexClosestResult m_cachedBC;
00112
00113 bool m_needsUpdate;
00114
00115 void removeVertex(int index);
00116 void reduceVertices (const btUsageBitfield& usedVerts);
00117 bool updateClosestVectorAndPoints();
00118
00119 bool closestPtPointTetrahedron(const btVector3& p, const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& d, btSubSimplexClosestResult& finalResult);
00120 int pointOutsideOfPlane(const btVector3& p, const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& d);
00121 bool closestPtPointTriangle(const btVector3& p, const btVector3& a, const btVector3& b, const btVector3& c,btSubSimplexClosestResult& result);
00122
00123 public:
00124
00125 void reset();
00126
00127 void addVertex(const btVector3& w, const btVector3& p, const btVector3& q);
00128
00129
00130 bool closest(btVector3& v);
00131
00132 btScalar maxVertex();
00133
00134 bool fullSimplex() const
00135 {
00136 return (m_numVertices == 4);
00137 }
00138
00139 int getSimplex(btVector3 *pBuf, btVector3 *qBuf, btVector3 *yBuf) const;
00140
00141 bool inSimplex(const btVector3& w);
00142
00143 void backup_closest(btVector3& v) ;
00144
00145 bool emptySimplex() const ;
00146
00147 void compute_points(btVector3& p1, btVector3& p2) ;
00148
00149 int numVertices() const
00150 {
00151 return m_numVertices;
00152 }
00153
00154
00155 };
00156
00157 #endif //VoronoiSimplexSolver