]> icculus.org git repositories - divverent/darkplaces.git/blob - model_brush.h
fix a severe bug with viewangles in cl_movement mode
[divverent/darkplaces.git] / model_brush.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #ifndef MODEL_BRUSH_H
22 #define MODEL_BRUSH_H
23
24 /*
25 ==============================================================================
26
27 BRUSH MODELS
28
29 ==============================================================================
30 */
31
32 #define Q3PATHLENGTH 64
33
34
35 //
36 // in memory representation
37 //
38 typedef struct
39 {
40         vec3_t position;
41 }
42 mvertex_t;
43
44 #define SIDE_FRONT 0
45 #define SIDE_BACK 1
46 #define SIDE_ON 2
47
48
49 // plane_t structure
50 typedef struct mplane_s
51 {
52         vec3_t normal;
53         float dist;
54         // for texture axis selection and fast side tests
55         int type;
56         int signbits;
57 }
58 mplane_t;
59
60 #define SHADERSTAGE_SKY 0
61 #define SHADERSTAGE_NORMAL 1
62 #define SHADERSTAGE_COUNT 2
63
64 //#define SURF_PLANEBACK 2
65
66 // set for anything to be transparent sorted
67 #define MATERIALFLAG_TRANSPARENT 1
68 // use alpha blend on this material
69 #define MATERIALFLAG_ALPHA 2
70 // use additive blend on this material
71 #define MATERIALFLAG_ADD 4
72 // turn off depth test on this material
73 #define MATERIALFLAG_NODEPTHTEST 8
74 // multiply alpha by r_wateralpha cvar
75 #define MATERIALFLAG_WATERALPHA 16
76 // draw with no lighting
77 #define MATERIALFLAG_FULLBRIGHT 32
78 // drawn as a normal lightmapped wall
79 #define MATERIALFLAG_WALL 64
80 // swirling water effect
81 #define MATERIALFLAG_WATER 128
82 // this surface shows the sky
83 // skipped if transparent
84 #define MATERIALFLAG_SKY 256
85 // skips drawing the surface
86 #define MATERIALFLAG_NODRAW 512
87 // probably used only on q1bsp water
88 #define MATERIALFLAG_LIGHTBOTHSIDES 1024
89
90 typedef struct
91 {
92         unsigned short v[2];
93 }
94 medge_t;
95
96 struct entity_render_s;
97 struct texture_s;
98 struct msurface_s;
99
100 typedef struct mnode_s
101 {
102         //this part shared between node and leaf
103         mplane_t *plane; // != NULL
104         struct mnode_s *parent;
105         struct mportal_s *portals;
106         // for bounding box culling
107         vec3_t mins;
108         vec3_t maxs;
109
110         // this part unique to node
111         struct mnode_s *children[2];
112
113         // q1bsp specific
114         unsigned short firstsurface;
115         unsigned short numsurfaces;
116 }
117 mnode_t;
118
119 typedef struct mleaf_s
120 {
121         //this part shared between node and leaf
122         mplane_t *plane; // == NULL
123         struct mnode_s *parent;
124         struct mportal_s *portals;
125         // for bounding box culling
126         vec3_t mins;
127         vec3_t maxs;
128
129         // this part unique to leaf
130         // common
131         int clusterindex; // -1 is not in pvs, >= 0 is pvs bit number
132         int areaindex; // q3bsp
133         int numleafsurfaces;
134         int *firstleafsurface;
135         int numleafbrushes; // q3bsp
136         int *firstleafbrush; // q3bsp
137         qbyte ambient_sound_level[NUM_AMBIENTS]; // q1bsp
138         int contents; // q1bsp: // TODO: remove (only used temporarily during loading when making collision hull 0)
139         int portalmarkid; // q1bsp // used by see-polygon-through-portals visibility checker
140 }
141 mleaf_t;
142
143 typedef struct
144 {
145         dclipnode_t *clipnodes;
146         mplane_t *planes;
147         int firstclipnode;
148         int lastclipnode;
149         vec3_t clip_mins;
150         vec3_t clip_maxs;
151         vec3_t clip_size;
152 }
153 hull_t;
154
155 typedef struct mportal_s
156 {
157         struct mportal_s *next; // the next portal on this leaf
158         mleaf_t *here; // the leaf this portal is on
159         mleaf_t *past; // the leaf through this portal (infront)
160         int numpoints;
161         mvertex_t *points;
162         vec3_t mins, maxs; // culling
163         mplane_t plane;
164 }
165 mportal_t;
166
167 typedef struct svbspmesh_s
168 {
169         struct svbspmesh_s *next;
170         int numverts, maxverts;
171         int numtriangles, maxtriangles;
172         float *verts;
173         int *elements;
174 }
175 svbspmesh_t;
176
177 typedef struct mlight_s
178 {
179         // location of light
180         vec3_t origin;
181         // distance attenuation scale (smaller is a larger light)
182         float falloff;
183         // color and brightness combined
184         vec3_t light;
185         // brightness bias, used for limiting radius without a hard edge
186         float subtract;
187         // spotlight direction
188         vec3_t spotdir;
189         // cosine of spotlight cone angle (or 0 if not a spotlight)
190         float spotcone;
191         // distance bias (larger value is softer and darker)
192         float distbias;
193         // light style controlling this light
194         int style;
195         // maximum extent of the light for shading purposes
196         float lightradius;
197         // maximum extent of the light for culling purposes
198         float cullradius;
199         float cullradius2;
200         /*
201         // surfaces this shines on
202         int numsurfaces;
203         msurface_t **surfaces;
204         // lit area
205         vec3_t mins, maxs;
206         // precomputed shadow volume meshs
207         //svbspmesh_t *shadowvolume;
208         //vec3_t shadowvolumemins, shadowvolumemaxs;
209         shadowmesh_t *shadowvolume;
210         */
211 }
212 mlight_t;
213
214 struct model_s;
215 void Mod_Q1BSP_Load(struct model_s *mod, void *buffer);
216 void Mod_IBSP_Load(struct model_s *mod, void *buffer);
217 void Mod_MAP_Load(struct model_s *mod, void *buffer);
218 void Mod_BrushInit(void);
219
220 // Q2 bsp stuff
221
222 #define Q2BSPVERSION    38
223
224 // leaffaces, leafbrushes, planes, and verts are still bounded by
225 // 16 bit short limits
226
227 //=============================================================================
228
229 #define Q2LUMP_ENTITIES         0
230 #define Q2LUMP_PLANES                   1
231 #define Q2LUMP_VERTEXES         2
232 #define Q2LUMP_VISIBILITY               3
233 #define Q2LUMP_NODES                    4
234 #define Q2LUMP_TEXINFO          5
235 #define Q2LUMP_FACES                    6
236 #define Q2LUMP_LIGHTING         7
237 #define Q2LUMP_LEAFS                    8
238 #define Q2LUMP_LEAFFACES                9
239 #define Q2LUMP_LEAFBRUSHES      10
240 #define Q2LUMP_EDGES                    11
241 #define Q2LUMP_SURFEDGES                12
242 #define Q2LUMP_MODELS                   13
243 #define Q2LUMP_BRUSHES          14
244 #define Q2LUMP_BRUSHSIDES               15
245 #define Q2LUMP_POP                      16
246 #define Q2LUMP_AREAS                    17
247 #define Q2LUMP_AREAPORTALS      18
248 #define Q2HEADER_LUMPS          19
249
250 typedef struct
251 {
252         int                     ident;
253         int                     version;
254         lump_t          lumps[HEADER_LUMPS];
255 } q2dheader_t;
256
257 typedef struct
258 {
259         float           mins[3], maxs[3];
260         float           origin[3];              // for sounds or lights
261         int                     headnode;
262         int                     firstface, numfaces;    // submodels just draw faces
263                                                                                 // without walking the bsp tree
264 } q2dmodel_t;
265
266 // planes (x&~1) and (x&~1)+1 are always opposites
267
268 // contents flags are seperate bits
269 // a given brush can contribute multiple content bits
270 // multiple brushes can be in a single leaf
271
272 // these definitions also need to be in q_shared.h!
273
274 // lower bits are stronger, and will eat weaker brushes completely
275 #define Q2CONTENTS_SOLID                        1               // an eye is never valid in a solid
276 #define Q2CONTENTS_WINDOW                       2               // translucent, but not watery
277 #define Q2CONTENTS_AUX                  4
278 #define Q2CONTENTS_LAVA                 8
279 #define Q2CONTENTS_SLIME                        16
280 #define Q2CONTENTS_WATER                        32
281 #define Q2CONTENTS_MIST                 64
282 #define Q2LAST_VISIBLE_CONTENTS 64
283
284 // remaining contents are non-visible, and don't eat brushes
285
286 #define Q2CONTENTS_AREAPORTAL           0x8000
287
288 #define Q2CONTENTS_PLAYERCLIP           0x10000
289 #define Q2CONTENTS_MONSTERCLIP  0x20000
290
291 // currents can be added to any other contents, and may be mixed
292 #define Q2CONTENTS_CURRENT_0            0x40000
293 #define Q2CONTENTS_CURRENT_90           0x80000
294 #define Q2CONTENTS_CURRENT_180  0x100000
295 #define Q2CONTENTS_CURRENT_270  0x200000
296 #define Q2CONTENTS_CURRENT_UP           0x400000
297 #define Q2CONTENTS_CURRENT_DOWN 0x800000
298
299 #define Q2CONTENTS_ORIGIN                       0x1000000       // removed before bsping an entity
300
301 #define Q2CONTENTS_MONSTER              0x2000000       // should never be on a brush, only in game
302 #define Q2CONTENTS_DEADMONSTER  0x4000000
303 #define Q2CONTENTS_DETAIL                       0x8000000       // brushes to be added after vis leafs
304 #define Q2CONTENTS_TRANSLUCENT  0x10000000      // auto set if any surface has trans
305 #define Q2CONTENTS_LADDER                       0x20000000
306
307
308
309 #define Q2SURF_LIGHT            0x1             // value will hold the light strength
310
311 #define Q2SURF_SLICK            0x2             // effects game physics
312
313 #define Q2SURF_SKY              0x4             // don't draw, but add to skybox
314 #define Q2SURF_WARP             0x8             // turbulent water warp
315 #define Q2SURF_TRANS33  0x10
316 #define Q2SURF_TRANS66  0x20
317 #define Q2SURF_FLOWING  0x40    // scroll towards angle
318 #define Q2SURF_NODRAW           0x80    // don't bother referencing the texture
319
320
321
322
323 typedef struct
324 {
325         int                     planenum;
326         int                     children[2];    // negative numbers are -(leafs+1), not nodes
327         short           mins[3];                // for frustom culling
328         short           maxs[3];
329         unsigned short  firstface;
330         unsigned short  numfaces;       // counting both sides
331 } q2dnode_t;
332
333
334 typedef struct
335 {
336         float           vecs[2][4];             // [s/t][xyz offset]
337         int                     flags;                  // miptex flags + overrides
338         int                     value;                  // light emission, etc
339         char            texture[32];    // texture name (textures/*.wal)
340         int                     nexttexinfo;    // for animations, -1 = end of chain
341 } q2texinfo_t;
342
343 typedef struct
344 {
345         int                             contents;                       // OR of all brushes (not needed?)
346
347         short                   cluster;
348         short                   area;
349
350         short                   mins[3];                        // for frustum culling
351         short                   maxs[3];
352
353         unsigned short  firstleafface;
354         unsigned short  numleaffaces;
355
356         unsigned short  firstleafbrush;
357         unsigned short  numleafbrushes;
358 } q2dleaf_t;
359
360 typedef struct
361 {
362         unsigned short  planenum;               // facing out of the leaf
363         short   texinfo;
364 } q2dbrushside_t;
365
366 typedef struct
367 {
368         int                     firstside;
369         int                     numsides;
370         int                     contents;
371 } q2dbrush_t;
372
373
374 // the visibility lump consists of a header with a count, then
375 // byte offsets for the PVS and PHS of each cluster, then the raw
376 // compressed bit vectors
377 #define Q2DVIS_PVS      0
378 #define Q2DVIS_PHS      1
379 typedef struct
380 {
381         int                     numclusters;
382         int                     bitofs[8][2];   // bitofs[numclusters][2]
383 } q2dvis_t;
384
385 // each area has a list of portals that lead into other areas
386 // when portals are closed, other areas may not be visible or
387 // hearable even if the vis info says that it should be
388 typedef struct
389 {
390         int             portalnum;
391         int             otherarea;
392 } q2dareaportal_t;
393
394 typedef struct
395 {
396         int             numareaportals;
397         int             firstareaportal;
398 } q2darea_t;
399
400
401 //Q3 bsp stuff
402
403 #define Q3BSPVERSION    46
404
405 #define Q3LUMP_ENTITIES         0 // entities to spawn (used by server and client)
406 #define Q3LUMP_TEXTURES         1 // textures used (used by faces)
407 #define Q3LUMP_PLANES           2 // planes used (used by bsp nodes)
408 #define Q3LUMP_NODES            3 // bsp nodes (used by bsp nodes, bsp leafs, rendering, collisions)
409 #define Q3LUMP_LEAFS            4 // bsp leafs (used by bsp nodes)
410 #define Q3LUMP_LEAFFACES        5 // array of ints indexing faces (used by leafs)
411 #define Q3LUMP_LEAFBRUSHES      6 // array of ints indexing brushes (used by leafs)
412 #define Q3LUMP_MODELS           7 // models (used by rendering, collisions)
413 #define Q3LUMP_BRUSHES          8 // brushes (used by effects, collisions)
414 #define Q3LUMP_BRUSHSIDES       9 // brush faces (used by brushes)
415 #define Q3LUMP_VERTICES         10 // mesh vertices (used by faces)
416 #define Q3LUMP_TRIANGLES        11 // mesh triangles (used by faces)
417 #define Q3LUMP_EFFECTS          12 // fog (used by faces)
418 #define Q3LUMP_FACES            13 // surfaces (used by leafs)
419 #define Q3LUMP_LIGHTMAPS        14 // lightmap textures (used by faces)
420 #define Q3LUMP_LIGHTGRID        15 // lighting as a voxel grid (used by rendering)
421 #define Q3LUMP_PVS                      16 // potentially visible set; bit[clusters][clusters] (used by rendering)
422 #define Q3HEADER_LUMPS          17
423
424 typedef struct
425 {
426         int                     ident;
427         int                     version;
428         lump_t          lumps[HEADER_LUMPS];
429 } q3dheader_t;
430
431 typedef struct
432 {
433         char name[Q3PATHLENGTH];
434         int surfaceflags;
435         int contents;
436 }
437 q3dtexture_t;
438
439 // note: planes are paired, the pair of planes with i and i ^ 1 are opposites.
440 typedef struct
441 {
442         float normal[3];
443         float dist;
444 }
445 q3dplane_t;
446
447 typedef struct
448 {
449         int planeindex;
450         int childrenindex[2];
451         int mins[3];
452         int maxs[3];
453 }
454 q3dnode_t;
455
456 typedef struct
457 {
458         int clusterindex; // pvs index
459         int areaindex; // area index
460         int mins[3];
461         int maxs[3];
462         int firstleafface;
463         int numleaffaces;
464         int firstleafbrush;
465         int numleafbrushes;
466 }
467 q3dleaf_t;
468
469 typedef struct
470 {
471         float mins[3];
472         float maxs[3];
473         int firstface;
474         int numfaces;
475         int firstbrush;
476         int numbrushes;
477 }
478 q3dmodel_t;
479
480 typedef struct
481 {
482         int firstbrushside;
483         int numbrushsides;
484         int textureindex;
485 }
486 q3dbrush_t;
487
488 typedef struct
489 {
490         int planeindex;
491         int textureindex;
492 }
493 q3dbrushside_t;
494
495 typedef struct
496 {
497         float origin3f[3];
498         float texcoord2f[2];
499         float lightmap2f[2];
500         float normal3f[3];
501         unsigned char color4ub[4];
502 }
503 q3dvertex_t;
504
505 typedef struct
506 {
507         int offset; // first vertex index of mesh
508 }
509 q3dmeshvertex_t;
510
511 typedef struct q3deffect_s
512 {
513         char shadername[Q3PATHLENGTH];
514         int brushindex;
515         int unknown; // I read this is always 5 except in q3dm8 which has one effect with -1
516 }
517 q3deffect_t;
518
519 #define Q3FACETYPE_POLYGON 1 // common
520 #define Q3FACETYPE_PATCH 2 // common
521 #define Q3FACETYPE_MESH 3 // common
522 #define Q3FACETYPE_FLARE 4 // rare (is this ever used?)
523
524 typedef struct
525 {
526         int textureindex;
527         int effectindex; // -1 if none
528         int type; // Q3FACETYPE
529         int firstvertex;
530         int numvertices;
531         int firstelement;
532         int numelements;
533         int lightmapindex; // -1 if none
534         int lightmap_base[2];
535         int lightmap_size[2];
536         union
537         {
538                 struct
539                 {
540                         // corrupt or don't care
541                         int blah[14];
542                 }
543                 unknown;
544                 struct
545                 {
546                         // Q3FACETYPE_POLYGON
547                         // polygon is simply a convex polygon, renderable as a mesh
548                         float lightmap_origin[3];
549                         float lightmap_vectors[2][3];
550                         float normal[3];
551                         int unused1[2];
552                 }
553                 polygon;
554                 struct
555                 {
556                         // Q3FACETYPE_PATCH
557                         // patch renders as a bezier mesh, with adjustable tesselation
558                         // level (optionally based on LOD using the bbox and polygon
559                         // count to choose a tesselation level)
560                         // note: multiple patches may have the same bbox to cause them to
561                         // be LOD adjusted together as a group
562                         int unused1[3];
563                         float mins[3]; // LOD bbox
564                         float maxs[3]; // LOD bbox
565                         int unused2[3];
566                         int patchsize[2]; // dimensions of vertex grid
567                 }
568                 patch;
569                 struct
570                 {
571                         // Q3FACETYPE_MESH
572                         // mesh renders as simply a triangle mesh
573                         int unused1[3];
574                         float mins[3];
575                         float maxs[3];
576                         int unused2[5];
577                 }
578                 mesh;
579                 struct
580                 {
581                         // Q3FACETYPE_FLARE
582                         // flare renders as a simple sprite at origin, no geometry
583                         // exists, nor does it have a radius, a cvar controls the radius
584                         // and another cvar controls distance fade
585                         // (they were not used in Q3 I'm told)
586                         float origin[3];
587                         int unused1[11];
588                 }
589                 flare;
590         }
591         specific;
592 }
593 q3dface_t;
594
595 typedef struct
596 {
597         unsigned char rgb[128*128*3];
598 }
599 q3dlightmap_t;
600
601 typedef struct
602 {
603         unsigned char ambientrgb[3];
604         unsigned char diffusergb[3];
605         unsigned char diffusepitch;
606         unsigned char diffuseyaw;
607 }
608 q3dlightgrid_t;
609
610 typedef struct
611 {
612         int numclusters;
613         int chainlength;
614         // unsigned char chains[];
615         // containing bits in 0-7 order (not 7-0 order),
616         // pvschains[mycluster * chainlength + (thatcluster >> 3)] & (1 << (thatcluster & 7))
617 }
618 q3dpvs_t;
619
620 // surfaceflags from bsp
621 #define Q3SURFACEFLAG_NODAMAGE 1
622 #define Q3SURFACEFLAG_SLICK 2
623 #define Q3SURFACEFLAG_SKY 4
624 #define Q3SURFACEFLAG_LADDER 8
625 #define Q3SURFACEFLAG_NOIMPACT 16
626 #define Q3SURFACEFLAG_NOMARKS 32
627 #define Q3SURFACEFLAG_FLESH 64
628 #define Q3SURFACEFLAG_NODRAW 128
629 #define Q3SURFACEFLAG_HINT 256
630 #define Q3SURFACEFLAG_SKIP 512
631 #define Q3SURFACEFLAG_NOLIGHTMAP 1024
632 #define Q3SURFACEFLAG_POINTLIGHT 2048
633 #define Q3SURFACEFLAG_METALSTEPS 4096
634 #define Q3SURFACEFLAG_NOSTEPS 8192
635 #define Q3SURFACEFLAG_NONSOLID 16384
636 #define Q3SURFACEFLAG_LIGHTFILTER 32768
637 #define Q3SURFACEFLAG_ALPHASHADOW 65536
638 #define Q3SURFACEFLAG_NODLIGHT 131072
639 #define Q3SURFACEFLAG_DUST 262144
640
641 // surfaceparms from shaders
642 #define Q3SURFACEPARM_ALPHASHADOW 1
643 #define Q3SURFACEPARM_AREAPORTAL 2
644 #define Q3SURFACEPARM_CLUSTERPORTAL 4
645 #define Q3SURFACEPARM_DETAIL 8
646 #define Q3SURFACEPARM_DONOTENTER 16
647 #define Q3SURFACEPARM_FOG 32
648 #define Q3SURFACEPARM_LAVA 64
649 #define Q3SURFACEPARM_LIGHTFILTER 128
650 #define Q3SURFACEPARM_METALSTEPS 256
651 #define Q3SURFACEPARM_NODAMAGE 512
652 #define Q3SURFACEPARM_NODLIGHT 1024
653 #define Q3SURFACEPARM_NODRAW 2048
654 #define Q3SURFACEPARM_NODROP 4096
655 #define Q3SURFACEPARM_NOIMPACT 8192
656 #define Q3SURFACEPARM_NOLIGHTMAP 16384
657 #define Q3SURFACEPARM_NOMARKS 32768
658 #define Q3SURFACEPARM_NOMIPMAPS 65536
659 #define Q3SURFACEPARM_NONSOLID 131072
660 #define Q3SURFACEPARM_ORIGIN 262144
661 #define Q3SURFACEPARM_PLAYERCLIP 524288
662 #define Q3SURFACEPARM_SKY 1048576
663 #define Q3SURFACEPARM_SLICK 2197152
664 #define Q3SURFACEPARM_SLIME 4194304
665 #define Q3SURFACEPARM_STRUCTURAL 8388608
666 #define Q3SURFACEPARM_TRANS 16777216
667 #define Q3SURFACEPARM_WATER 33554432
668 #define Q3SURFACEPARM_POINTLIGHT 67108864
669
670 // various flags from shaders
671 #define Q3TEXTUREFLAG_TWOSIDED 1
672 #define Q3TEXTUREFLAG_ADDITIVE 2
673 #define Q3TEXTUREFLAG_NOMIPMAPS 4
674 #define Q3TEXTUREFLAG_NOPICMIP 8
675 #define Q3TEXTUREFLAG_AUTOSPRITE 16
676 #define Q3TEXTUREFLAG_AUTOSPRITE2 32
677 #define Q3TEXTUREFLAG_ALPHATEST 64
678
679 typedef struct q3mbrush_s
680 {
681         struct colbrushf_s *colbrushf;
682         int numbrushsides;
683         struct q3mbrushside_s *firstbrushside;
684         struct texture_s *texture;
685 }
686 q3mbrush_t;
687
688 typedef struct q3mbrushside_s
689 {
690         struct mplane_s *plane;
691         struct texture_s *texture;
692 }
693 q3mbrushside_t;
694
695 #define CHECKPVSBIT(pvs,b) ((b) >= 0 ? ((pvs)[(b) >> 3] & (1 << ((b) & 7))) : false)
696 #define SETPVSBIT(pvs,b) ((b) >= 0 ? ((pvs)[(b) >> 3] |= (1 << ((b) & 7))) : false)
697 #define CLEARPVSBIT(pvs,b) ((b) >= 0 ? ((pvs)[(b) >> 3] &= ~(1 << ((b) & 7))) : false)
698
699 #endif
700