2007-11-04 03:34:51 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
#include "qbsp.h"
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int c_glfaces;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int PortalVisibleSides( portal_t *p ){
|
|
|
|
int fcon, bcon;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !p->onnode ) {
|
|
|
|
return 0; // outside
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
fcon = p->nodes[0]->contents;
|
|
|
|
bcon = p->nodes[1]->contents;
|
|
|
|
|
|
|
|
// same contents never create a face
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( fcon == bcon ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// FIXME: is this correct now?
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !fcon ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( !bcon ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 2;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void OutputWinding( winding_t *w, FILE *glview ){
|
|
|
|
static int level = 128;
|
|
|
|
vec_t light;
|
|
|
|
int i;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
fprintf( glview, "%i\n", w->numpoints );
|
|
|
|
level += 28;
|
|
|
|
light = ( level & 255 ) / 255.0;
|
|
|
|
for ( i = 0 ; i < w->numpoints ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
fprintf( glview, "%6.3f %6.3f %6.3f %6.3f %6.3f %6.3f\n",
|
|
|
|
w->p[i][0],
|
|
|
|
w->p[i][1],
|
|
|
|
w->p[i][2],
|
|
|
|
light,
|
|
|
|
light,
|
|
|
|
light );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
fprintf( glview, "\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
OutputPortal
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void OutputPortal( portal_t *p, FILE *glview ){
|
|
|
|
winding_t *w;
|
|
|
|
int sides;
|
|
|
|
|
|
|
|
sides = PortalVisibleSides( p );
|
|
|
|
if ( !sides ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
c_glfaces++;
|
|
|
|
|
|
|
|
w = p->winding;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sides == 2 ) { // back side
|
|
|
|
w = ReverseWinding( w );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
OutputWinding( w, glview );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sides == 2 ) {
|
|
|
|
FreeWinding( w );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
WriteGLView_r
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void WriteGLView_r( node_t *node, FILE *glview ){
|
|
|
|
portal_t *p, *nextp;
|
|
|
|
|
|
|
|
if ( node->planenum != PLANENUM_LEAF ) {
|
|
|
|
WriteGLView_r( node->children[0], glview );
|
|
|
|
WriteGLView_r( node->children[1], glview );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// write all the portals
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( p = node->portals ; p ; p = nextp )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->nodes[0] == node ) {
|
|
|
|
OutputPortal( p, glview );
|
2007-11-04 03:34:51 +00:00
|
|
|
nextp = p->next[0];
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
nextp = p->next[1];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
WriteGLView
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void WriteGLView( tree_t *tree, char *source ){
|
|
|
|
char name[1024];
|
|
|
|
FILE *glview;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
c_glfaces = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( name, "%s%s.gl",outbase, source );
|
|
|
|
Sys_Printf( "Writing %s\n", name );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
glview = fopen( name, "w" );
|
|
|
|
if ( !glview ) {
|
|
|
|
Error( "Couldn't open %s", name );
|
|
|
|
}
|
|
|
|
WriteGLView_r( tree->headnode, glview );
|
|
|
|
fclose( glview );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "%5i c_glfaces\n", c_glfaces );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|