Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
4.2 KiB

  1. //--------------------------------------------------------------------------------------------------
  2. /**
  3. @file qhConvex.h
  4. @author Dirk Gregorius
  5. @version 0.1
  6. @date 30/11/2011
  7. Copyright(C) 2011 by D. Gregorius. All rights reserved.
  8. */
  9. //--------------------------------------------------------------------------------------------------
  10. #pragma once
  11. #include "qhTypes.h"
  12. #include "qhMath.h"
  13. #include "qhArray.h"
  14. #include "qhList.h"
  15. #include "qhHalfEdge.h"
  16. #include "qhMass.h"
  17. //--------------------------------------------------------------------------------------------------
  18. // qhMesh
  19. //--------------------------------------------------------------------------------------------------
  20. struct qhMesh
  21. {
  22. qhArray< qhVector3 > Vertices; // Vertices
  23. qhArray< qhVector3 > Normals; // *Face* normals
  24. qhArray< int > Faces; // Index count for each face
  25. qhArray< int > Indices; // Face indices into vertex array
  26. };
  27. //--------------------------------------------------------------------------------------------------
  28. // qhIteration
  29. //--------------------------------------------------------------------------------------------------
  30. struct qhIteration
  31. {
  32. qhVector3 Apex;
  33. qhArray< qhVector3 > Horizon;
  34. qhArray< qhVector3 > Vertices;
  35. qhArray< int > Faces;
  36. };
  37. //--------------------------------------------------------------------------------------------------
  38. // qhConvex
  39. //--------------------------------------------------------------------------------------------------
  40. class qhConvex
  41. {
  42. public:
  43. // Construction / Destruction
  44. qhConvex( void );
  45. ~qhConvex( void );
  46. void Construct( int VertexCount, const qhVector3* VertexBase, qhReal RelativeWeldTolerance );
  47. void Construct( int PlaneCount, const qhPlane* PlaneBase, qhReal RelativeWeldTolerance, const qhVector3& InternalPoint = QH_VEC3_ZERO );
  48. bool IsConsistent( void ) const;
  49. void Simplify( qhConvex& Convex, qhReal MaxAngle ) const;
  50. // Accessors / Mutators
  51. qhVector3 GetCentroid( void ) const;
  52. int GetVertexCount( void ) const;
  53. int GetEdgeCount( void ) const;
  54. int GetFaceCount( void ) const;
  55. const qhList< qhVertex >& GetVertexList( void ) const;
  56. const qhList< qhFace >& GetFaceList( void ) const;
  57. // Polygonal mesh for rendering
  58. void GetMesh( qhMesh& Mesh ) const;
  59. // Mass properties (relative to origin)
  60. qhMass ComputeMass( qhReal Density = qhReal( 1 ) ) const;
  61. // Debug information
  62. int GetIterationCount( void ) const;
  63. const qhIteration& GetIteration( int Index ) const;
  64. private:
  65. // Memory management
  66. qhVertex* CreateVertex( const qhVector3& Position );
  67. void DestroyVertex( qhVertex* Vertex );
  68. qhFace* CreateFace( qhVertex* Vertex1, qhVertex* Vertex2, qhVertex* Vertex3 );
  69. void DestroyFace( qhFace* Face );
  70. // Implementation
  71. void ComputeTolerance( qhArray< qhVector3 >& Vertices );
  72. bool BuildInitialHull( int VertexCount, const qhVector3* VertexBase );
  73. qhVertex* NextConflictVertex( void );
  74. void AddVertexToHull( qhVertex* Vertex );
  75. void AddIteration( qhVertex* Apex, const qhArray< qhHalfEdge* >& Horizon, const qhList< qhFace >& FaceList );
  76. void CleanHull( void );
  77. void ShiftHull( const qhVector3& Translation );
  78. void BuildHorizon( qhArray< qhHalfEdge* >& Horizon, qhVertex* Apex, qhFace* Seed, qhHalfEdge* Edge1 = NULL );
  79. void BuildCone( qhArray< qhFace* >& Cone, const qhArray< qhHalfEdge* >& Horizon, qhVertex* Apex );
  80. void MergeFaces( qhArray< qhFace* >& Cone );
  81. void ResolveVertices( qhArray< qhFace* >& Cone );
  82. void ResolveFaces( qhArray< qhFace* >& Cone );
  83. bool FirstPass( qhFace* Face );
  84. bool SecondPass( qhFace* Face );
  85. void ConnectFaces( qhHalfEdge* Edge );
  86. void ConnectEdges( qhHalfEdge* Prev, qhHalfEdge* Next, qhArray< qhFace* >& MergedFaces );
  87. void DestroyEdges( qhHalfEdge* Begin, qhHalfEdge* End );
  88. void AbsorbFaces( qhFace* Face, qhArray< qhFace* >& MergedFaces );
  89. // Data members
  90. qhReal mTolerance;
  91. qhReal mMinRadius;
  92. qhReal mMinOutside;
  93. qhVector3 mInteriorPoint;
  94. qhList< qhVertex > mOrphanedList;
  95. qhList< qhVertex > mVertexList;
  96. qhList< qhFace > mFaceList;
  97. qhArray< qhIteration > mIterations;
  98. // Non-copyable
  99. qhConvex( const qhConvex& );
  100. qhConvex& operator=( const qhConvex& );
  101. };
  102. #include "qhConvex.inl"