Advertisement
Guest User

Untitled

a guest
Nov 14th, 2016
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. /*
  2. * Author: Irlan Robson
  3. * http://irlans.wordpress.com
  4. * Description: An implemetation of the GJK-SAT algorithm in 3D.
  5. */
  6.  
  7. #ifndef __GJK_H__
  8. #define __GJK_H__
  9.  
  10. #include "..\IRMathLib\CVector3.h"
  11. #include "CShapeInstance.h"
  12. #include "CPolyhedron.h"
  13.  
  14. #ifndef GJK_ITERATIONS
  15. #define GJK_ITERATIONS 20UL
  16. #endif //#define GJK_ITERATIONS
  17.  
  18. class CGjk {
  19.     friend class CEpa;
  20. public :
  21.     struct SIMPLEX_VERTEX {
  22.         unsigned int ui32SupA;
  23.         unsigned int ui32SupB;
  24.         CVector3 vSupA;
  25.         CVector3 vSupB;
  26.         CVector3 vMinkSup;
  27.  
  28.         bool operator==(const SIMPLEX_VERTEX& _sOther) const {
  29.             return ui32SupA == _sOther.ui32SupA && ui32SupB == _sOther.ui32SupB;
  30.         }
  31.     };
  32.  
  33.     struct SIMPLEX {
  34.         enum S_SIMPLEX_TYPE {
  35.             ST_POINT,
  36.             ST_EDGE,
  37.             ST_FACE,
  38.             ST_TETRAHEDRON,
  39.             ST_SIMPLEX_TOTALS
  40.         };
  41.  
  42.         SIMPLEX_VERTEX vA;
  43.         SIMPLEX_VERTEX vB;
  44.         SIMPLEX_VERTEX vC;
  45.         SIMPLEX_VERTEX vD;
  46.         S_SIMPLEX_TYPE ssSimplexType;
  47.     };
  48.  
  49.     CGjk();
  50.     ~CGjk();
  51.  
  52.     bool Intersect(const CShapeInstance* _psiLeft, const CShapeInstance* _psiRight);
  53. protected :
  54.     void GetSupportPoint(const CVector3& _vSearchDir, const CShapeInstance* _psiLeft, const CShapeInstance* _psiRight, SIMPLEX_VERTEX& _vRet) const;
  55.     bool UpdateSimplex();
  56.     bool UpdateSimplexTetrahedronFace(const CVector3& _vAo);
  57.  
  58.     bool SimplexEdgeUpdate();
  59.     bool SimplexFaceUpdate();
  60.     bool SimplexTetrahedronUpdate();
  61.  
  62.     typedef bool (CGjk::*SimplexFunc)();
  63.     SimplexFunc m_psfpSimplexUpdateFuncs[SIMPLEX::ST_SIMPLEX_TOTALS];
  64.     SIMPLEX m_sSimplex;
  65.     CVector3 m_vSearchDir;
  66. };
  67.  
  68. #endif //#ifndef __GJK_H__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement