cm_patch.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. //#define CULL_BBOX
  19. /*
  20. This file does not reference any globals, and has these entry points:
  21. void CM_ClearLevelPatches( void );
  22. struct patchCollide_s *CM_GeneratePatchCollide( int width, int height, const vec3_t *points );
  23. void CM_TraceThroughPatchCollide( traceWork_t *tw, const struct patchCollide_s *pc );
  24. qboolean CM_PositionTestInPatchCollide( traceWork_t *tw, const struct patchCollide_s *pc );
  25. void CM_DrawDebugSurface( void (*drawPoly)(int color, int numPoints, flaot *points) );
  26. Issues for collision against curved surfaces:
  27. Surface edges need to be handled differently than surface planes
  28. Plane expansion causes raw surfaces to expand past expanded bounding box
  29. Position test of a volume against a surface is tricky.
  30. Position test of a point against a surface is not well defined, because the surface has no volume.
  31. Tracing leading edge points instead of volumes?
  32. Position test by tracing corner to corner? (8*7 traces -- ouch)
  33. coplanar edges
  34. triangulated patches
  35. degenerate patches
  36. endcaps
  37. degenerate
  38. WARNING: this may misbehave with meshes that have rows or columns that only
  39. degenerate a few triangles. Completely degenerate rows and columns are handled
  40. properly.
  41. */
  42. #define MAX_FACETS 1024
  43. #define MAX_PATCH_PLANES 2048
  44. typedef struct {
  45. float plane[4];
  46. int signbits; // signx + (signy<<1) + (signz<<2), used as lookup during collision
  47. } patchPlane_t;
  48. typedef struct {
  49. int surfacePlane;
  50. int numBorders; // 3 or four + 6 axial bevels + 4 or 3 * 4 edge bevels
  51. int borderPlanes[4+6+16];
  52. int borderInward[4+6+16];
  53. qboolean borderNoAdjust[4+6+16];
  54. } facet_t;
  55. typedef struct patchCollide_s {
  56. vec3_t bounds[2];
  57. int numPlanes; // surface planes plus edge planes
  58. patchPlane_t *planes;
  59. int numFacets;
  60. facet_t *facets;
  61. } patchCollide_t;
  62. #define MAX_GRID_SIZE 129
  63. typedef struct {
  64. int width;
  65. int height;
  66. qboolean wrapWidth;
  67. qboolean wrapHeight;
  68. vec3_t points[MAX_GRID_SIZE][MAX_GRID_SIZE]; // [width][height]
  69. } cGrid_t;
  70. #define SUBDIVIDE_DISTANCE 16 //4 // never more than this units away from curve
  71. #define PLANE_TRI_EPSILON 0.1
  72. #define WRAP_POINT_EPSILON 0.1
  73. struct patchCollide_s *CM_GeneratePatchCollide( int width, int height, vec3_t *points );