00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "qbsp.h"
00024
00025 int c_glfaces;
00026
00027 int PortalVisibleSides (portal_t *p)
00028 {
00029 int fcon, bcon;
00030
00031 if (!p->onnode)
00032 return 0;
00033
00034 fcon = p->nodes[0]->opaque;
00035 bcon = p->nodes[1]->opaque;
00036
00037
00038 if (fcon == bcon)
00039 return 0;
00040
00041 if (!fcon)
00042 return 1;
00043 if (!bcon)
00044 return 2;
00045 return 0;
00046 }
00047
00048 void OutputWinding (winding_t *w, FILE *glview)
00049 {
00050 static int level = 128;
00051 vec_t light;
00052 int i;
00053
00054 fprintf (glview, "%i\n", w->numpoints);
00055 level+=28;
00056 light = (level&255)/255.0;
00057 for (i=0 ; i<w->numpoints ; i++)
00058 {
00059 fprintf (glview, "%6.3f %6.3f %6.3f %6.3f %6.3f %6.3f\n",
00060 w->p[i][0],
00061 w->p[i][1],
00062 w->p[i][2],
00063 light,
00064 light,
00065 light);
00066 }
00067 fprintf (glview, "\n");
00068 }
00069
00070
00071
00072
00073
00074
00075 void OutputPortal (portal_t *p, FILE *glview)
00076 {
00077 winding_t *w;
00078 int sides;
00079
00080 sides = PortalVisibleSides (p);
00081 if (!sides)
00082 return;
00083
00084 c_glfaces++;
00085
00086 w = p->winding;
00087
00088 if (sides == 2)
00089 w = ReverseWinding (w);
00090
00091 OutputWinding (w, glview);
00092
00093 if (sides == 2)
00094 FreeWinding(w);
00095 }
00096
00097
00098
00099
00100
00101
00102 void WriteGLView_r (node_t *node, FILE *glview)
00103 {
00104 portal_t *p, *nextp;
00105
00106 if (node->planenum != PLANENUM_LEAF)
00107 {
00108 WriteGLView_r (node->children[0], glview);
00109 WriteGLView_r (node->children[1], glview);
00110 return;
00111 }
00112
00113
00114 for (p=node->portals ; p ; p=nextp)
00115 {
00116 if (p->nodes[0] == node)
00117 {
00118 OutputPortal (p, glview);
00119 nextp = p->next[0];
00120 }
00121 else
00122 nextp = p->next[1];
00123 }
00124 }
00125
00126
00127
00128
00129
00130
00131 void WriteGLView (tree_t *tree, char *source)
00132 {
00133 char name[1024];
00134 FILE *glview;
00135
00136 c_glfaces = 0;
00137 sprintf (name, "%s%s.gl",outbase, source);
00138 _printf ("Writing %s\n", name);
00139
00140 glview = fopen (name, "w");
00141 if (!glview)
00142 Error ("Couldn't open %s", name);
00143 WriteGLView_r (tree->headnode, glview);
00144 fclose (glview);
00145
00146 _printf ("%5i c_glfaces\n", c_glfaces);
00147 }
00148