1
0
Fork 0

Playing around with texture coordinates.

This commit is contained in:
curt 1998-05-02 01:52:14 +00:00
parent 1f5aeb1d46
commit 5a4b56c58e
7 changed files with 95 additions and 120 deletions

View file

@ -1,6 +1,5 @@
/* -*- Mode: C++ -*- /*
* * obj.cxx -- routines to handle "sorta" WaveFront .obj format files.
* obj.c -- routines to handle WaveFront .obj format files.
* *
* Written by Curtis Olson, started October 1997. * Written by Curtis Olson, started October 1997.
* *
@ -44,8 +43,10 @@
#include <Main/options.hxx> #include <Main/options.hxx>
#include <Math/mat3.h> #include <Math/mat3.h>
#include <Math/fg_random.h> #include <Math/fg_random.h>
#include <Scenery/obj.hxx> #include <Math/polar3d.h>
#include <Scenery/scenery.hxx>
#include "obj.hxx"
#include "scenery.hxx"
#define MAXNODES 100000 #define MAXNODES 100000
@ -73,33 +74,29 @@ void calc_normal(double p1[3], double p2[3], double p3[3], double normal[3])
#define FG_TEX_CONSTANT 128.0 #define FG_TEX_CONSTANT 128.0
float calc_lon(double x, double y, double z) {
float tmp;
tmp = fmod(
(RAD_TO_DEG*atan2(y, x)) * FG_TEX_CONSTANT,
10.0);
// printf("lon = %.2f\n", (float)tmp); // Calculate texture coordinates for a given point.
return (float)tmp; fgPolarPoint3d calc_tex_coords(double *node, fgCartesianPoint3d *ref) {
} fgCartesianPoint3d cp;
fgPolarPoint3d pp;
cp.x = node[0] + ref->x;
cp.y = node[1] + ref->y;
cp.z = node[2] + ref->z;
float calc_lat(double x, double y, double z) { pp = fgCartToPolar3d(cp);
float tmp;
tmp = fmod( pp.lon = fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.lon, 15.0);
(90.0 - RAD_TO_DEG * pp.lat = fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.lat, 15.0);
atan2( sqrt(x*x + y*y), z )) * FG_TEX_CONSTANT,
10.0);
// printf("lat = %.2f\n", (float)tmp); return(pp);
return (float)tmp;
} }
/* Load a .obj file and generate the GL call list */ /* Load a .obj file and generate the GL call list */
GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) { GLint fgObjLoad(char *path, fgCartesianPoint3d *ref, double *radius) {
fgOPTIONS *o; fgOPTIONS *o;
fgPolarPoint3d pp;
char fgpath[256], line[256], winding_str[256]; char fgpath[256], line[256], winding_str[256];
double approx_normal[3], normal[3], scale; double approx_normal[3], normal[3], scale;
// double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin; // double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin;
@ -163,7 +160,8 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
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][2]); &nodes[ncount][0], &nodes[ncount][1],
&nodes[ncount][2]);
/* first time through set min's and max'es */ /* first time through set min's and max'es */
/* /*
@ -252,64 +250,44 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
// (averaged) normals // (averaged) normals
MAT3_SCALE_VEC(normal, normals[n1], scale); MAT3_SCALE_VEC(normal, normals[n1], scale);
xglNormal3dv(normal); xglNormal3dv(normal);
xglTexCoord2f(calc_lon(nodes[n1][0] + ref->x, pp = calc_tex_coords(nodes[n1], ref);
nodes[n1][1] + ref->y, xglTexCoord2f(pp.lon, pp.lat);
nodes[n1][2] + ref->z),
calc_lat(nodes[n1][0] + ref->x,
nodes[n1][1] + ref->y,
nodes[n1][2] + ref->z));
xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]); xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
MAT3_SCALE_VEC(normal, normals[n2], scale); MAT3_SCALE_VEC(normal, normals[n2], scale);
xglNormal3dv(normal); xglNormal3dv(normal);
xglTexCoord2f(calc_lon(nodes[n2][0] + ref->x, pp = calc_tex_coords(nodes[n2], ref);
nodes[n2][1] + ref->y, xglTexCoord2f(pp.lon, pp.lat);
nodes[n2][2] + ref->z),
calc_lat(nodes[n2][0] + ref->x,
nodes[n2][1] + ref->y,
nodes[n2][2] + ref->z));
xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]); xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]);
MAT3_SCALE_VEC(normal, normals[n3], scale); MAT3_SCALE_VEC(normal, normals[n3], scale);
xglNormal3dv(normal); xglNormal3dv(normal);
xglTexCoord2f(calc_lon(nodes[n3][0] + ref->x, pp = calc_tex_coords(nodes[n3], ref);
nodes[n3][1] + ref->y, xglTexCoord2f(pp.lon, pp.lat);
nodes[n3][2] + ref->z),
calc_lat(nodes[n3][0] + ref->x,
nodes[n3][1] + ref->y,
nodes[n3][2] + ref->z));
xglVertex3d(nodes[n3][0], nodes[n3][1], nodes[n3][2]); xglVertex3d(nodes[n3][0], nodes[n3][1], nodes[n3][2]);
} else { } else {
// Shading model is "GL_FLAT" so calculate per face // Shading model is "GL_FLAT" so calculate per face
// normals on the fly. // normals on the fly.
if ( odd ) { if ( odd ) {
calc_normal(nodes[n1], nodes[n2], nodes[n3], approx_normal); calc_normal(nodes[n1], nodes[n2],
nodes[n3], approx_normal);
} else { } else {
calc_normal(nodes[n2], nodes[n1], nodes[n3], approx_normal); calc_normal(nodes[n2], nodes[n1],
nodes[n3], approx_normal);
} }
MAT3_SCALE_VEC(normal, approx_normal, scale); MAT3_SCALE_VEC(normal, approx_normal, scale);
xglNormal3dv(normal); xglNormal3dv(normal);
xglTexCoord2f(calc_lon(nodes[n1][0] + ref->x, pp = calc_tex_coords(nodes[n1], ref);
nodes[n1][1] + ref->y, xglTexCoord2f(pp.lon, pp.lat);
nodes[n1][2] + ref->z),
calc_lat(nodes[n1][0] + ref->x,
nodes[n1][1] + ref->y,
nodes[n1][2] + ref->z));
xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]); xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
xglTexCoord2f(calc_lon(nodes[n2][0] + ref->x,
nodes[n2][1] + ref->y, pp = calc_tex_coords(nodes[n2], ref);
nodes[n2][2] + ref->z), xglTexCoord2f(pp.lon, pp.lat);
calc_lat(nodes[n2][0] + ref->x,
nodes[n2][1] + ref->y,
nodes[n2][2] + ref->z));
xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]); xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]);
xglTexCoord2f(calc_lon(nodes[n3][0] + ref->x,
nodes[n3][1] + ref->y, pp = calc_tex_coords(nodes[n3], ref);
nodes[n3][2] + ref->z), xglTexCoord2f(pp.lon, pp.lat);
calc_lat(nodes[n3][0] + ref->x,
nodes[n3][1] + ref->y,
nodes[n3][2] + ref->z));
xglVertex3d(nodes[n3][0], nodes[n3][1], nodes[n3][2]); xglVertex3d(nodes[n3][0], nodes[n3][1], nodes[n3][2]);
} }
@ -327,12 +305,8 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
MAT3_SCALE_VEC(normal, approx_normal, scale); MAT3_SCALE_VEC(normal, approx_normal, scale);
} }
xglNormal3dv(normal); xglNormal3dv(normal);
xglTexCoord2f(calc_lon(nodes[n4][0] + ref->x, pp = calc_tex_coords(nodes[n4], ref);
nodes[n4][1] + ref->y, xglTexCoord2f(pp.lon, pp.lat);
nodes[n4][2] + ref->z),
calc_lat(nodes[n4][0] + ref->x,
nodes[n4][1] + ref->y,
nodes[n4][2] + ref->z));
xglVertex3d(nodes[n4][0], nodes[n4][1], nodes[n4][2]); xglVertex3d(nodes[n4][0], nodes[n4][1], nodes[n4][2]);
odd = 1 - odd; odd = 1 - odd;
@ -355,30 +329,18 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
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]);
xglTexCoord2f(calc_lon(nodes[n1][0] + ref->x, pp = calc_tex_coords(nodes[n1], ref);
nodes[n1][1] + ref->y, xglTexCoord2f(pp.lon, pp.lat);
nodes[n1][2] + ref->z),
calc_lat(nodes[n1][0] + ref->x,
nodes[n1][1] + ref->y,
nodes[n1][2] + ref->z));
xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]); xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
xglNormal3d(normals[n2][0], normals[n2][1], normals[n2][2]); xglNormal3d(normals[n2][0], normals[n2][1], normals[n2][2]);
xglTexCoord2f(calc_lon(nodes[n2][0] + ref->x, pp = calc_tex_coords(nodes[n2], ref);
nodes[n2][1] + ref->y, xglTexCoord2f(pp.lon, pp.lat);
nodes[n2][2] + ref->z),
calc_lat(nodes[n2][0] + ref->x,
nodes[n2][1] + ref->y,
nodes[n2][2] + ref->z));
xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]); xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]);
xglNormal3d(normals[n3][0], normals[n3][1], normals[n3][2]); xglNormal3d(normals[n3][0], normals[n3][1], normals[n3][2]);
xglTexCoord2f(calc_lon(nodes[n3][0] + ref->x, pp = calc_tex_coords(nodes[n3], ref);
nodes[n3][1] + ref->y, xglTexCoord2f(pp.lon, pp.lat);
nodes[n3][2] + ref->z),
calc_lat(nodes[n3][0] + ref->x,
nodes[n3][1] + ref->y,
nodes[n3][2] + ref->z));
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 */
@ -406,12 +368,8 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
xglNormal3dv(normal); xglNormal3dv(normal);
} }
xglTexCoord2f(calc_lon(nodes[n1][0] + ref->x, pp = calc_tex_coords(nodes[n1], ref);
nodes[n1][1] + ref->y, xglTexCoord2f(pp.lon, pp.lat);
nodes[n1][2] + ref->z),
calc_lat(nodes[n1][0] + ref->x,
nodes[n1][1] + ref->y,
nodes[n1][2] + ref->z));
xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]); xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
odd = 1 - odd; odd = 1 - odd;
@ -438,12 +396,8 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
xglNormal3dv(normal); xglNormal3dv(normal);
} }
xglTexCoord2f(calc_lon(nodes[n2][0] + ref->x, pp = calc_tex_coords(nodes[n2], ref);
nodes[n2][1] + ref->y, xglTexCoord2f(pp.lon, pp.lat);
nodes[n2][2] + ref->z),
calc_lat(nodes[n2][0] + ref->x,
nodes[n2][1] + ref->y,
nodes[n2][2] + ref->z));
xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]); xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]);
odd = 1 -odd; odd = 1 -odd;
@ -494,9 +448,12 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
/* $Log$ /* $Log$
/* Revision 1.1 1998/04/30 12:35:28 curt /* Revision 1.2 1998/05/02 01:52:14 curt
/* Added a command line rendering option specify smooth/flat shading. /* Playing around with texture coordinates.
/* /*
* 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 * Revision 1.35 1998/04/28 21:43:26 curt
* Wrapped zlib calls up so we can conditionally comment out zlib support. * Wrapped zlib calls up so we can conditionally comment out zlib support.
* *

View file

@ -47,16 +47,19 @@
/* Load a .obj file and generate the GL call list */ /* Load a .obj file and generate the GL call list */
GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius); GLint fgObjLoad(char *path, fgCartesianPoint3d *ref, double *radius);
#endif /* _OBJ_HXX */ #endif /* _OBJ_HXX */
/* $Log$ /* $Log$
/* Revision 1.1 1998/04/30 12:35:29 curt /* Revision 1.2 1998/05/02 01:52:15 curt
/* Added a command line rendering option specify smooth/flat shading. /* Playing around with texture coordinates.
/* /*
* 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 * Revision 1.11 1998/04/25 22:06:31 curt
* Edited cvs log messages in source files ... bad bad bad! * Edited cvs log messages in source files ... bad bad bad!
* *

View file

@ -72,7 +72,7 @@ int fgSceneryInit( void ) {
path[0] = '\0'; path[0] = '\0';
strcat(path, g->root_dir); strcat(path, g->root_dir);
strcat(path, "/Textures/"); strcat(path, "/Textures/");
strcat(path, "forest.rgb"); strcat(path, "desert.rgb");
// Try uncompressed // Try uncompressed
if ( (texbuf = read_rgb_texture(path, &width, &height)) == NULL ) { if ( (texbuf = read_rgb_texture(path, &width, &height)) == NULL ) {
@ -123,9 +123,12 @@ void fgSceneryRender( void ) {
/* $Log$ /* $Log$
/* Revision 1.1 1998/04/30 12:35:30 curt /* Revision 1.2 1998/05/02 01:52:16 curt
/* Added a command line rendering option specify smooth/flat shading. /* Playing around with texture coordinates.
/* /*
* 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 * Revision 1.42 1998/04/28 21:43:27 curt
* Wrapped zlib calls up so we can conditionally comment out zlib support. * Wrapped zlib calls up so we can conditionally comment out zlib support.
* *

View file

@ -42,10 +42,10 @@ struct fgSCENERY {
int terrain_skip; int terrain_skip;
/* center of current scenery chunk */ /* center of current scenery chunk */
struct fgCartesianPoint center; fgCartesianPoint3d center;
/* next center of current scenery chunk */ /* next center of current scenery chunk */
struct fgCartesianPoint next_center; fgCartesianPoint3d next_center;
/* angle of sun relative to current local horizontal */ /* angle of sun relative to current local horizontal */
double sun_angle; double sun_angle;
@ -71,9 +71,12 @@ void fgSceneryRender( void );
/* $Log$ /* $Log$
/* Revision 1.1 1998/04/30 12:35:31 curt /* Revision 1.2 1998/05/02 01:52:16 curt
/* Added a command line rendering option specify smooth/flat shading. /* Playing around with texture coordinates.
/* /*
* 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 * Revision 1.21 1998/04/25 22:06:31 curt
* Edited cvs log messages in source files ... bad bad bad! * Edited cvs log messages in source files ... bad bad bad!
* *

View file

@ -132,7 +132,7 @@ void fgTileCacheEntryFree( int index ) {
/* Return info for a tile cache entry */ /* Return info for a tile cache entry */
void fgTileCacheEntryInfo( int index, GLint *display_list, void fgTileCacheEntryInfo( int index, GLint *display_list,
struct fgCartesianPoint *local_ref ) { fgCartesianPoint3d *local_ref ) {
*display_list = tile_cache[index].display_list; *display_list = tile_cache[index].display_list;
/* fgPrintf(FG_TERRAIN, FG_DEBUG, "Display list = %d\n", *display_list); */ /* fgPrintf(FG_TERRAIN, FG_DEBUG, "Display list = %d\n", *display_list); */
@ -200,9 +200,12 @@ int fgTileCacheNextAvail( void ) {
/* $Log$ /* $Log$
/* Revision 1.5 1998/04/30 12:35:31 curt /* Revision 1.6 1998/05/02 01:52:17 curt
/* Added a command line rendering option specify smooth/flat shading. /* Playing around with texture coordinates.
/* /*
* 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 * Revision 1.4 1998/04/28 01:21:43 curt
* Tweaked texture parameter calculations to keep the number smaller. This * Tweaked texture parameter calculations to keep the number smaller. This
* avoids the "swimming" problem. * avoids the "swimming" problem.

View file

@ -57,7 +57,7 @@
struct fgTILE { struct fgTILE {
struct fgBUCKET tile_bucket; struct fgBUCKET tile_bucket;
GLint display_list; GLint display_list;
struct fgCartesianPoint local_ref; fgCartesianPoint3d local_ref;
double bounding_radius; double bounding_radius;
int used; int used;
int priority; int priority;
@ -81,16 +81,19 @@ void fgTileCacheEntryFillIn( int index, struct fgBUCKET *p );
/* Return info for a tile cache entry */ /* Return info for a tile cache entry */
void fgTileCacheEntryInfo( int index, GLint *display_list, void fgTileCacheEntryInfo( int index, GLint *display_list,
struct fgCartesianPoint *local_ref ); fgCartesianPoint3d *local_ref );
#endif /* _TILECACHE_HXX */ #endif /* _TILECACHE_HXX */
/* $Log$ /* $Log$
/* Revision 1.4 1998/04/30 12:35:31 curt /* Revision 1.5 1998/05/02 01:52:17 curt
/* Added a command line rendering option specify smooth/flat shading. /* Playing around with texture coordinates.
/* /*
* 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 * Revision 1.3 1998/04/25 22:06:32 curt
* Edited cvs log messages in source files ... bad bad bad! * Edited cvs log messages in source files ... bad bad bad!
* *

View file

@ -185,7 +185,7 @@ int fgTileMgrUpdate( void ) {
void fgTileMgrRender( void ) { void fgTileMgrRender( void ) {
fgFLIGHT *f; fgFLIGHT *f;
struct fgBUCKET p; struct fgBUCKET p;
struct fgCartesianPoint local_ref; fgCartesianPoint3d local_ref;
GLint display_list; GLint display_list;
int i; int i;
int index; int index;
@ -221,9 +221,12 @@ void fgTileMgrRender( void ) {
/* $Log$ /* $Log$
/* Revision 1.5 1998/04/30 12:35:32 curt /* Revision 1.6 1998/05/02 01:52:18 curt
/* Added a command line rendering option specify smooth/flat shading. /* Playing around with texture coordinates.
/* /*
* 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 * Revision 1.4 1998/04/27 03:30:14 curt
* Minor transformation adjustments to try to keep scenery tiles closer to * 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 * (0, 0, 0) GLfloats run out of precision at the distances we need to model