Implimented fragment level view frustum culling.
This commit is contained in:
parent
4c1ec83f52
commit
922f9e9ba1
3 changed files with 343 additions and 321 deletions
484
Scenery/obj.cxx
484
Scenery/obj.cxx
|
@ -1,27 +1,25 @@
|
||||||
/*
|
// obj.cxx -- routines to handle "sorta" WaveFront .obj format files.
|
||||||
* obj.cxx -- routines to handle "sorta" WaveFront .obj format files.
|
//
|
||||||
*
|
// Written by Curtis Olson, started October 1997.
|
||||||
* Written by Curtis Olson, started October 1997.
|
//
|
||||||
*
|
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
||||||
* Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
//
|
||||||
*
|
// This program is free software; you can redistribute it and/or
|
||||||
* This program is free software; you can redistribute it and/or
|
// modify it under the terms of the GNU General Public License as
|
||||||
* modify it under the terms of the GNU General Public License as
|
// published by the Free Software Foundation; either version 2 of the
|
||||||
* published by the Free Software Foundation; either version 2 of the
|
// License, or (at your option) any later version.
|
||||||
* License, or (at your option) any later version.
|
//
|
||||||
*
|
// This program is distributed in the hope that it will be useful, but
|
||||||
* This program is distributed in the hope that it will be useful, but
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
// General Public License for more details.
|
||||||
* General Public License for more details.
|
//
|
||||||
*
|
// You should have received a copy of the GNU General Public License
|
||||||
* You should have received a copy of the GNU General Public License
|
// along with this program; if not, write to the Free Software
|
||||||
* along with this program; if not, write to the Free Software
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
//
|
||||||
*
|
// $Id$
|
||||||
* $Id$
|
// (Log is kept at end of this file)
|
||||||
* (Log is kept at end of this file)
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
|
@ -56,7 +54,7 @@ static double nodes[MAXNODES][3];
|
||||||
static double normals[MAXNODES][3];
|
static double normals[MAXNODES][3];
|
||||||
|
|
||||||
|
|
||||||
/* given three points defining a triangle, calculate the normal */
|
// given three points defining a triangle, calculate the normal
|
||||||
static void calc_normal(double p1[3], double p2[3],
|
static void calc_normal(double p1[3], double p2[3],
|
||||||
double p3[3], double normal[3])
|
double p3[3], double normal[3])
|
||||||
{
|
{
|
||||||
|
@ -69,8 +67,8 @@ static void calc_normal(double p1[3], double p2[3],
|
||||||
MAT3cross_product(normal, v1, v2);
|
MAT3cross_product(normal, v1, v2);
|
||||||
MAT3_NORMALIZE_VEC(normal,temp);
|
MAT3_NORMALIZE_VEC(normal,temp);
|
||||||
|
|
||||||
/* fgPrintf( FG_TERRAIN, FG_DEBUG, " Normal = %.2f %.2f %.2f\n",
|
// fgPrintf( FG_TERRAIN, FG_DEBUG, " Normal = %.2f %.2f %.2f\n",
|
||||||
normal[0], normal[1], normal[2]);*/
|
// normal[0], normal[1], normal[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,7 +93,7 @@ fgPolarPoint3d calc_tex_coords(double *node, fgCartesianPoint3d *ref) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Load a .obj file and build the GL fragment list */
|
// Load a .obj file and build the GL fragment list
|
||||||
int fgObjLoad(char *path, fgTILE *tile) {
|
int fgObjLoad(char *path, fgTILE *tile) {
|
||||||
fgOPTIONS *o;
|
fgOPTIONS *o;
|
||||||
fgFRAGMENT fragment;
|
fgFRAGMENT fragment;
|
||||||
|
@ -106,7 +104,7 @@ int fgObjLoad(char *path, fgTILE *tile) {
|
||||||
// GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 };
|
// GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 };
|
||||||
GLint display_list;
|
GLint display_list;
|
||||||
fgFile f;
|
fgFile f;
|
||||||
int first, ncount, vncount, n1, n2, n3, n4;
|
int in_fragment, in_faces, ncount, vncount, n1, n2, n3, n4;
|
||||||
int last1, last2, odd;
|
int last1, last2, odd;
|
||||||
|
|
||||||
o = ¤t_options;
|
o = ¤t_options;
|
||||||
|
@ -131,50 +129,43 @@ int fgObjLoad(char *path, fgTILE *tile) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
display_list = xglGenLists(1);
|
in_fragment = 0;
|
||||||
xglNewList(display_list, GL_COMPILE);
|
|
||||||
|
|
||||||
first = 1;
|
|
||||||
ncount = 1;
|
ncount = 1;
|
||||||
vncount = 1;
|
vncount = 1;
|
||||||
tile->bounding_radius = 0.0;
|
tile->bounding_radius = 0.0;
|
||||||
|
|
||||||
while ( fggets(f, line, 250) != NULL ) {
|
while ( fggets(f, line, 250) != NULL ) {
|
||||||
if ( line[0] == '#' ) {
|
if ( line[0] == '#' ) {
|
||||||
/* comment -- ignore */
|
// comment -- ignore
|
||||||
} else if ( line[0] == '\n' ) {
|
} else if ( line[0] == '\n' ) {
|
||||||
/* empty line -- ignore */
|
// empty line -- ignore
|
||||||
} else if ( strncmp(line, "gb ", 3) == 0 ) {
|
} else if ( strncmp(line, "gbs ", 4) == 0 ) {
|
||||||
/* reference point (center offset) */
|
// reference point (center offset)
|
||||||
sscanf(line, "gb %lf %lf %lf %lf\n",
|
sscanf(line, "gbs %lf %lf %lf %lf\n",
|
||||||
&tile->center.x, &tile->center.y, &tile->center.z,
|
&tile->center.x, &tile->center.y, &tile->center.z,
|
||||||
&tile->bounding_radius);
|
&tile->bounding_radius);
|
||||||
|
} else if ( strncmp(line, "bs ", 3) == 0 ) {
|
||||||
|
// reference point (center offset)
|
||||||
|
sscanf(line, "bs %lf %lf %lf %lf\n",
|
||||||
|
&fragment.center.x, &fragment.center.y, &fragment.center.z,
|
||||||
|
&fragment.bounding_radius);
|
||||||
} else if ( strncmp(line, "v ", 2) == 0 ) {
|
} else if ( strncmp(line, "v ", 2) == 0 ) {
|
||||||
/* node (vertex) */
|
// node (vertex)
|
||||||
if ( ncount < MAXNODES ) {
|
if ( ncount < MAXNODES ) {
|
||||||
/* fgPrintf( FG_TERRAIN, FG_DEBUG, "vertex = %s", line); */
|
// fgPrintf( FG_TERRAIN, FG_DEBUG, "vertex = %s", line);
|
||||||
sscanf(line, "v %lf %lf %lf\n",
|
sscanf(line, "v %lf %lf %lf\n",
|
||||||
&nodes[ncount][0], &nodes[ncount][1],
|
&nodes[ncount][0], &nodes[ncount][1],
|
||||||
&nodes[ncount][2]);
|
&nodes[ncount][2]);
|
||||||
|
|
||||||
// temporary code to calculate bounding radius
|
|
||||||
// dist = calc_dist(nodes[ncount]);
|
|
||||||
// printf("node = %.2f %.2f %.2f dist = %.2f\n",
|
|
||||||
// nodes[ncount][0], nodes[ncount][1], nodes[ncount][2],
|
|
||||||
// dist);
|
|
||||||
// if ( (dist > *radius) && (dist < 100000.0) ) {
|
|
||||||
// *radius = dist;
|
|
||||||
// }
|
|
||||||
|
|
||||||
ncount++;
|
ncount++;
|
||||||
} else {
|
} else {
|
||||||
fgPrintf( FG_TERRAIN, FG_EXIT,
|
fgPrintf( FG_TERRAIN, FG_EXIT,
|
||||||
"Read too many nodes ... dying :-(\n");
|
"Read too many nodes ... dying :-(\n");
|
||||||
}
|
}
|
||||||
} else if ( strncmp(line, "vn ", 3) == 0 ) {
|
} else if ( strncmp(line, "vn ", 3) == 0 ) {
|
||||||
/* vertex normal */
|
// vertex normal
|
||||||
if ( vncount < MAXNODES ) {
|
if ( vncount < MAXNODES ) {
|
||||||
/* fgPrintf( FG_TERRAIN, FG_DEBUG, "vertex normal = %s", line); */
|
// fgPrintf( FG_TERRAIN, FG_DEBUG, "vertex normal = %s", line);
|
||||||
sscanf(line, "vn %lf %lf %lf\n",
|
sscanf(line, "vn %lf %lf %lf\n",
|
||||||
&normals[vncount][0], &normals[vncount][1],
|
&normals[vncount][0], &normals[vncount][1],
|
||||||
&normals[vncount][2]);
|
&normals[vncount][2]);
|
||||||
|
@ -184,25 +175,38 @@ int fgObjLoad(char *path, fgTILE *tile) {
|
||||||
"Read too many vertex normals ... dying :-(\n");
|
"Read too many vertex normals ... dying :-(\n");
|
||||||
}
|
}
|
||||||
} else if ( strncmp(line, "usemtl ", 7) == 0 ) {
|
} else if ( strncmp(line, "usemtl ", 7) == 0 ) {
|
||||||
/* material property specification */
|
// material property specification
|
||||||
|
|
||||||
|
// this also signals the start of a new fragment
|
||||||
|
if ( in_fragment ) {
|
||||||
|
// close out the previous structure and start the next
|
||||||
|
xglEnd();
|
||||||
|
xglEndList();
|
||||||
|
|
||||||
|
// update fragment
|
||||||
|
fragment.display_list = display_list;
|
||||||
|
|
||||||
|
// push this fragment onto the tile's object list
|
||||||
|
tile->fragment_list.push_back(fragment);
|
||||||
|
} else {
|
||||||
|
in_fragment = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
display_list = xglGenLists(1);
|
||||||
|
xglNewList(display_list, GL_COMPILE);
|
||||||
|
in_faces = 0;
|
||||||
|
|
||||||
|
// scan the material line
|
||||||
sscanf(line, "usemtl %s\n", material);
|
sscanf(line, "usemtl %s\n", material);
|
||||||
} else if ( line[0] == 't' ) {
|
} else if ( line[0] == 't' ) {
|
||||||
/* start a new triangle strip */
|
// start a new triangle strip
|
||||||
|
|
||||||
n1 = n2 = n3 = n4 = 0;
|
n1 = n2 = n3 = n4 = 0;
|
||||||
|
|
||||||
if ( !first ) {
|
// fgPrintf( FG_TERRAIN, FG_DEBUG, " new tri strip = %s", line);
|
||||||
/* close out the previous structure and start the next */
|
|
||||||
xglEnd();
|
|
||||||
} else {
|
|
||||||
first = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* fgPrintf( FG_TERRAIN, FG_DEBUG, " new tri strip = %s",
|
|
||||||
line); */
|
|
||||||
sscanf(line, "t %d %d %d %d\n", &n1, &n2, &n3, &n4);
|
sscanf(line, "t %d %d %d %d\n", &n1, &n2, &n3, &n4);
|
||||||
|
|
||||||
/* fgPrintf( FG_TERRAIN, FG_DEBUG, "(t) = "); */
|
// fgPrintf( FG_TERRAIN, FG_DEBUG, "(t) = ");
|
||||||
|
|
||||||
xglBegin(GL_TRIANGLE_STRIP);
|
xglBegin(GL_TRIANGLE_STRIP);
|
||||||
|
|
||||||
|
@ -278,18 +282,14 @@ int fgObjLoad(char *path, fgTILE *tile) {
|
||||||
last2 = n4;
|
last2 = n4;
|
||||||
}
|
}
|
||||||
} else if ( line[0] == 'f' ) {
|
} else if ( line[0] == 'f' ) {
|
||||||
/* unoptimized face */
|
// unoptimized face
|
||||||
|
|
||||||
if ( !first ) {
|
if ( !in_faces ) {
|
||||||
/* close out the previous structure and start the next */
|
xglBegin(GL_TRIANGLES);
|
||||||
xglEnd();
|
in_faces = 1;
|
||||||
} else {
|
|
||||||
first = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xglBegin(GL_TRIANGLES);
|
// fgPrintf( FG_TERRAIN, FG_DEBUG, "new triangle = %s", line);*/
|
||||||
|
|
||||||
/* fgPrintf( FG_TERRAIN, FG_DEBUG, "new triangle = %s", line);*/
|
|
||||||
sscanf(line, "f %d %d %d\n", &n1, &n2, &n3);
|
sscanf(line, "f %d %d %d\n", &n1, &n2, &n3);
|
||||||
|
|
||||||
xglNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]);
|
xglNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]);
|
||||||
|
@ -307,13 +307,13 @@ int fgObjLoad(char *path, fgTILE *tile) {
|
||||||
xglTexCoord2f(pp.lon, pp.lat);
|
xglTexCoord2f(pp.lon, pp.lat);
|
||||||
xglVertex3d(nodes[n3][0], nodes[n3][1], nodes[n3][2]);
|
xglVertex3d(nodes[n3][0], nodes[n3][1], nodes[n3][2]);
|
||||||
} else if ( line[0] == 'q' ) {
|
} else if ( line[0] == 'q' ) {
|
||||||
/* continue a triangle strip */
|
// continue a triangle strip
|
||||||
n1 = n2 = 0;
|
n1 = n2 = 0;
|
||||||
|
|
||||||
/* fgPrintf( FG_TERRAIN, FG_DEBUG, "continued tri strip = %s ",
|
// fgPrintf( FG_TERRAIN, FG_DEBUG, "continued tri strip = %s ",
|
||||||
line); */
|
// line);
|
||||||
sscanf(line, "q %d %d\n", &n1, &n2);
|
sscanf(line, "q %d %d\n", &n1, &n2);
|
||||||
/* fgPrintf( FG_TERRAIN, FG_DEBUG, "read %d %d\n", n1, n2); */
|
// fgPrintf( FG_TERRAIN, FG_DEBUG, "read %d %d\n", n1, n2);
|
||||||
|
|
||||||
if ( o->shading ) {
|
if ( o->shading ) {
|
||||||
// Shading model is "GL_SMOOTH"
|
// Shading model is "GL_SMOOTH"
|
||||||
|
@ -341,7 +341,7 @@ int fgObjLoad(char *path, fgTILE *tile) {
|
||||||
last2 = n1;
|
last2 = n1;
|
||||||
|
|
||||||
if ( n2 > 0 ) {
|
if ( n2 > 0 ) {
|
||||||
/* fgPrintf( FG_TERRAIN, FG_DEBUG, " (cont)\n"); */
|
// fgPrintf( FG_TERRAIN, FG_DEBUG, " (cont)\n");
|
||||||
|
|
||||||
if ( o->shading ) {
|
if ( o->shading ) {
|
||||||
// Shading model is "GL_SMOOTH"
|
// Shading model is "GL_SMOOTH"
|
||||||
|
@ -374,9 +374,19 @@ int fgObjLoad(char *path, fgTILE *tile) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xglEnd();
|
if ( in_fragment ) {
|
||||||
|
// close out the previous structure and start the next
|
||||||
|
xglEnd();
|
||||||
|
xglEndList();
|
||||||
|
|
||||||
/* Draw normal vectors (for visually verifying normals)*/
|
// update fragment
|
||||||
|
fragment.display_list = display_list;
|
||||||
|
|
||||||
|
// push this fragment onto the tile's object list
|
||||||
|
tile->fragment_list.push_back(fragment);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw normal vectors (for visually verifying normals)
|
||||||
/*
|
/*
|
||||||
xglBegin(GL_LINES);
|
xglBegin(GL_LINES);
|
||||||
xglColor3f(0.0, 0.0, 0.0);
|
xglColor3f(0.0, 0.0, 0.0);
|
||||||
|
@ -389,171 +399,165 @@ int fgObjLoad(char *path, fgTILE *tile) {
|
||||||
nodes[i][2] + 500*normals[i][2]);
|
nodes[i][2] + 500*normals[i][2]);
|
||||||
}
|
}
|
||||||
xglEnd();
|
xglEnd();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
xglEndList();
|
|
||||||
|
|
||||||
fgclose(f);
|
fgclose(f);
|
||||||
|
|
||||||
// temporary: create a fragment
|
|
||||||
fragment.center = tile->center;
|
|
||||||
fragment.bounding_radius = tile->bounding_radius;
|
|
||||||
fragment.display_list = display_list;
|
|
||||||
|
|
||||||
// temporary: push this fragment onto the tile's object list
|
|
||||||
tile->fragment_list.push_back(fragment);
|
|
||||||
|
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* $Log$
|
// $Log$
|
||||||
/* Revision 1.6 1998/05/23 14:09:20 curt
|
// Revision 1.7 1998/05/24 02:49:09 curt
|
||||||
/* Added tile.cxx and tile.hxx.
|
// Implimented fragment level view frustum culling.
|
||||||
/* Working on rewriting the tile management system so a tile is just a list
|
//
|
||||||
/* fragments, and the fragment record contains the display list for that fragment.
|
// Revision 1.6 1998/05/23 14:09:20 curt
|
||||||
/*
|
// Added tile.cxx and tile.hxx.
|
||||||
* Revision 1.5 1998/05/20 20:53:53 curt
|
// Working on rewriting the tile management system so a tile is just a list
|
||||||
* Moved global ref point and radius (bounding sphere info, and offset) to
|
// fragments, and the fragment record contains the display list for that
|
||||||
* data file rather than calculating it on the fly.
|
// fragment.
|
||||||
* Fixed polygon winding problem in scenery generation stage rather than
|
//
|
||||||
* compensating for it on the fly.
|
// Revision 1.5 1998/05/20 20:53:53 curt
|
||||||
* Made a fgTILECACHE class.
|
// Moved global ref point and radius (bounding sphere info, and offset) to
|
||||||
*
|
// data file rather than calculating it on the fly.
|
||||||
* Revision 1.4 1998/05/16 13:09:57 curt
|
// Fixed polygon winding problem in scenery generation stage rather than
|
||||||
* Beginning to add support for view frustum culling.
|
// compensating for it on the fly.
|
||||||
* Added some temporary code to calculate bouding radius, until the
|
// Made a fgTILECACHE class.
|
||||||
* scenery generation tools and scenery can be updated.
|
//
|
||||||
*
|
// Revision 1.4 1998/05/16 13:09:57 curt
|
||||||
* Revision 1.3 1998/05/03 00:48:01 curt
|
// Beginning to add support for view frustum culling.
|
||||||
* Updated texture coordinate fmod() parameter.
|
// Added some temporary code to calculate bouding radius, until the
|
||||||
*
|
// scenery generation tools and scenery can be updated.
|
||||||
* Revision 1.2 1998/05/02 01:52:14 curt
|
//
|
||||||
* Playing around with texture coordinates.
|
// Revision 1.3 1998/05/03 00:48:01 curt
|
||||||
*
|
// Updated texture coordinate fmod() parameter.
|
||||||
* Revision 1.1 1998/04/30 12:35:28 curt
|
//
|
||||||
* Added a command line rendering option specify smooth/flat shading.
|
// Revision 1.2 1998/05/02 01:52:14 curt
|
||||||
*
|
// Playing around with texture coordinates.
|
||||||
* Revision 1.35 1998/04/28 21:43:26 curt
|
//
|
||||||
* Wrapped zlib calls up so we can conditionally comment out zlib support.
|
// Revision 1.1 1998/04/30 12:35:28 curt
|
||||||
*
|
// Added a command line rendering option specify smooth/flat shading.
|
||||||
* Revision 1.34 1998/04/28 01:21:42 curt
|
//
|
||||||
* Tweaked texture parameter calculations to keep the number smaller. This
|
// Revision 1.35 1998/04/28 21:43:26 curt
|
||||||
* avoids the "swimming" problem.
|
// Wrapped zlib calls up so we can conditionally comment out zlib support.
|
||||||
* Type-ified fgTIME and fgVIEW.
|
//
|
||||||
*
|
// Revision 1.34 1998/04/28 01:21:42 curt
|
||||||
* Revision 1.33 1998/04/27 15:58:15 curt
|
// Tweaked texture parameter calculations to keep the number smaller. This
|
||||||
* Screwing around with texture coordinate generation ... still needs work.
|
// avoids the "swimming" problem.
|
||||||
*
|
// Type-ified fgTIME and fgVIEW.
|
||||||
* Revision 1.32 1998/04/27 03:30:13 curt
|
//
|
||||||
* Minor transformation adjustments to try to keep scenery tiles closer to
|
// Revision 1.33 1998/04/27 15:58:15 curt
|
||||||
* (0, 0, 0) GLfloats run out of precision at the distances we need to model
|
// Screwing around with texture coordinate generation ... still needs work.
|
||||||
* the earth, but we can do a bunch of pre-transformations using double math
|
//
|
||||||
* and then cast to GLfloat once everything is close in where we have less
|
// Revision 1.32 1998/04/27 03:30:13 curt
|
||||||
* precision problems.
|
// Minor transformation adjustments to try to keep scenery tiles closer to
|
||||||
*
|
// (0, 0, 0) GLfloats run out of precision at the distances we need to model
|
||||||
* Revision 1.31 1998/04/25 15:09:57 curt
|
// the earth, but we can do a bunch of pre-transformations using double math
|
||||||
* Changed "r" to "rb" in gzopen() options. This fixes bad behavior in win32.
|
// and then cast to GLfloat once everything is close in where we have less
|
||||||
*
|
// precision problems.
|
||||||
* Revision 1.30 1998/04/24 14:21:08 curt
|
//
|
||||||
* Added "file.obj.gz" support.
|
// Revision 1.31 1998/04/25 15:09:57 curt
|
||||||
*
|
// Changed "r" to "rb" in gzopen() options. This fixes bad behavior in win32.
|
||||||
* Revision 1.29 1998/04/24 00:51:07 curt
|
//
|
||||||
* Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
|
// Revision 1.30 1998/04/24 14:21:08 curt
|
||||||
* Tweaked the scenery file extentions to be "file.obj" (uncompressed)
|
// Added "file.obj.gz" support.
|
||||||
* or "file.obz" (compressed.)
|
//
|
||||||
*
|
// Revision 1.29 1998/04/24 00:51:07 curt
|
||||||
* Revision 1.28 1998/04/22 13:22:44 curt
|
// Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
|
||||||
* C++ - ifing the code a bit.
|
// Tweaked the scenery file extentions to be "file.obj" (uncompressed)
|
||||||
*
|
// or "file.obz" (compressed.)
|
||||||
* Revision 1.27 1998/04/18 04:13:17 curt
|
//
|
||||||
* Added zlib on the fly decompression support for loading scenery objects.
|
// Revision 1.28 1998/04/22 13:22:44 curt
|
||||||
*
|
// C++ - ifing the code a bit.
|
||||||
* Revision 1.26 1998/04/03 22:11:36 curt
|
//
|
||||||
* Converting to Gnu autoconf system.
|
// Revision 1.27 1998/04/18 04:13:17 curt
|
||||||
*
|
// Added zlib on the fly decompression support for loading scenery objects.
|
||||||
* Revision 1.25 1998/03/14 00:30:50 curt
|
//
|
||||||
* Beginning initial terrain texturing experiments.
|
// Revision 1.26 1998/04/03 22:11:36 curt
|
||||||
*
|
// Converting to Gnu autoconf system.
|
||||||
* Revision 1.24 1998/02/09 21:30:18 curt
|
//
|
||||||
* Fixed a nagging problem with terrain tiles not "quite" matching up perfectly.
|
// Revision 1.25 1998/03/14 00:30:50 curt
|
||||||
*
|
// Beginning initial terrain texturing experiments.
|
||||||
* Revision 1.23 1998/02/09 15:07:52 curt
|
//
|
||||||
* Minor tweaks.
|
// Revision 1.24 1998/02/09 21:30:18 curt
|
||||||
*
|
// Fixed a nagging problem with terrain tiles not "quite" matching up perfectly.
|
||||||
* Revision 1.22 1998/02/01 03:39:54 curt
|
//
|
||||||
* Minor tweaks.
|
// Revision 1.23 1998/02/09 15:07:52 curt
|
||||||
*
|
// Minor tweaks.
|
||||||
* Revision 1.21 1998/01/31 00:43:25 curt
|
//
|
||||||
* Added MetroWorks patches from Carmen Volpe.
|
// Revision 1.22 1998/02/01 03:39:54 curt
|
||||||
*
|
// Minor tweaks.
|
||||||
* Revision 1.20 1998/01/29 00:51:39 curt
|
//
|
||||||
* First pass at tile cache, dynamic tile loading and tile unloading now works.
|
// Revision 1.21 1998/01/31 00:43:25 curt
|
||||||
*
|
// Added MetroWorks patches from Carmen Volpe.
|
||||||
* Revision 1.19 1998/01/27 03:26:42 curt
|
//
|
||||||
* Playing with new fgPrintf command.
|
// Revision 1.20 1998/01/29 00:51:39 curt
|
||||||
*
|
// First pass at tile cache, dynamic tile loading and tile unloading now works.
|
||||||
* Revision 1.18 1998/01/19 19:27:16 curt
|
//
|
||||||
* Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
// Revision 1.19 1998/01/27 03:26:42 curt
|
||||||
* This should simplify things tremendously.
|
// Playing with new fgPrintf command.
|
||||||
*
|
//
|
||||||
* Revision 1.17 1998/01/13 00:23:10 curt
|
// Revision 1.18 1998/01/19 19:27:16 curt
|
||||||
* Initial changes to support loading and management of scenery tiles. Note,
|
// Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
||||||
* there's still a fair amount of work left to be done.
|
// This should simplify things tremendously.
|
||||||
*
|
//
|
||||||
* Revision 1.16 1997/12/30 23:09:40 curt
|
// Revision 1.17 1998/01/13 00:23:10 curt
|
||||||
* Worked on winding problem without luck, so back to calling glFrontFace()
|
// Initial changes to support loading and management of scenery tiles. Note,
|
||||||
* 3 times for each scenery area.
|
// there's still a fair amount of work left to be done.
|
||||||
*
|
//
|
||||||
* Revision 1.15 1997/12/30 20:47:51 curt
|
// Revision 1.16 1997/12/30 23:09:40 curt
|
||||||
* Integrated new event manager with subsystem initializations.
|
// Worked on winding problem without luck, so back to calling glFrontFace()
|
||||||
*
|
// 3 times for each scenery area.
|
||||||
* Revision 1.14 1997/12/30 01:38:46 curt
|
//
|
||||||
* Switched back to per vertex normals and smooth shading for terrain.
|
// Revision 1.15 1997/12/30 20:47:51 curt
|
||||||
*
|
// Integrated new event manager with subsystem initializations.
|
||||||
* Revision 1.13 1997/12/18 23:32:36 curt
|
//
|
||||||
* First stab at sky dome actually starting to look reasonable. :-)
|
// Revision 1.14 1997/12/30 01:38:46 curt
|
||||||
*
|
// Switched back to per vertex normals and smooth shading for terrain.
|
||||||
* Revision 1.12 1997/12/17 23:13:47 curt
|
//
|
||||||
* Began working on rendering the sky.
|
// Revision 1.13 1997/12/18 23:32:36 curt
|
||||||
*
|
// First stab at sky dome actually starting to look reasonable. :-)
|
||||||
* Revision 1.11 1997/12/15 23:55:01 curt
|
//
|
||||||
* Add xgl wrappers for debugging.
|
// Revision 1.12 1997/12/17 23:13:47 curt
|
||||||
* Generate terrain normals on the fly.
|
// Began working on rendering the sky.
|
||||||
*
|
//
|
||||||
* Revision 1.10 1997/12/12 21:41:28 curt
|
// Revision 1.11 1997/12/15 23:55:01 curt
|
||||||
* More light/material property tweaking ... still a ways off.
|
// Add xgl wrappers for debugging.
|
||||||
*
|
// Generate terrain normals on the fly.
|
||||||
* Revision 1.9 1997/12/12 19:52:57 curt
|
//
|
||||||
* Working on lightling and material properties.
|
// Revision 1.10 1997/12/12 21:41:28 curt
|
||||||
*
|
// More light/material property tweaking ... still a ways off.
|
||||||
* Revision 1.8 1997/12/10 01:19:51 curt
|
//
|
||||||
* Tweaks for verion 0.15 release.
|
// Revision 1.9 1997/12/12 19:52:57 curt
|
||||||
*
|
// Working on lightling and material properties.
|
||||||
* Revision 1.7 1997/12/08 22:51:17 curt
|
//
|
||||||
* Enhanced to handle ccw and cw tri-stripe winding. This is a temporary
|
// Revision 1.8 1997/12/10 01:19:51 curt
|
||||||
* admission of defeat. I will eventually go back and get all the stripes
|
// Tweaks for verion 0.15 release.
|
||||||
* wound the same way (ccw).
|
//
|
||||||
*
|
// Revision 1.7 1997/12/08 22:51:17 curt
|
||||||
* Revision 1.6 1997/11/25 19:25:35 curt
|
// Enhanced to handle ccw and cw tri-stripe winding. This is a temporary
|
||||||
* Changes to integrate Durk's moon/sun code updates + clean up.
|
// admission of defeat. I will eventually go back and get all the stripes
|
||||||
*
|
// wound the same way (ccw).
|
||||||
* Revision 1.5 1997/11/15 18:16:39 curt
|
//
|
||||||
* minor tweaks.
|
// Revision 1.6 1997/11/25 19:25:35 curt
|
||||||
*
|
// Changes to integrate Durk's moon/sun code updates + clean up.
|
||||||
* Revision 1.4 1997/11/14 00:26:49 curt
|
//
|
||||||
* Transform scenery coordinates earlier in pipeline when scenery is being
|
// Revision 1.5 1997/11/15 18:16:39 curt
|
||||||
* created, not when it is being loaded. Precalculate normals for each node
|
// minor tweaks.
|
||||||
* as average of the normals of each containing polygon so Garoude shading is
|
//
|
||||||
* now supportable.
|
// Revision 1.4 1997/11/14 00:26:49 curt
|
||||||
*
|
// Transform scenery coordinates earlier in pipeline when scenery is being
|
||||||
* Revision 1.3 1997/10/31 04:49:12 curt
|
// created, not when it is being loaded. Precalculate normals for each node
|
||||||
* Tweaking vertex orders.
|
// as average of the normals of each containing polygon so Garoude shading is
|
||||||
*
|
// now supportable.
|
||||||
* Revision 1.2 1997/10/30 12:38:45 curt
|
//
|
||||||
* Working on new scenery subsystem.
|
// Revision 1.3 1997/10/31 04:49:12 curt
|
||||||
*
|
// Tweaking vertex orders.
|
||||||
* Revision 1.1 1997/10/28 21:14:54 curt
|
//
|
||||||
* Initial revision.
|
// Revision 1.2 1997/10/30 12:38:45 curt
|
||||||
*
|
// Working on new scenery subsystem.
|
||||||
*/
|
//
|
||||||
|
// Revision 1.1 1997/10/28 21:14:54 curt
|
||||||
|
// Initial revision.
|
||||||
|
|
||||||
|
|
||||||
|
|
156
Scenery/obj.hxx
156
Scenery/obj.hxx
|
@ -1,27 +1,25 @@
|
||||||
/**************************************************************************
|
// obj.hxx -- routines to handle WaveFront .obj-ish format files.
|
||||||
* obj.hxx -- routines to handle WaveFront .obj-ish format files.
|
//
|
||||||
*
|
// Written by Curtis Olson, started October 1997.
|
||||||
* Written by Curtis Olson, started October 1997.
|
//
|
||||||
*
|
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
||||||
* Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
//
|
||||||
*
|
// This program is free software; you can redistribute it and/or
|
||||||
* This program is free software; you can redistribute it and/or
|
// modify it under the terms of the GNU General Public License as
|
||||||
* modify it under the terms of the GNU General Public License as
|
// published by the Free Software Foundation; either version 2 of the
|
||||||
* published by the Free Software Foundation; either version 2 of the
|
// License, or (at your option) any later version.
|
||||||
* License, or (at your option) any later version.
|
//
|
||||||
*
|
// This program is distributed in the hope that it will be useful, but
|
||||||
* This program is distributed in the hope that it will be useful, but
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
// General Public License for more details.
|
||||||
* General Public License for more details.
|
//
|
||||||
*
|
// You should have received a copy of the GNU General Public License
|
||||||
* You should have received a copy of the GNU General Public License
|
// along with this program; if not, write to the Free Software
|
||||||
* along with this program; if not, write to the Free Software
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
//
|
||||||
*
|
// $Id$
|
||||||
* $Id$
|
// (Log is kept at end of this file)
|
||||||
* (Log is kept at end of this file)
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef _OBJ_HXX
|
#ifndef _OBJ_HXX
|
||||||
|
@ -48,62 +46,64 @@
|
||||||
#include "tile.hxx"
|
#include "tile.hxx"
|
||||||
|
|
||||||
|
|
||||||
/* Load a .obj file and build the GL fragment list */
|
// Load a .obj file and build the GL fragment list
|
||||||
int fgObjLoad(char *path, fgTILE *tile);
|
int fgObjLoad(char *path, fgTILE *tile);
|
||||||
// GLint fgObjLoad(char *path, fgCartesianPoint3d *ref, double *radius) {
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* _OBJ_HXX */
|
#endif // _OBJ_HXX
|
||||||
|
|
||||||
|
|
||||||
/* $Log$
|
// $Log$
|
||||||
/* Revision 1.3 1998/05/23 14:09:21 curt
|
// Revision 1.4 1998/05/24 02:49:10 curt
|
||||||
/* Added tile.cxx and tile.hxx.
|
// Implimented fragment level view frustum culling.
|
||||||
/* Working on rewriting the tile management system so a tile is just a list
|
//
|
||||||
/* fragments, and the fragment record contains the display list for that fragment.
|
// Revision 1.3 1998/05/23 14:09:21 curt
|
||||||
/*
|
// Added tile.cxx and tile.hxx.
|
||||||
* Revision 1.2 1998/05/02 01:52:15 curt
|
// Working on rewriting the tile management system so a tile is just a list
|
||||||
* Playing around with texture coordinates.
|
// fragments, and the fragment record contains the display list for that
|
||||||
*
|
// fragment.
|
||||||
* Revision 1.1 1998/04/30 12:35:29 curt
|
//
|
||||||
* Added a command line rendering option specify smooth/flat shading.
|
// Revision 1.2 1998/05/02 01:52:15 curt
|
||||||
*
|
// Playing around with texture coordinates.
|
||||||
* Revision 1.11 1998/04/25 22:06:31 curt
|
//
|
||||||
* Edited cvs log messages in source files ... bad bad bad!
|
// Revision 1.1 1998/04/30 12:35:29 curt
|
||||||
*
|
// Added a command line rendering option specify smooth/flat shading.
|
||||||
* Revision 1.10 1998/04/24 00:51:07 curt
|
//
|
||||||
* Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
|
// Revision 1.11 1998/04/25 22:06:31 curt
|
||||||
* Tweaked the scenery file extentions to be "file.obj" (uncompressed)
|
// Edited cvs log messages in source files ... bad bad bad!
|
||||||
* or "file.obz" (compressed.)
|
//
|
||||||
*
|
// Revision 1.10 1998/04/24 00:51:07 curt
|
||||||
* Revision 1.9 1998/04/22 13:22:45 curt
|
// Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
|
||||||
* C++ - ifing the code a bit.
|
// Tweaked the scenery file extentions to be "file.obj" (uncompressed)
|
||||||
*
|
// or "file.obz" (compressed.)
|
||||||
* Revision 1.8 1998/04/21 17:02:43 curt
|
//
|
||||||
* Prepairing for C++ integration.
|
// Revision 1.9 1998/04/22 13:22:45 curt
|
||||||
*
|
// C++ - ifing the code a bit.
|
||||||
* Revision 1.7 1998/04/03 22:11:37 curt
|
//
|
||||||
* Converting to Gnu autoconf system.
|
// Revision 1.8 1998/04/21 17:02:43 curt
|
||||||
*
|
// Prepairing for C++ integration.
|
||||||
* Revision 1.6 1998/01/31 00:43:25 curt
|
//
|
||||||
* Added MetroWorks patches from Carmen Volpe.
|
// Revision 1.7 1998/04/03 22:11:37 curt
|
||||||
*
|
// Converting to Gnu autoconf system.
|
||||||
* Revision 1.5 1998/01/27 00:48:03 curt
|
//
|
||||||
* Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
|
// Revision 1.6 1998/01/31 00:43:25 curt
|
||||||
* system and commandline/config file processing code.
|
// Added MetroWorks patches from Carmen Volpe.
|
||||||
*
|
//
|
||||||
* Revision 1.4 1998/01/22 02:59:41 curt
|
// Revision 1.5 1998/01/27 00:48:03 curt
|
||||||
* Changed #ifdef FILE_H to #ifdef _FILE_H
|
// Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
|
||||||
*
|
// system and commandline/config file processing code.
|
||||||
* Revision 1.3 1998/01/19 19:27:17 curt
|
//
|
||||||
* Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
// Revision 1.4 1998/01/22 02:59:41 curt
|
||||||
* This should simplify things tremendously.
|
// Changed #ifdef FILE_H to #ifdef _FILE_H
|
||||||
*
|
//
|
||||||
* Revision 1.2 1998/01/13 00:23:10 curt
|
// Revision 1.3 1998/01/19 19:27:17 curt
|
||||||
* Initial changes to support loading and management of scenery tiles. Note,
|
// Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
||||||
* there's still a fair amount of work left to be done.
|
// This should simplify things tremendously.
|
||||||
*
|
//
|
||||||
* Revision 1.1 1997/10/28 21:14:55 curt
|
// Revision 1.2 1998/01/13 00:23:10 curt
|
||||||
* Initial revision.
|
// Initial changes to support loading and management of scenery tiles. Note,
|
||||||
*
|
// there's still a fair amount of work left to be done.
|
||||||
*/
|
//
|
||||||
|
// Revision 1.1 1997/10/28 21:14:55 curt
|
||||||
|
// Initial revision.
|
||||||
|
|
||||||
|
|
|
@ -329,6 +329,7 @@ void fgTileMgrRender( void ) {
|
||||||
offset.y = t->center.y - scenery.center.y;
|
offset.y = t->center.y - scenery.center.y;
|
||||||
offset.z = t->center.z - scenery.center.z;
|
offset.z = t->center.z - scenery.center.z;
|
||||||
|
|
||||||
|
// Course (tile based) culling
|
||||||
if ( viewable(&offset, t->bounding_radius) ) {
|
if ( viewable(&offset, t->bounding_radius) ) {
|
||||||
// at least a portion of this tile is viewable
|
// at least a portion of this tile is viewable
|
||||||
|
|
||||||
|
@ -343,22 +344,39 @@ void fgTileMgrRender( void ) {
|
||||||
fragment = *current++;
|
fragment = *current++;
|
||||||
|
|
||||||
if ( fragment.display_list >= 0 ) {
|
if ( fragment.display_list >= 0 ) {
|
||||||
xglCallList(fragment.display_list);
|
// Fine (fragment based) culling
|
||||||
|
offset.x = fragment.center.x - scenery.center.x;
|
||||||
|
offset.y = fragment.center.y - scenery.center.y;
|
||||||
|
offset.z = fragment.center.z - scenery.center.z;
|
||||||
|
|
||||||
|
if ( viewable(&offset, fragment.bounding_radius * 2) ) {
|
||||||
|
xglCallList(fragment.display_list);
|
||||||
|
drawn++;
|
||||||
|
} else {
|
||||||
|
// printf("Culled a fragment %.2f %.2f %.2f %.2f\n",
|
||||||
|
// fragment.center.x, fragment.center.y,
|
||||||
|
// fragment.center.z, fragment.bounding_radius);
|
||||||
|
culled++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xglPopMatrix();
|
xglPopMatrix();
|
||||||
|
} else {
|
||||||
|
culled += t->fragment_list.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// v->vfc_ratio = (double)culled / (double)(drawn + culled);
|
v->vfc_ratio = (double)culled / (double)(drawn + culled);
|
||||||
v->vfc_ratio = 0.0;
|
|
||||||
// printf("drawn = %d culled = %d saved = %.2f\n", drawn, culled,
|
// printf("drawn = %d culled = %d saved = %.2f\n", drawn, culled,
|
||||||
// v->vfc_ratio);
|
// v->vfc_ratio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.13 1998/05/24 02:49:10 curt
|
||||||
|
// Implimented fragment level view frustum culling.
|
||||||
|
//
|
||||||
// Revision 1.12 1998/05/23 14:09:23 curt
|
// Revision 1.12 1998/05/23 14:09:23 curt
|
||||||
// Added tile.cxx and tile.hxx.
|
// Added tile.cxx and tile.hxx.
|
||||||
// Working on rewriting the tile management system so a tile is just a list
|
// Working on rewriting the tile management system so a tile is just a list
|
||||||
|
|
Loading…
Add table
Reference in a new issue