home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 22 / PCPP #22.iso / Quake2 / q2source_12_11 / utils3 / bsp / qbsp3 / glfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-09  |  2.0 KB  |  129 lines

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