aas_edgemelting.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. #include "qbsp.h"
  19. #include "../botlib/aasfile.h"
  20. #include "aas_create.h"
  21. //===========================================================================
  22. // try to melt the windings of the two faces
  23. // FIXME: this is buggy
  24. //
  25. // Parameter: -
  26. // Returns: -
  27. // Changes Globals: -
  28. //===========================================================================
  29. int AAS_MeltFaceWinding(tmp_face_t *face1, tmp_face_t *face2)
  30. {
  31. int i, n;
  32. int splits = 0;
  33. winding_t *w2, *neww;
  34. plane_t *plane1;
  35. #ifdef DEBUG
  36. if (!face1->winding) Error("face1 %d without winding", face1->num);
  37. if (!face2->winding) Error("face2 %d without winding", face2->num);
  38. #endif //DEBUG
  39. w2 = face2->winding;
  40. plane1 = &mapplanes[face1->planenum];
  41. for (i = 0; i < w2->numpoints; i++)
  42. {
  43. if (PointOnWinding(face1->winding, plane1->normal, plane1->dist, w2->p[i], &n))
  44. {
  45. neww = AddWindingPoint(face1->winding, w2->p[i], n);
  46. FreeWinding(face1->winding);
  47. face1->winding = neww;
  48. splits++;
  49. } //end if
  50. } //end for
  51. return splits;
  52. } //end of the function AAS_MeltFaceWinding
  53. //===========================================================================
  54. // melt the windings of the area faces
  55. //
  56. // Parameter: -
  57. // Returns: -
  58. // Changes Globals: -
  59. //===========================================================================
  60. int AAS_MeltFaceWindingsOfArea(tmp_area_t *tmparea)
  61. {
  62. int side1, side2, num_windingsplits = 0;
  63. tmp_face_t *face1, *face2;
  64. for (face1 = tmparea->tmpfaces; face1; face1 = face1->next[side1])
  65. {
  66. side1 = face1->frontarea != tmparea;
  67. for (face2 = tmparea->tmpfaces; face2; face2 = face2->next[side2])
  68. {
  69. side2 = face2->frontarea != tmparea;
  70. if (face1 == face2) continue;
  71. num_windingsplits += AAS_MeltFaceWinding(face1, face2);
  72. } //end for
  73. } //end for
  74. return num_windingsplits;
  75. } //end of the function AAS_MeltFaceWindingsOfArea
  76. //===========================================================================
  77. // melt the windings of the faces of all areas
  78. //
  79. // Parameter: -
  80. // Returns: -
  81. // Changes Globals: -
  82. //===========================================================================
  83. void AAS_MeltAreaFaceWindings(void)
  84. {
  85. tmp_area_t *tmparea;
  86. int num_windingsplits = 0;
  87. Log_Write("AAS_MeltAreaFaceWindings\r\n");
  88. qprintf("%6d edges melted", num_windingsplits);
  89. //NOTE: first convex area (zero) is a dummy
  90. for (tmparea = tmpaasworld.areas; tmparea; tmparea = tmparea->l_next)
  91. {
  92. num_windingsplits += AAS_MeltFaceWindingsOfArea(tmparea);
  93. qprintf("\r%6d", num_windingsplits);
  94. } //end for
  95. qprintf("\n");
  96. Log_Write("%6d edges melted\r\n", num_windingsplits);
  97. } //end of the function AAS_MeltAreaFaceWindings