Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

glfile.c

Go to the documentation of this file.
00001 /*
00002 ===========================================================================
00003 Copyright (C) 1999-2005 Id Software, Inc.
00004 
00005 This file is part of Quake III Arena source code.
00006 
00007 Quake III Arena source code is free software; you can redistribute it
00008 and/or modify it under the terms of the GNU General Public License as
00009 published by the Free Software Foundation; either version 2 of the License,
00010 or (at your option) any later version.
00011 
00012 Quake III Arena source code is distributed in the hope that it will be
00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Foobar; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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;       // outside
00033 
00034     fcon = p->nodes[0]->opaque;
00035     bcon = p->nodes[1]->opaque;
00036 
00037     // same contents never create a face
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 OutputPortal
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)     // back side
00089         w = ReverseWinding (w);
00090 
00091     OutputWinding (w, glview);
00092 
00093     if (sides == 2)
00094         FreeWinding(w);
00095 }
00096 
00097 /*
00098 =============
00099 WriteGLView_r
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     // write all the portals
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 WriteGLView
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 

Generated on Thu Aug 25 12:37:15 2005 for Quake III Arena by  doxygen 1.3.9.1