| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include "qbsp.h" |
| 23 |
|
| 24 |
int c_glfaces; |
| 25 |
|
| 26 |
int PortalVisibleSides( portal_t *p ){ |
| 27 |
int fcon, bcon; |
| 28 |
|
| 29 |
if ( !p->onnode ) { |
| 30 |
return 0; |
| 31 |
|
| 32 |
} |
| 33 |
fcon = p->nodes[0]->contents; |
| 34 |
bcon = p->nodes[1]->contents; |
| 35 |
|
| 36 |
|
| 37 |
if ( fcon == bcon ) { |
| 38 |
return 0; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
if ( !fcon ) { |
| 43 |
return 1; |
| 44 |
} |
| 45 |
if ( !bcon ) { |
| 46 |
return 2; |
| 47 |
} |
| 48 |
return 0; |
| 49 |
} |
| 50 |
|
| 51 |
void OutputWinding( winding_t *w, FILE *glview ){ |
| 52 |
static int level = 128; |
| 53 |
vec_t light; |
| 54 |
int i; |
| 55 |
|
| 56 |
fprintf( glview, "%i\n", w->numpoints ); |
| 57 |
level += 28; |
| 58 |
light = ( level & 255 ) / 255.0; |
| 59 |
for ( i = 0 ; i < w->numpoints ; i++ ) |
| 60 |
{ |
| 61 |
fprintf( glview, "%6.3f %6.3f %6.3f %6.3f %6.3f %6.3f\n", |
| 62 |
w->p[i][0], |
| 63 |
w->p[i][1], |
| 64 |
w->p[i][2], |
| 65 |
light, |
| 66 |
light, |
| 67 |
light ); |
| 68 |
} |
| 69 |
fprintf( glview, "\n" ); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
void OutputPortal( portal_t *p, FILE *glview ){ |
| 78 |
winding_t *w; |
| 79 |
int sides; |
| 80 |
|
| 81 |
sides = PortalVisibleSides( p ); |
| 82 |
if ( !sides ) { |
| 83 |
return; |
| 84 |
} |
| 85 |
|
| 86 |
c_glfaces++; |
| 87 |
|
| 88 |
w = p->winding; |
| 89 |
|
| 90 |
if ( sides == 2 ) { |
| 91 |
w = ReverseWinding( w ); |
| 92 |
} |
| 93 |
|
| 94 |
OutputWinding( w, glview ); |
| 95 |
|
| 96 |
if ( sides == 2 ) { |
| 97 |
FreeWinding( w ); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
void WriteGLView_r( node_t *node, FILE *glview ){ |
| 107 |
portal_t *p, *nextp; |
| 108 |
|
| 109 |
if ( node->planenum != PLANENUM_LEAF ) { |
| 110 |
WriteGLView_r( node->children[0], glview ); |
| 111 |
WriteGLView_r( node->children[1], glview ); |
| 112 |
return; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
for ( p = node->portals ; p ; p = nextp ) |
| 117 |
{ |
| 118 |
if ( p->nodes[0] == node ) { |
| 119 |
OutputPortal( p, glview ); |
| 120 |
nextp = p->next[0]; |
| 121 |
} |
| 122 |
else{ |
| 123 |
nextp = p->next[1]; |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
void WriteGLView( tree_t *tree, char *source ){ |
| 134 |
char name[1024]; |
| 135 |
FILE *glview; |
| 136 |
|
| 137 |
c_glfaces = 0; |
| 138 |
sprintf( name, "%s%s.gl",outbase, source ); |
| 139 |
Sys_Printf( "Writing %s\n", name ); |
| 140 |
|
| 141 |
glview = fopen( name, "w" ); |
| 142 |
if ( !glview ) { |
| 143 |
Error( "Couldn't open %s", name ); |
| 144 |
} |
| 145 |
WriteGLView_r( tree->headnode, glview ); |
| 146 |
fclose( glview ); |
| 147 |
|
| 148 |
Sys_Printf( "%5i c_glfaces\n", c_glfaces ); |
| 149 |
} |