1 /*
2 ===========================================================================
3 
4 Return to Castle Wolfenstein multiplayer GPL Source Code
5 Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Return to Castle Wolfenstein multiplayer GPL Source Code (“RTCW MP Source Code”).
8 
9 RTCW MP Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 RTCW MP Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with RTCW MP Source Code.  If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the RTCW MP 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 RTCW MP Source Code.  If not, please request a copy in writing from id Software at the address below.
23 
24 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.
25 
26 ===========================================================================
27 */
28 
29 
30 //#define	CULL_BBOX
31 
32 /*
33 
34 This file does not reference any globals, and has these entry points:
35 
36 void CM_ClearLevelPatches( void );
37 struct patchCollide_s	*CM_GeneratePatchCollide( int width, int height, const vec3_t *points );
38 void CM_TraceThroughPatchCollide( traceWork_t *tw, const struct patchCollide_s *pc );
39 qboolean CM_PositionTestInPatchCollide( traceWork_t *tw, const struct patchCollide_s *pc );
40 void CM_DrawDebugSurface( void (*drawPoly)(int color, int numPoints, flaot *points) );
41 
42 
43 Issues for collision against curved surfaces:
44 
45 Surface edges need to be handled differently than surface planes
46 
47 Plane expansion causes raw surfaces to expand past expanded bounding box
48 
49 Position test of a volume against a surface is tricky.
50 
51 Position test of a point against a surface is not well defined, because the surface has no volume.
52 
53 
54 Tracing leading edge points instead of volumes?
55 Position test by tracing corner to corner? (8*7 traces -- ouch)
56 
57 coplanar edges
58 triangulated patches
59 degenerate patches
60 
61   endcaps
62   degenerate
63 
64 WARNING: this may misbehave with meshes that have rows or columns that only
65 degenerate a few triangles.  Completely degenerate rows and columns are handled
66 properly.
67 */
68 
69 
70 #define MAX_FACETS          1024
71 #define MAX_PATCH_PLANES    2048
72 
73 typedef struct {
74 	float plane[4];
75 	int signbits;           // signx + (signy<<1) + (signz<<2), used as lookup during collision
76 } patchPlane_t;
77 
78 typedef struct {
79 	int surfacePlane;
80 	int numBorders;             // 3 or four + 6 axial bevels + 4 or 3 * 4 edge bevels
81 	int borderPlanes[4 + 6 + 16];
82 	int borderInward[4 + 6 + 16];
83 	qboolean borderNoAdjust[4 + 6 + 16];
84 } facet_t;
85 
86 typedef struct patchCollide_s {
87 	vec3_t bounds[2];
88 	int numPlanes;              // surface planes plus edge planes
89 	patchPlane_t    *planes;
90 	int numFacets;
91 	facet_t *facets;
92 } patchCollide_t;
93 
94 
95 #define MAX_GRID_SIZE   129
96 
97 typedef struct {
98 	int width;
99 	int height;
100 	qboolean wrapWidth;
101 	qboolean wrapHeight;
102 	vec3_t points[MAX_GRID_SIZE][MAX_GRID_SIZE];    // [width][height]
103 } cGrid_t;
104 
105 #define SUBDIVIDE_DISTANCE  16  //4	// never more than this units away from curve
106 #define PLANE_TRI_EPSILON   0.1
107 #define WRAP_POINT_EPSILON  0.1
108 
109 
110 struct patchCollide_s   *CM_GeneratePatchCollide( int width, int height, vec3_t *points );
111