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.

244 lines
6.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef SUBDIV_H
  8. #define SUBDIV_H
  9. #pragma once
  10. class CMapDisp;
  11. class CSubdivEdge;
  12. class CSubdivQuad;
  13. //=============================================================================
  14. //
  15. // Class Subdivision Point
  16. //
  17. class CSubdivPoint
  18. {
  19. public:
  20. enum { POINT_ORDINARY = 0,
  21. POINT_CORNER = 1,
  22. POINT_CREASE = 2 };
  23. enum { NUM_SUBDIV_EDGES = 8 };
  24. Vector m_Point;
  25. Vector m_Normal;
  26. Vector m_NewPoint;
  27. Vector m_NewNormal;
  28. int m_Type;
  29. int m_Valence;
  30. CSubdivEdge *m_pEdges[NUM_SUBDIV_EDGES];
  31. void Clear( void );
  32. void Copy( const CSubdivPoint *pFrom );
  33. void CalcNewVertexPoint( void );
  34. void CalcNewVertexNormal( void );
  35. friend bool CompareSubdivPoints( const CSubdivPoint *pPoint1, const CSubdivPoint *pPoint2, float tolerance );
  36. friend bool CompareSubdivPointToPoint( const CSubdivPoint *pSubdivPoint, const Vector& point, float tolerance );
  37. };
  38. //=============================================================================
  39. //
  40. // Class Subdivision Edge
  41. //
  42. class CSubdivEdge
  43. {
  44. public:
  45. short m_ndxPoint[2];
  46. CSubdivQuad *m_pQuads[2];
  47. short m_ndxQuadEdge[2];
  48. float m_Sharpness;
  49. Vector m_NewEdgePoint;
  50. Vector m_NewEdgeNormal;
  51. bool m_Active;
  52. void Clear( void );
  53. void Copy( const CSubdivEdge *pFrom );
  54. void CalcNewEdgePoint( void );
  55. void CalcNewEdgeNormal( void );
  56. friend bool CompareSubdivEdges( const CSubdivEdge *pEdge1, const CSubdivEdge *pEdge2 );
  57. };
  58. //=============================================================================
  59. //
  60. // Class Subdivision Quad
  61. //
  62. class CSubdivQuad
  63. {
  64. public:
  65. short m_ndxQuad[4]; // quad indices -- see CSubdivManager
  66. short m_ndxVert[4]; // vert indices -- see CSubdivManager
  67. short m_ndxEdge[4]; // edge indices -- see CSubdivManager
  68. Vector m_Centroid; // center of quad
  69. Vector m_Normal; // quad normal
  70. void GetCentroid( Vector& centroid );
  71. void CalcCentroid( void );
  72. void GetNormal( Vector& normal );
  73. void CalcNormal( void );
  74. };
  75. //=============================================================================
  76. //
  77. // Class Subdivision Mesh
  78. //
  79. class CSubdivMesh
  80. {
  81. public:
  82. //=========================================================================
  83. //
  84. // Creation/Destruction
  85. //
  86. CSubdivMesh();
  87. ~CSubdivMesh();
  88. //=========================================================================
  89. //
  90. //
  91. //
  92. inline void Clear( void );
  93. void DoSubdivide( void );
  94. //=========================================================================
  95. //
  96. //
  97. //
  98. inline int GetPointCount( void );
  99. int AddPoint( const Vector& point, const Vector& normal );
  100. void RemovePoint( Vector& point );
  101. inline void GetPoint( int index, Vector& point );
  102. inline void GetNormal( int index, Vector& normal );
  103. inline int GetEdgeCount( void );
  104. int AddEdge( CSubdivEdge *edge );
  105. void RemoveEdge( CSubdivEdge *edge );
  106. inline void GetEdge( int index, CSubdivEdge *edge );
  107. private:
  108. // enum { MAX_SUBDIV_POINTS = 32000 };
  109. // enum { MAX_TREES = 64 };
  110. int m_PointCount;
  111. int m_MaxPointCount;
  112. CSubdivPoint *m_pPoints;
  113. // CSubdivPoint m_Points[MAX_SUBDIV_POINTS]; // mesh list of subdivision verts
  114. int m_EdgeCount;
  115. int m_MaxEdgeCount;
  116. CSubdivEdge *m_pEdges;
  117. // CSubdivEdge m_Edges[MAX_SUBDIV_POINTS]; // mesh list of subdivision edges
  118. int m_TreeCount;
  119. int m_MaxTreeCount;
  120. CSubdivQuad **m_ppTrees;
  121. // CSubdivQuad *m_pTrees[MAX_TREES];
  122. void CatmullClarkSubdivide( void );
  123. int AddTree( CSubdivQuad *pTree );
  124. int GetStartIndexFromLevel( int levelIndex );
  125. int GetEndIndexFromLevel( int levelIndex );
  126. void AddQuadToMesh( CSubdivQuad *pQuad );
  127. inline void ClearEdges( void );
  128. void CreateChildQuads( CSubdivQuad *pRoot, int quadIndex );
  129. void SetEdgeData( CSubdivQuad *pRoot, int index, int parentIndex, int subdivIndex );
  130. void CreateChildQuad1( CSubdivQuad *pRoot, int index, int parentIndex );
  131. void CreateChildQuad2( CSubdivQuad *pRoot, int index, int parentIndex );
  132. void CreateChildQuad3( CSubdivQuad *pRoot, int index, int parentIndex );
  133. void CreateChildQuad4( CSubdivQuad *pRoot, int index, int parentIndex );
  134. bool PreSubdivide( void );
  135. void Subdivide( void );
  136. void PostSubdivide( void );
  137. bool AllocCache( int dispCount );
  138. void FreeCache( void );
  139. };
  140. //-----------------------------------------------------------------------------
  141. //-----------------------------------------------------------------------------
  142. inline void CSubdivMesh::Clear( void )
  143. {
  144. m_PointCount = 0;
  145. m_EdgeCount = 0;
  146. m_TreeCount = 0;
  147. m_MaxPointCount = 0;
  148. m_MaxEdgeCount = 0;
  149. m_MaxTreeCount = 0;
  150. m_pPoints = NULL;
  151. m_pEdges = NULL;
  152. m_ppTrees = NULL;
  153. }
  154. //-----------------------------------------------------------------------------
  155. //-----------------------------------------------------------------------------
  156. inline int CSubdivMesh::GetPointCount( void )
  157. {
  158. return m_PointCount;
  159. }
  160. //-----------------------------------------------------------------------------
  161. //-----------------------------------------------------------------------------
  162. inline void CSubdivMesh::GetPoint( int index, Vector& point )
  163. {
  164. assert( index >= 0 );
  165. assert( index < m_PointCount );
  166. point = m_pPoints[index].m_Point;
  167. }
  168. //-----------------------------------------------------------------------------
  169. //-----------------------------------------------------------------------------
  170. inline void CSubdivMesh::GetNormal( int index, Vector& normal )
  171. {
  172. assert( index >= 0 );
  173. assert( index < m_PointCount );
  174. normal = m_pPoints[index].m_Normal;
  175. }
  176. //-----------------------------------------------------------------------------
  177. //-----------------------------------------------------------------------------
  178. inline int CSubdivMesh::GetEdgeCount( void )
  179. {
  180. return m_EdgeCount;
  181. }
  182. //-----------------------------------------------------------------------------
  183. //-----------------------------------------------------------------------------
  184. inline void CSubdivMesh::GetEdge( int index, CSubdivEdge *edge )
  185. {
  186. assert( index >= 0 );
  187. assert( index < m_EdgeCount );
  188. edge->Copy( &m_pEdges[index] );
  189. }
  190. #endif // SUBDIV_H