cm_patch.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //#define CULL_BBOX
  2. /*
  3. This file does not reference any globals, and has these entry points:
  4. void CM_ClearLevelPatches( void );
  5. struct patchCollide_s *CM_GeneratePatchCollide( int width, int height, const vec3_t *points );
  6. void CM_TraceThroughPatchCollide( traceWork_t *tw, const struct patchCollide_s *pc );
  7. qboolean CM_PositionTestInPatchCollide( traceWork_t *tw, const struct patchCollide_s *pc );
  8. void CM_DrawDebugSurface( void (*drawPoly)(int color, int numPoints, flaot *points) );
  9. Issues for collision against curved surfaces:
  10. Surface edges need to be handled differently than surface planes
  11. Plane expansion causes raw surfaces to expand past expanded bounding box
  12. Position test of a volume against a surface is tricky.
  13. Position test of a point against a surface is not well defined, because the surface has no volume.
  14. Tracing leading edge points instead of volumes?
  15. Position test by tracing corner to corner? (8*7 traces -- ouch)
  16. coplanar edges
  17. triangulated patches
  18. degenerate patches
  19. endcaps
  20. degenerate
  21. WARNING: this may misbehave with meshes that have rows or columns that only
  22. degenerate a few triangles. Completely degenerate rows and columns are handled
  23. properly.
  24. */
  25. #define MAX_FACETS 1024
  26. #define MAX_PATCH_PLANES 2048
  27. typedef struct {
  28. float plane[4];
  29. int signbits; // signx + (signy<<1) + (signz<<2), used as lookup during collision
  30. } patchPlane_t;
  31. #ifdef _XBOX
  32. //Facets are now two structures - a maximum sized version that's used
  33. //temporarily during load time, and smaller version that only allocates
  34. //as much memory as needed. The load version is copied into the small
  35. //version after it's been assembled.
  36. #pragma pack(push, 1)
  37. typedef struct {
  38. int surfacePlane;
  39. int numBorders; // 3 or four + 6 axial bevels + 4 or 3 * 4 edge bevels
  40. short borderPlanes[4+6+16];
  41. unsigned char borderInward[4+6+16];
  42. unsigned char borderNoAdjust[4+6+16];
  43. } facetLoad_t;
  44. typedef struct {
  45. int surfacePlane;
  46. int numBorders; // 3 or four + 6 axial bevels + 4 or 3 * 4 edge bevels
  47. char *data;
  48. short *GetBorderPlanes(void) { return (short*)data; }
  49. char *GetBorderInward(void) { return data + (numBorders * 2); }
  50. char *GetBorderNoAdjust(void)
  51. { return data + (numBorders * 2) + numBorders; }
  52. const short *GetBorderPlanes(void) const { return (short*)data; }
  53. const char *GetBorderInward(void) const { return data + (numBorders * 2); }
  54. const char *GetBorderNoAdjust(void) const
  55. { return data + (numBorders * 2) + numBorders; }
  56. } facet_t;
  57. #pragma pack(pop)
  58. #else // _XBOX
  59. typedef struct {
  60. int surfacePlane;
  61. int numBorders; // 3 or four + 6 axial bevels + 4 or 3 * 4 edge bevels
  62. int borderPlanes[4+6+16];
  63. int borderInward[4+6+16];
  64. qboolean borderNoAdjust[4+6+16];
  65. } facet_t;
  66. #endif // _XBOX
  67. typedef struct patchCollide_s {
  68. vec3_t bounds[2];
  69. int numPlanes; // surface planes plus edge planes
  70. patchPlane_t *planes;
  71. int numFacets;
  72. facet_t *facets;
  73. } patchCollide_t;
  74. #define CM_MAX_GRID_SIZE 129
  75. typedef struct {
  76. int width;
  77. int height;
  78. qboolean wrapWidth;
  79. qboolean wrapHeight;
  80. vec3_t points[CM_MAX_GRID_SIZE][CM_MAX_GRID_SIZE]; // [width][height]
  81. } cGrid_t;
  82. #define SUBDIVIDE_DISTANCE 16 //4 // never more than this units away from curve
  83. #define PLANE_TRI_EPSILON 0.1
  84. #define WRAP_POINT_EPSILON 0.1
  85. #ifdef _XBOX
  86. struct patchCollide_s *CM_GeneratePatchCollide( int width, int height, vec3_t *points,
  87. facetLoad_t *facetbuf, int *gridbuf );
  88. #else
  89. struct patchCollide_s *CM_GeneratePatchCollide( int width, int height, vec3_t *points );
  90. #endif // _XBOX