Back to index

supertuxkart  0.5+dfsg1
btVoronoiSimplexSolver.h
Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 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.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
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        btPoint3      m_closestPointOnSimplex;
00054        //MASK for m_usedVertices
00055        //stores the simplex vertex-usage, using the MASK, 
00056        // if m_usedVertices & MASK then the related vertex is used
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        btPoint3      m_simplexPointsP[VORONOI_SIMPLEX_MAX_VERTS];
00101        btPoint3      m_simplexPointsQ[VORONOI_SIMPLEX_MAX_VERTS];
00102 
00103        
00104 
00105        btPoint3      m_cachedP1;
00106        btPoint3      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 btPoint3& p, const btPoint3& a, const btPoint3& b, const btPoint3& c, const btPoint3& d, btSubSimplexClosestResult& finalResult);
00120        int           pointOutsideOfPlane(const btPoint3& p, const btPoint3& a, const btPoint3& b, const btPoint3& c, const btPoint3& d);
00121        bool   closestPtPointTriangle(const btPoint3& p, const btPoint3& a, const btPoint3& b, const btPoint3& c,btSubSimplexClosestResult& result);
00122 
00123 public:
00124 
00125         void reset();
00126 
00127         void addVertex(const btVector3& w, const btPoint3& p, const btPoint3& 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(btPoint3 *pBuf, btPoint3 *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(btPoint3& p1, btPoint3& p2) ;
00148 
00149         int numVertices() const 
00150         {
00151                return m_numVertices;
00152         }
00153 
00154 
00155 };
00156 
00157 #endif //VoronoiSimplexSolver