From 401b414feb523b9747d97212013169bbe1ea4a23 Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 30 Apr 1998 12:35:26 +0000 Subject: [PATCH] Added a command line rendering option specify smooth/flat shading. --- Scenery/Makefile.am | 4 ++-- Scenery/Makefile.in | 4 ++-- Scenery/{obj.c => obj.cxx} | 36 +++++++++++++++++++++--------- Scenery/{obj.h => obj.hxx} | 30 ++++++++++++------------- Scenery/{scenery.c => scenery.cxx} | 13 ++++++----- Scenery/{scenery.h => scenery.hxx} | 28 +++++++++++------------ Scenery/tilecache.cxx | 15 ++++++++----- Scenery/tilecache.hxx | 15 ++++++++----- Scenery/tilemgr.cxx | 19 +++++++++------- 9 files changed, 94 insertions(+), 70 deletions(-) rename Scenery/{obj.c => obj.cxx} (95%) rename Scenery/{obj.h => obj.hxx} (85%) rename Scenery/{scenery.c => scenery.cxx} (96%) rename Scenery/{scenery.h => scenery.hxx} (89%) diff --git a/Scenery/Makefile.am b/Scenery/Makefile.am index 575d02ab7..22633ec7d 100644 --- a/Scenery/Makefile.am +++ b/Scenery/Makefile.am @@ -3,8 +3,8 @@ libdir = ${exec_prefix}/lib lib_LTLIBRARIES = libScenery.la libScenery_la_SOURCES = \ - obj.c obj.h \ - scenery.c scenery.h \ + obj.cxx obj.hxx \ + scenery.cxx scenery.hxx \ texload.c texload.h \ tilecache.cxx tilecache.hxx \ tilemgr.cxx tilemgr.hxx diff --git a/Scenery/Makefile.in b/Scenery/Makefile.in index f6ced03c8..c3577ce94 100644 --- a/Scenery/Makefile.in +++ b/Scenery/Makefile.in @@ -75,8 +75,8 @@ libdir = ${exec_prefix}/lib lib_LTLIBRARIES = libScenery.la libScenery_la_SOURCES = \ - obj.c obj.h \ - scenery.c scenery.h \ + obj.cxx obj.hxx \ + scenery.cxx scenery.hxx \ texload.c texload.h \ tilecache.cxx tilecache.hxx \ tilemgr.cxx tilemgr.hxx diff --git a/Scenery/obj.c b/Scenery/obj.cxx similarity index 95% rename from Scenery/obj.c rename to Scenery/obj.cxx index e8f18370d..1874603c6 100644 --- a/Scenery/obj.c +++ b/Scenery/obj.cxx @@ -41,10 +41,11 @@ #include #include #include +#include
#include #include -#include -#include +#include +#include #define MAXNODES 100000 @@ -98,17 +99,19 @@ float calc_lat(double x, double y, double z) { /* Load a .obj file and generate the GL call list */ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) { + fgOPTIONS *o; char fgpath[256], line[256], winding_str[256]; double approx_normal[3], normal[3], scale; // double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin; - GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 }; + // GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 }; GLint tile; fgFile f; int first, ncount, vncount, n1, n2, n3, n4; - static int use_per_vertex_norms = 1; int winding; int last1, last2, odd; + o = ¤t_options; + // First try "path.obz" (compressed format) strcpy(fgpath, path); strcat(fgpath, ".obz"); @@ -244,7 +247,9 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) { scale = 1.0; } - if ( use_per_vertex_norms ) { + if ( o->shading ) { + // Shading model is "GL_SMOOTH" so use precalculated + // (averaged) normals MAT3_SCALE_VEC(normal, normals[n1], scale); xglNormal3dv(normal); xglTexCoord2f(calc_lon(nodes[n1][0] + ref->x, @@ -275,6 +280,8 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) { nodes[n3][2] + ref->z)); xglVertex3d(nodes[n3][0], nodes[n3][1], nodes[n3][2]); } else { + // Shading model is "GL_FLAT" so calculate per face + // normals on the fly. if ( odd ) { calc_normal(nodes[n1], nodes[n2], nodes[n3], approx_normal); } else { @@ -311,9 +318,11 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) { last2 = n3; if ( n4 > 0 ) { - if ( use_per_vertex_norms ) { + if ( o->shading ) { + // Shading model is "GL_SMOOTH" MAT3_SCALE_VEC(normal, normals[n4], scale); } else { + // Shading model is "GL_FLAT" calc_normal(nodes[n3], nodes[n2], nodes[n4], approx_normal); MAT3_SCALE_VEC(normal, approx_normal, scale); } @@ -380,10 +389,12 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) { sscanf(line, "q %d %d\n", &n1, &n2); /* fgPrintf( FG_TERRAIN, FG_DEBUG, "read %d %d\n", n1, n2); */ - if ( use_per_vertex_norms ) { + if ( o->shading ) { + // Shading model is "GL_SMOOTH" MAT3_SCALE_VEC(normal, normals[n1], scale); xglNormal3dv(normal); } else { + // Shading model is "GL_FLAT" if ( odd ) { calc_normal(nodes[last1], nodes[last2], nodes[n1], approx_normal); @@ -410,10 +421,12 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) { if ( n2 > 0 ) { /* fgPrintf( FG_TERRAIN, FG_DEBUG, " (cont)\n"); */ - if ( use_per_vertex_norms ) { + if ( o->shading ) { + // Shading model is "GL_SMOOTH" MAT3_SCALE_VEC(normal, normals[n2], scale); xglNormal3dv(normal); } else { + // Shading model is "GL_FLAT" if ( odd ) { calc_normal(nodes[last1], nodes[last2], nodes[n2], approx_normal); @@ -481,9 +494,12 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) { /* $Log$ -/* 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.35 1998/04/28 21:43:26 curt + * Wrapped zlib calls up so we can conditionally comment out zlib support. + * * Revision 1.34 1998/04/28 01:21:42 curt * Tweaked texture parameter calculations to keep the number smaller. This * avoids the "swimming" problem. diff --git a/Scenery/obj.h b/Scenery/obj.hxx similarity index 85% rename from Scenery/obj.h rename to Scenery/obj.hxx index 47d42f11f..1539cfd6f 100644 --- a/Scenery/obj.h +++ b/Scenery/obj.hxx @@ -1,5 +1,5 @@ /************************************************************************** - * obj.h -- 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. * @@ -24,8 +24,13 @@ **************************************************************************/ -#ifndef _OBJ_H -#define _OBJ_H +#ifndef _OBJ_HXX +#define _OBJ_HXX + + +#ifndef __cplusplus +# error This library requires C++ +#endif #ifdef HAVE_CONFIG_H @@ -41,27 +46,20 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - - /* Load a .obj file and generate the GL call list */ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius); -#ifdef __cplusplus -} -#endif - - -#endif /* _OBJ_H */ +#endif /* _OBJ_HXX */ /* $Log$ -/* 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.11 1998/04/25 22:06:31 curt + * Edited cvs log messages in source files ... bad bad bad! + * * Revision 1.10 1998/04/24 00:51:07 curt * Wrapped "#include " in "#ifdef HAVE_CONFIG_H" * Tweaked the scenery file extentions to be "file.obj" (uncompressed) diff --git a/Scenery/scenery.c b/Scenery/scenery.cxx similarity index 96% rename from Scenery/scenery.c rename to Scenery/scenery.cxx index f5ce0068c..e58d9921b 100644 --- a/Scenery/scenery.c +++ b/Scenery/scenery.cxx @@ -41,8 +41,8 @@ #include #include -#include -#include +#include +#include #include @@ -72,7 +72,7 @@ int fgSceneryInit( void ) { path[0] = '\0'; strcat(path, g->root_dir); strcat(path, "/Textures/"); - strcat(path, "desert.rgb"); + strcat(path, "forest.rgb"); // Try uncompressed if ( (texbuf = read_rgb_texture(path, &width, &height)) == NULL ) { @@ -123,9 +123,12 @@ void fgSceneryRender( void ) { /* $Log$ -/* Revision 1.42 1998/04/28 21:43:27 curt -/* Wrapped zlib calls up so we can conditionally comment out zlib support. +/* Revision 1.1 1998/04/30 12:35:30 curt +/* Added a command line rendering option specify smooth/flat shading. /* + * Revision 1.42 1998/04/28 21:43:27 curt + * Wrapped zlib calls up so we can conditionally comment out zlib support. + * * Revision 1.41 1998/04/24 00:51:08 curt * Wrapped "#include " in "#ifdef HAVE_CONFIG_H" * Tweaked the scenery file extentions to be "file.obj" (uncompressed) diff --git a/Scenery/scenery.h b/Scenery/scenery.hxx similarity index 89% rename from Scenery/scenery.h rename to Scenery/scenery.hxx index 74250df4b..606912ec6 100644 --- a/Scenery/scenery.h +++ b/Scenery/scenery.hxx @@ -1,5 +1,5 @@ /************************************************************************** - * scenery.h -- data structures and routines for managing scenery. + * scenery.hxx -- data structures and routines for managing scenery. * * Written by Curtis Olson, started May 1997. * @@ -24,16 +24,16 @@ **************************************************************************/ -#ifndef _SCENERY_H -#define _SCENERY_H +#ifndef _SCENERY_HXX +#define _SCENERY_HXX -#include +#ifndef __cplusplus +# error This library requires C++ +#endif -#ifdef __cplusplus -extern "C" { -#endif +#include /* Define a structure containing global scenery parameters */ @@ -67,18 +67,16 @@ void fgSceneryUpdate(double lon, double lat, double elev); void fgSceneryRender( void ); -#ifdef __cplusplus -} -#endif - - -#endif /* _SCENERY_H */ +#endif /* _SCENERY_HXX */ /* $Log$ -/* Revision 1.21 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:31 curt +/* Added a command line rendering option specify smooth/flat shading. /* + * Revision 1.21 1998/04/25 22:06:31 curt + * Edited cvs log messages in source files ... bad bad bad! + * * Revision 1.20 1998/04/22 13:22:45 curt * C++ - ifing the code a bit. * diff --git a/Scenery/tilecache.cxx b/Scenery/tilecache.cxx index d621bd4f3..08303ab94 100644 --- a/Scenery/tilecache.cxx +++ b/Scenery/tilecache.cxx @@ -1,5 +1,5 @@ /************************************************************************** - * tilecache.c -- routines to handle scenery tile caching + * tilecache.cxx -- routines to handle scenery tile caching * * Written by Curtis Olson, started January 1998. * @@ -41,7 +41,7 @@ #include #include
-#include "obj.h" +#include "obj.hxx" #include "tilecache.hxx" @@ -200,11 +200,14 @@ int fgTileCacheNextAvail( void ) { /* $Log$ -/* Revision 1.4 1998/04/28 01:21:43 curt -/* Tweaked texture parameter calculations to keep the number smaller. This -/* avoids the "swimming" problem. -/* Type-ified fgTIME and fgVIEW. +/* Revision 1.5 1998/04/30 12:35:31 curt +/* Added a command line rendering option specify smooth/flat shading. /* + * Revision 1.4 1998/04/28 01:21:43 curt + * Tweaked texture parameter calculations to keep the number smaller. This + * avoids the "swimming" problem. + * Type-ified fgTIME and fgVIEW. + * * Revision 1.3 1998/04/25 22:06:32 curt * Edited cvs log messages in source files ... bad bad bad! * diff --git a/Scenery/tilecache.hxx b/Scenery/tilecache.hxx index e6aecccaa..705c2e6a2 100644 --- a/Scenery/tilecache.hxx +++ b/Scenery/tilecache.hxx @@ -1,5 +1,5 @@ /************************************************************************** - * tilecache.h -- routines to handle scenery tile caching + * tilecache.hxx -- routines to handle scenery tile caching * * Written by Curtis Olson, started January 1998. * @@ -24,8 +24,8 @@ **************************************************************************/ -#ifndef _TILECACHE_H -#define _TILECACHE_H +#ifndef _TILECACHE_HXX +#define _TILECACHE_HXX #ifndef __cplusplus @@ -84,13 +84,16 @@ void fgTileCacheEntryInfo( int index, GLint *display_list, struct fgCartesianPoint *local_ref ); -#endif /* _TILECACHE_H */ +#endif /* _TILECACHE_HXX */ /* $Log$ -/* Revision 1.3 1998/04/25 22:06:32 curt -/* Edited cvs log messages in source files ... bad bad bad! +/* Revision 1.4 1998/04/30 12:35:31 curt +/* Added a command line rendering option specify smooth/flat shading. /* + * Revision 1.3 1998/04/25 22:06:32 curt + * Edited cvs log messages in source files ... bad bad bad! + * * Revision 1.2 1998/04/24 00:51:08 curt * Wrapped "#include " in "#ifdef HAVE_CONFIG_H" * Tweaked the scenery file extentions to be "file.obj" (uncompressed) diff --git a/Scenery/tilemgr.cxx b/Scenery/tilemgr.cxx index daeeed7a4..0fd38eaab 100644 --- a/Scenery/tilemgr.cxx +++ b/Scenery/tilemgr.cxx @@ -36,8 +36,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -221,13 +221,16 @@ void fgTileMgrRender( void ) { /* $Log$ -/* Revision 1.4 1998/04/27 03:30:14 curt -/* 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 -/* 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 -/* precision problems. +/* Revision 1.5 1998/04/30 12:35:32 curt +/* Added a command line rendering option specify smooth/flat shading. /* + * Revision 1.4 1998/04/27 03:30:14 curt + * 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 + * 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 + * precision problems. + * * Revision 1.3 1998/04/25 22:06:32 curt * Edited cvs log messages in source files ... bad bad bad! * -- 2.39.2