Surface_Patch.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __SURFACE_PATCH_H__
  21. #define __SURFACE_PATCH_H__
  22. /*
  23. ===============================================================================
  24. Bezier patch surface.
  25. ===============================================================================
  26. */
  27. class idSurface_Patch : public idSurface {
  28. public:
  29. idSurface_Patch();
  30. idSurface_Patch( int maxPatchWidth, int maxPatchHeight );
  31. idSurface_Patch( const idSurface_Patch &patch );
  32. ~idSurface_Patch();
  33. void SetSize( int patchWidth, int patchHeight );
  34. int GetWidth() const;
  35. int GetHeight() const;
  36. // subdivide the patch mesh based on error
  37. void Subdivide( float maxHorizontalError, float maxVerticalError, float maxLength, bool genNormals = false );
  38. // subdivide the patch up to an explicit number of horizontal and vertical subdivisions
  39. void SubdivideExplicit( int horzSubdivisions, int vertSubdivisions, bool genNormals, bool removeLinear = false );
  40. protected:
  41. int width; // width of patch
  42. int height; // height of patch
  43. int maxWidth; // maximum width allocated for
  44. int maxHeight; // maximum height allocated for
  45. bool expanded; // true if vertices are spaced out
  46. private:
  47. // put the approximation points on the curve
  48. void PutOnCurve();
  49. // remove columns and rows with all points on one line
  50. void RemoveLinearColumnsRows();
  51. // resize verts buffer
  52. void ResizeExpanded( int height, int width );
  53. // space points out over maxWidth * maxHeight buffer
  54. void Expand();
  55. // move all points to the start of the verts buffer
  56. void Collapse();
  57. // project a point onto a vector to calculate maximum curve error
  58. void ProjectPointOntoVector( const idVec3 &point, const idVec3 &vStart, const idVec3 &vEnd, idVec3 &vProj );
  59. // generate normals
  60. void GenerateNormals();
  61. // generate triangle indexes
  62. void GenerateIndexes();
  63. // lerp point from two patch point
  64. void LerpVert( const idDrawVert &a, const idDrawVert &b, idDrawVert &out ) const;
  65. // sample a single 3x3 patch
  66. void SampleSinglePatchPoint( const idDrawVert ctrl[3][3], float u, float v, idDrawVert *out ) const;
  67. void SampleSinglePatch( const idDrawVert ctrl[3][3], int baseCol, int baseRow, int width, int horzSub, int vertSub, idDrawVert *outVerts ) const;
  68. };
  69. /*
  70. =================
  71. idSurface_Patch::idSurface_Patch
  72. =================
  73. */
  74. ID_INLINE idSurface_Patch::idSurface_Patch() {
  75. height = width = maxHeight = maxWidth = 0;
  76. expanded = false;
  77. }
  78. /*
  79. =================
  80. idSurface_Patch::idSurface_Patch
  81. =================
  82. */
  83. ID_INLINE idSurface_Patch::idSurface_Patch( int maxPatchWidth, int maxPatchHeight ) {
  84. width = height = 0;
  85. maxWidth = maxPatchWidth;
  86. maxHeight = maxPatchHeight;
  87. verts.SetNum( maxWidth * maxHeight );
  88. expanded = false;
  89. }
  90. /*
  91. =================
  92. idSurface_Patch::idSurface_Patch
  93. =================
  94. */
  95. ID_INLINE idSurface_Patch::idSurface_Patch( const idSurface_Patch &patch ) {
  96. (*this) = patch;
  97. }
  98. /*
  99. =================
  100. idSurface_Patch::~idSurface_Patch
  101. =================
  102. */
  103. ID_INLINE idSurface_Patch::~idSurface_Patch() {
  104. }
  105. /*
  106. =================
  107. idSurface_Patch::GetWidth
  108. =================
  109. */
  110. ID_INLINE int idSurface_Patch::GetWidth() const {
  111. return width;
  112. }
  113. /*
  114. =================
  115. idSurface_Patch::GetHeight
  116. =================
  117. */
  118. ID_INLINE int idSurface_Patch::GetHeight() const {
  119. return height;
  120. }
  121. #endif /* !__SURFACE_PATCH_H__ */