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]->contents;
00035     bcon = p->nodes[1]->contents;
00036 
00037     // same contents never create a face
00038     if (fcon == bcon)
00039         return 0;
00040 
00041     // FIXME: is this correct now?
00042     if (!fcon)
00043         return 1;
00044     if (!bcon)
00045         return 2;
00046     return 0;
00047 }
00048 
00049 void OutputWinding (winding_t *w, FILE *glview)
00050 {
00051     static  int level = 128;
00052     vec_t       light;
00053     int         i;
00054 
00055     fprintf (glview, "%i\n", w->numpoints);
00056     level+=28;
00057     light = (level&255)/255.0;
00058     for (i=0 ; i<w->numpoints ; i++)
00059     {
00060         fprintf (glview, "%6.3f %6.3f %6.3f %6.3f %6.3f %6.3f\n",
00061             w->p[i][0],
00062             w->p[i][1],
00063             w->p[i][2],
00064             light,
00065             light,
00066             light);
00067     }
00068     fprintf (glview, "\n");
00069 }
00070 
00071 /*
00072 =============
00073 OutputPortal
00074 =============
00075 */
00076 void OutputPortal (portal_t *p, FILE *glview)
00077 {
00078     winding_t   *w;
00079     int     sides;
00080 
00081     sides = PortalVisibleSides (p);
00082     if (!sides)
00083         return;
00084 
00085     c_glfaces++;
00086 
00087     w = p->winding;
00088 
00089     if (sides == 2)     // back side
00090         w = ReverseWinding (w);
00091 
00092     OutputWinding (w, glview);
00093 
00094     if (sides == 2)
00095         FreeWinding(w);
00096 }
00097 
00098 /*
00099 =============
00100 WriteGLView_r
00101 =============
00102 */
00103 void WriteGLView_r (node_t *node, FILE *glview)
00104 {
00105     portal_t    *p, *nextp;
00106 
00107     if (node->planenum != PLANENUM_LEAF)
00108     {
00109         WriteGLView_r (node->children[0], glview);
00110         WriteGLView_r (node->children[1], glview);
00111         return;
00112     }
00113 
00114     // write all the portals
00115     for (p=node->portals ; p ; p=nextp)
00116     {
00117         if (p->nodes[0] == node)
00118         {
00119             OutputPortal (p, glview);
00120             nextp = p->next[0];
00121         }
00122         else
00123             nextp = p->next[1];
00124     }
00125 }
00126 
00127 /*
00128 =============
00129 WriteGLView
00130 =============
00131 */
00132 void WriteGLView (tree_t *tree, char *source)
00133 {
00134     char    name[1024];
00135     FILE    *glview;
00136 
00137     c_glfaces = 0;
00138     sprintf (name, "%s%s.gl",outbase, source);
00139     printf ("Writing %s\n", name);
00140 
00141     glview = fopen (name, "w");
00142     if (!glview)
00143         Error ("Couldn't open %s", name);
00144     WriteGLView_r (tree->headnode, glview);
00145     fclose (glview);
00146 
00147     printf ("%5i c_glfaces\n", c_glfaces);
00148 }
00149 

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