Added a command line rendering option specify smooth/flat shading.
This commit is contained in:
parent
d87408c767
commit
401b414feb
9 changed files with 95 additions and 71 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -41,10 +41,11 @@
|
|||
#include <Debug/fg_debug.h>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Include/fg_zlib.h>
|
||||
#include <Main/options.hxx>
|
||||
#include <Math/mat3.h>
|
||||
#include <Math/fg_random.h>
|
||||
#include <Scenery/obj.h>
|
||||
#include <Scenery/scenery.h>
|
||||
#include <Scenery/obj.hxx>
|
||||
#include <Scenery/scenery.hxx>
|
||||
|
||||
|
||||
#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.
|
|
@ -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 <Include/fg_types.h>
|
||||
|
||||
|
||||
#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 <config.h>" in "#ifdef HAVE_CONFIG_H"
|
||||
* Tweaked the scenery file extentions to be "file.obj" (uncompressed)
|
|
@ -41,8 +41,8 @@
|
|||
|
||||
#include <Debug/fg_debug.h>
|
||||
#include <Include/general.h>
|
||||
#include <Scenery/obj.h>
|
||||
#include <Scenery/scenery.h>
|
||||
#include <Scenery/obj.hxx>
|
||||
#include <Scenery/scenery.hxx>
|
||||
#include <Scenery/texload.h>
|
||||
|
||||
|
||||
|
@ -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 <config.h>" in "#ifdef HAVE_CONFIG_H"
|
||||
* Tweaked the scenery file extentions to be "file.obj" (uncompressed)
|
|
@ -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,18 +24,18 @@
|
|||
**************************************************************************/
|
||||
|
||||
|
||||
#ifndef _SCENERY_H
|
||||
#define _SCENERY_H
|
||||
#ifndef _SCENERY_HXX
|
||||
#define _SCENERY_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
#include <Include/fg_types.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Define a structure containing global scenery parameters */
|
||||
struct fgSCENERY {
|
||||
/* number of terrain data points to skip */
|
||||
|
@ -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.
|
||||
*
|
|
@ -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 <Debug/fg_debug.h>
|
||||
#include <Main/views.hxx>
|
||||
|
||||
#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!
|
||||
*
|
||||
|
|
|
@ -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 <config.h>" in "#ifdef HAVE_CONFIG_H"
|
||||
* Tweaked the scenery file extentions to be "file.obj" (uncompressed)
|
||||
|
|
|
@ -36,8 +36,8 @@
|
|||
#include <GL/glut.h>
|
||||
#include <XGL/xgl.h>
|
||||
|
||||
#include <Scenery/scenery.h>
|
||||
#include <Scenery/obj.h>
|
||||
#include <Scenery/obj.hxx>
|
||||
#include <Scenery/scenery.hxx>
|
||||
#include <Scenery/tilecache.hxx>
|
||||
|
||||
#include <Aircraft/aircraft.h>
|
||||
|
@ -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!
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue