From: curt Date: Tue, 13 Jan 1998 00:23:08 +0000 (+0000) Subject: Initial changes to support loading and management of scenery tiles. Note, X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0f64d76c81956ca2b7537f23f8d7258ae1b34e79;p=flightgear.git Initial changes to support loading and management of scenery tiles. Note, there's still a fair amount of work left to be done. --- diff --git a/Main/GLUTmain.c b/Main/GLUTmain.c index af7d45812..8152da3ae 100644 --- a/Main/GLUTmain.c +++ b/Main/GLUTmain.c @@ -283,7 +283,8 @@ static void fgRenderFrame( void ) { /* set lighting parameters */ xglLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_ambient ); xglLightfv(GL_LIGHT0, GL_DIFFUSE, l->scene_diffuse ); - fgSceneryRender(); + fgTileMgrRender(); + /* fgSceneryRender(); */ /* display HUD */ if( show_hud ) { @@ -516,7 +517,7 @@ static void fgMainLoop( void ) { /* fgAircraftOutputCurrent(a); */ /* see if we need to load any new scenery tiles */ - fgTileMgrUpdate(); + /* fgTileMgrUpdate(); */ /* Process/manage pending events */ fgEventProcess(); @@ -632,9 +633,13 @@ int main( int argc, char *argv[] ) { /* $Log$ -/* Revision 1.46 1998/01/08 02:22:06 curt -/* Beginning to integrate Tile management subsystem. +/* Revision 1.47 1998/01/13 00:23:08 curt +/* 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.46 1998/01/08 02:22:06 curt + * Beginning to integrate Tile management subsystem. + * * Revision 1.45 1998/01/07 03:18:55 curt * Moved astronomical stuff from .../Src/Scenery to .../Src/Astro/ * diff --git a/Main/fg_init.c b/Main/fg_init.c index 47d76bb8a..c6ca50e40 100644 --- a/Main/fg_init.c +++ b/Main/fg_init.c @@ -122,6 +122,12 @@ void fgInitSubsystems( void ) { /* FG_Latitude = ( 119548.21 / 3600.0 ) * DEG_TO_RAD; */ /* FG_Altitude = 0.0 + 3.758099; */ + /* Initial Posisition near where I used to live in Globe, AZ */ + /* FG_Longitude = ( -398757.6 / 3600.0 ) * DEG_TO_RAD; */ + /* FG_Latitude = ( 120160.0 / 3600.0 ) * DEG_TO_RAD; */ + /* FG_Runway_altitude = 5000.0; */ + /* FG_Altitude = FG_Runway_altitude + 3.758099; */ + /* Initial Position: 10125 Jewell St. NE */ /* FG_Longitude = ( -93.15 ) * DEG_TO_RAD; */ /* FG_Latitude = ( 45.15 ) * DEG_TO_RAD; */ @@ -130,6 +136,7 @@ void fgInitSubsystems( void ) { /* A random test position */ /* FG_Longitude = ( 88128.00 / 3600.0 ) * DEG_TO_RAD; */ /* FG_Latitude = ( 93312.00 / 3600.0 ) * DEG_TO_RAD; */ + FG_Runway_altitude = 4000.0; FG_Altitude = FG_Runway_altitude + 3.758099; @@ -225,11 +232,12 @@ void fgInitSubsystems( void ) { /* Initialize the Scenery Management subsystem */ fgTileMgrInit(); - fgSceneryInit(); + /* fgSceneryInit(); */ /* Tell the Scenery Management system where we are so it can load * the correct scenery data */ - fgSceneryUpdate(FG_Latitude, FG_Longitude, FG_Altitude); + fgTileMgrUpdate(); + /* fgSceneryUpdate(FG_Latitude, FG_Longitude, FG_Altitude); */ /* I'm just sticking this here for now, it should probably move * eventually */ @@ -269,9 +277,13 @@ void fgInitSubsystems( void ) { /* $Log$ -/* Revision 1.29 1998/01/08 02:22:08 curt -/* Beginning to integrate Tile management subsystem. +/* Revision 1.30 1998/01/13 00:23:09 curt +/* 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.29 1998/01/08 02:22:08 curt + * Beginning to integrate Tile management subsystem. + * * Revision 1.28 1998/01/07 03:18:58 curt * Moved astronomical stuff from .../Src/Scenery to .../Src/Astro/ * diff --git a/Main/views.c b/Main/views.c index 40e428576..9c1d02af4 100644 --- a/Main/views.c +++ b/Main/views.c @@ -69,8 +69,8 @@ void fgViewUpdate(struct fgFLIGHT *f, struct fgVIEW *v, struct fgLIGHT *l) { v->view_pos.y -= scenery.center.y; v->view_pos.z -= scenery.center.z; - /* printf("View pos = %.4f, %.4f, %.4f\n", - v->view_pos.x, v->view_pos.y, v->view_pos.z); */ + printf("View pos = %.4f, %.4f, %.4f\n", + v->view_pos.x, v->view_pos.y, v->view_pos.z); /* make a vector to the current view position */ MAT3_SET_VEC(v0, v->view_pos.x, v->view_pos.y, v->view_pos.z); @@ -182,9 +182,13 @@ void fgViewUpdate(struct fgFLIGHT *f, struct fgVIEW *v, struct fgLIGHT *l) { /* $Log$ -/* Revision 1.8 1997/12/30 22:22:33 curt -/* Further integration of event manager. +/* Revision 1.9 1998/01/13 00:23:09 curt +/* 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.8 1997/12/30 22:22:33 curt + * Further integration of event manager. + * * Revision 1.7 1997/12/30 20:47:45 curt * Integrated new event manager with subsystem initializations. * diff --git a/Scenery/obj.c b/Scenery/obj.c index 7c16dbcfe..b94b50b52 100644 --- a/Scenery/obj.c +++ b/Scenery/obj.c @@ -63,10 +63,9 @@ void calc_normal(float p1[3], float p2[3], float p3[3], double normal[3]) /* Load a .obj file and generate the GL call list */ -GLint fgObjLoad(char *path) { +GLint fgObjLoad(char *path, struct fgCartesianPoint *ref) { char line[256], winding_str[256]; double v1[3], v2[3], approx_normal[3], normal[3], dot_prod, scale, temp; - struct fgCartesianPoint ref; GLint area; FILE *f; int first, ncount, vncount, n1, n2, n3, n4; @@ -76,7 +75,8 @@ GLint fgObjLoad(char *path) { if ( (f = fopen(path, "r")) == NULL ) { printf("Cannot open file: %s\n", path); - exit(-1); + /* exit(-1); */ + return(0); } area = xglGenLists(1); @@ -99,10 +99,10 @@ GLint fgObjLoad(char *path) { &nodes[ncount][0], &nodes[ncount][1], &nodes[ncount][2]); if ( ncount == 1 ) { /* first node becomes the reference point */ - ref.x = nodes[ncount][0]; - ref.y = nodes[ncount][1]; - ref.z = nodes[ncount][2]; - scenery.center = ref; + ref->x = nodes[ncount][0]; + ref->y = nodes[ncount][1]; + ref->z = nodes[ncount][2]; + /* scenery.center = ref; */ } ncount++; } else { @@ -166,18 +166,18 @@ GLint fgObjLoad(char *path) { if ( use_vertex_norms ) { MAT3_SCALE_VEC(normal, normals[n1], scale); xglNormal3dv(normal); - xglVertex3d(nodes[n1][0] - ref.x, nodes[n1][1] - ref.y, - nodes[n1][2] - ref.z); + xglVertex3d(nodes[n1][0] - ref->x, nodes[n1][1] - ref->y, + nodes[n1][2] - ref->z); MAT3_SCALE_VEC(normal, normals[n2], scale); xglNormal3dv(normal); - xglVertex3d(nodes[n2][0] - ref.x, nodes[n2][1] - ref.y, - nodes[n2][2] - ref.z); + xglVertex3d(nodes[n2][0] - ref->x, nodes[n2][1] - ref->y, + nodes[n2][2] - ref->z); MAT3_SCALE_VEC(normal, normals[n3], scale); xglNormal3dv(normal); - xglVertex3d(nodes[n3][0] - ref.x, nodes[n3][1] - ref.y, - nodes[n3][2] - ref.z); + xglVertex3d(nodes[n3][0] - ref->x, nodes[n3][1] - ref->y, + nodes[n3][2] - ref->z); } else { if ( odd ) { calc_normal(nodes[n1], nodes[n2], nodes[n3], approx_normal); @@ -187,12 +187,12 @@ GLint fgObjLoad(char *path) { MAT3_SCALE_VEC(normal, approx_normal, scale); xglNormal3dv(normal); - xglVertex3d(nodes[n1][0] - ref.x, nodes[n1][1] - ref.y, - nodes[n1][2] - ref.z); - xglVertex3d(nodes[n2][0] - ref.x, nodes[n2][1] - ref.y, - nodes[n2][2] - ref.z); - xglVertex3d(nodes[n3][0] - ref.x, nodes[n3][1] - ref.y, - nodes[n3][2] - ref.z); + xglVertex3d(nodes[n1][0] - ref->x, nodes[n1][1] - ref->y, + nodes[n1][2] - ref->z); + xglVertex3d(nodes[n2][0] - ref->x, nodes[n2][1] - ref->y, + nodes[n2][2] - ref->z); + xglVertex3d(nodes[n3][0] - ref->x, nodes[n3][1] - ref->y, + nodes[n3][2] - ref->z); } odd = 1 - odd; @@ -207,8 +207,8 @@ GLint fgObjLoad(char *path) { MAT3_SCALE_VEC(normal, approx_normal, scale); } xglNormal3dv(normal); - xglVertex3d(nodes[n4][0] - ref.x, nodes[n4][1] - ref.y, - nodes[n4][2] - ref.z); + xglVertex3d(nodes[n4][0] - ref->x, nodes[n4][1] - ref->y, + nodes[n4][2] - ref->z); odd = 1 - odd; last1 = n3; @@ -230,16 +230,16 @@ GLint fgObjLoad(char *path) { sscanf(line, "f %d %d %d\n", &n1, &n2, &n3); xglNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]); - xglVertex3d(nodes[n1][0] - ref.x, nodes[n1][1] - ref.y, - nodes[n1][2] - ref.z); + xglVertex3d(nodes[n1][0] - ref->x, nodes[n1][1] - ref->y, + nodes[n1][2] - ref->z); xglNormal3d(normals[n2][0], normals[n2][1], normals[n2][2]); - xglVertex3d(nodes[n2][0] - ref.x, nodes[n2][1] - ref.y, - nodes[n2][2] - ref.z); + xglVertex3d(nodes[n2][0] - ref->x, nodes[n2][1] - ref->y, + nodes[n2][2] - ref->z); xglNormal3d(normals[n3][0], normals[n3][1], normals[n3][2]); - xglVertex3d(nodes[n3][0] - ref.x, nodes[n3][1] - ref.y, - nodes[n3][2] - ref.z); + xglVertex3d(nodes[n3][0] - ref->x, nodes[n3][1] - ref->y, + nodes[n3][2] - ref->z); } else if ( line[0] == 'q' ) { /* continue a triangle strip */ n1 = n2 = 0; @@ -263,8 +263,8 @@ GLint fgObjLoad(char *path) { xglNormal3dv(normal); } - xglVertex3d(nodes[n1][0] - ref.x, nodes[n1][1] - ref.y, - nodes[n1][2] - ref.z); + xglVertex3d(nodes[n1][0] - ref->x, nodes[n1][1] - ref->y, + nodes[n1][2] - ref->z); odd = 1 - odd; last1 = last2; @@ -288,8 +288,8 @@ GLint fgObjLoad(char *path) { xglNormal3dv(normal); } - xglVertex3d(nodes[n2][0] - ref.x, nodes[n2][1] - ref.y, - nodes[n2][2] - ref.z); + xglVertex3d(nodes[n2][0] - ref->x, nodes[n2][1] - ref->y, + nodes[n2][2] - ref->z); odd = 1 -odd; last1 = last2; @@ -307,12 +307,12 @@ GLint fgObjLoad(char *path) { xglBegin(GL_LINES); xglColor3f(0.0, 0.0, 0.0); for ( i = 0; i < ncount; i++ ) { - xglVertex3d(nodes[i][0] - ref.x, - nodes[i][1] - ref.y, - nodes[i][2] - ref.z); - xglVertex3d(nodes[i][0] - ref.x + 500*normals[i][0], - nodes[i][1] - ref.y + 500*normals[i][1], - nodes[i][2] - ref.z + 500*normals[i][2]); + xglVertex3d(nodes[i][0] - ref->x, + nodes[i][1] - ref->y, + nodes[i][2] - ref->z); + xglVertex3d(nodes[i][0] - ref->x + 500*normals[i][0], + nodes[i][1] - ref->y + 500*normals[i][1], + nodes[i][2] - ref->z + 500*normals[i][2]); } xglEnd(); */ @@ -328,10 +328,14 @@ GLint fgObjLoad(char *path) { /* $Log$ -/* Revision 1.16 1997/12/30 23:09:40 curt -/* Worked on winding problem without luck, so back to calling glFrontFace() -/* 3 times for each scenery area. +/* Revision 1.17 1998/01/13 00:23:10 curt +/* 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.16 1997/12/30 23:09:40 curt + * Worked on winding problem without luck, so back to calling glFrontFace() + * 3 times for each scenery area. + * * Revision 1.15 1997/12/30 20:47:51 curt * Integrated new event manager with subsystem initializations. * diff --git a/Scenery/obj.h b/Scenery/obj.h index af8f4099d..3fd6be4ca 100644 --- a/Scenery/obj.h +++ b/Scenery/obj.h @@ -34,16 +34,22 @@ #include +#include "../Include/types.h" + /* Load a .obj file and generate the GL call list */ -GLint fgObjLoad(char *file); +GLint fgObjLoad(char *file, struct fgCartesianPoint *ref); #endif /* OBJ_H */ /* $Log$ -/* Revision 1.1 1997/10/28 21:14:55 curt -/* Initial revision. +/* Revision 1.2 1998/01/13 00:23:10 curt +/* 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. + * */ diff --git a/Scenery/scenery.c b/Scenery/scenery.c index 5b3801ea5..9aee8c092 100644 --- a/Scenery/scenery.c +++ b/Scenery/scenery.c @@ -76,7 +76,7 @@ void fgSceneryUpdate(double lon, double lat, double elev) { printf(" Loading Scenery: %s\n", path); - area_terrain = fgObjLoad(path); + area_terrain = fgObjLoad(path, &scenery.center); } @@ -100,9 +100,13 @@ void fgSceneryRender() { /* $Log$ -/* Revision 1.30 1998/01/07 03:22:29 curt -/* Moved astro stuff to .../Src/Astro/ +/* Revision 1.31 1998/01/13 00:23:11 curt +/* 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.30 1998/01/07 03:22:29 curt + * Moved astro stuff to .../Src/Astro/ + * * Revision 1.29 1997/12/30 20:47:52 curt * Integrated new event manager with subsystem initializations. * diff --git a/Scenery/tilemgr.c b/Scenery/tilemgr.c index ab5ce1fb9..e867da8b1 100644 --- a/Scenery/tilemgr.c +++ b/Scenery/tilemgr.c @@ -31,14 +31,20 @@ #include #include "../XGL/xgl.h" +#include "scenery.h" #include "tileutils.h" +#include "obj.h" #include "../Aircraft/aircraft.h" #include "../Include/constants.h" +#include "../Include/general.h" +#include "../Include/types.h" /* here's where we keep the array of closest (potentially viewable) tiles */ -static long int tile[49]; +struct bucket local_tiles[49]; +GLint local_display_lists[49]; +struct fgCartesianPoint local_refs[49]; /* Initialize the Tile Manager subsystem */ @@ -52,21 +58,73 @@ void fgTileMgrInit() { * the chunk isn't already in the cache, then read it from disk. */ void fgTileMgrUpdate() { struct fgFLIGHT *f; + struct fgGENERAL *g; struct bucket p; + char base_path[256]; + char file_name[256]; + int i, j; f = ¤t_aircraft.flight; + g = &general; find_bucket(FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, &p); printf("Updating Tile list for %d,%d %d,%d\n", p.lon, p.lat, p.x, p.y); - gen_idx_array(&p, tile, 7, 7); + gen_idx_array(&p, local_tiles, 7, 7); + + /* scenery.center = ref; */ + + for ( i = 0; i < 49; i++ ) { + gen_base_path(&local_tiles[i], base_path); + sprintf(file_name, "%s/Scenery/%s/%ld.obj", + g->root_dir, base_path, gen_index(&local_tiles[i])); + local_display_lists[i] = + fgObjLoad(file_name, &local_refs[i]); + + if ( (local_tiles[i].lon == p.lon) && + (local_tiles[i].lat == p.lat) && + (local_tiles[i].x == p.x) && + (local_tiles[i].y == p.y) ) { + scenery.center = local_refs[i]; + } + } +} + + +/* Render the local tiles --- hack, hack, hack */ +void fgTileMgrRender() { + static GLfloat terrain_color[4] = { 0.6, 0.8, 0.4, 1.0 }; + static GLfloat terrain_ambient[4]; + static GLfloat terrain_diffuse[4]; + int i, j; + + for ( i = 0; i < 4; i++ ) { + terrain_ambient[i] = terrain_color[i] * 0.5; + terrain_diffuse[i] = terrain_color[i]; + } + + xglMaterialfv(GL_FRONT, GL_AMBIENT, terrain_ambient); + xglMaterialfv(GL_FRONT, GL_DIFFUSE, terrain_diffuse); + + for ( i = 0; i < 49; i++ ) { + xglPushMatrix(); + xglTranslatef(local_refs[i].x - scenery.center.x, + local_refs[i].y - scenery.center.y, + local_refs[i].z - scenery.center.z); + xglCallList(local_display_lists[i]); + xglPopMatrix(); + } } /* $Log$ -/* Revision 1.2 1998/01/08 02:22:27 curt -/* Continue working on basic features. +/* Revision 1.3 1998/01/13 00:23:11 curt +/* 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.2 1998/01/08 02:22:27 curt + * Continue working on basic features. + * * Revision 1.1 1998/01/07 23:50:51 curt * "area" renamed to "tile" * diff --git a/Scenery/tilemgr.h b/Scenery/tilemgr.h index 23d208bd1..cba5a948e 100644 --- a/Scenery/tilemgr.h +++ b/Scenery/tilemgr.h @@ -33,10 +33,18 @@ void fgTileMgrInit(); void fgTileMgrUpdate(); +/* Render the local tiles --- hack, hack, hack */ +void fgTileMgrRender(); + + /* $Log$ -/* Revision 1.1 1998/01/07 23:50:51 curt -/* "area" renamed to "tile" +/* Revision 1.2 1998/01/13 00:23:11 curt +/* 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 1998/01/07 23:50:51 curt + * "area" renamed to "tile" + * * */ diff --git a/Scenery/tileutils.c b/Scenery/tileutils.c index 298b1e83b..c0a1af2ee 100644 --- a/Scenery/tileutils.c +++ b/Scenery/tileutils.c @@ -205,19 +205,20 @@ void find_bucket(double lon, double lat, struct bucket *p) { /* Given a lat/lon, fill in the local tile index array */ -void gen_idx_array(struct bucket *p1, long int *tiles, +void gen_idx_array(struct bucket *p1, struct bucket *tiles, int width, int height) { - struct bucket p2; + struct bucket *p2; int dw, dh, i, j; dh = height / 2; dw = width / 2; for ( j = 0; j < height; j++ ) { for ( i = 0; i < width; i++ ) { - offset_bucket(p1, &p2, i - dw, j - dh); - tiles[(j*width)+i] = gen_index(&p2); + offset_bucket(p1, &tiles[(j*width)+i], i - dw, j - dh); + p2 = &tiles[(j*width)+i]; printf(" bucket = %d %d %d %d index = %ld\n", - p2.lon, p2.lat, p2.x, p2.y, tiles[(j*width)+i]); + p2->lon, p2->lat, p2->x, p2->y, + gen_index(&tiles[(j*width)+i])); } } } @@ -265,9 +266,13 @@ int main() { /* $Log$ -/* Revision 1.3 1998/01/10 00:01:47 curt -/* Misc api changes and tweaks. +/* Revision 1.4 1998/01/13 00:23:12 curt +/* 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.3 1998/01/10 00:01:47 curt + * Misc api changes and tweaks. + * * Revision 1.2 1998/01/08 02:22:28 curt * Continue working on basic features. * diff --git a/Scenery/tileutils.h b/Scenery/tileutils.h index 314db7a8a..31dd063d1 100644 --- a/Scenery/tileutils.h +++ b/Scenery/tileutils.h @@ -69,7 +69,7 @@ void find_bucket(double lon, double lat, struct bucket *p); /* Given a lat/lon, fill in the local tile index array */ -void gen_idx_array(struct bucket *p1, long int *tiles, +void gen_idx_array(struct bucket *p1, struct bucket *tiles, int width, int height); @@ -77,9 +77,13 @@ void gen_idx_array(struct bucket *p1, long int *tiles, /* $Log$ -/* Revision 1.3 1998/01/10 00:01:48 curt -/* Misc api changes and tweaks. +/* Revision 1.4 1998/01/13 00:23:12 curt +/* 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.3 1998/01/10 00:01:48 curt + * Misc api changes and tweaks. + * * Revision 1.2 1998/01/08 02:22:28 curt * Continue working on basic features. * diff --git a/Time/fg_time.c b/Time/fg_time.c index a5d25af43..8018b6348 100644 --- a/Time/fg_time.c +++ b/Time/fg_time.c @@ -57,6 +57,7 @@ void fgTimeInit(struct fgTIME *t) { t->gst_diff = -9999.0; t->warp = 0; + t->warp = 5 * 3600; t->warp_delta = 0; } @@ -244,7 +245,6 @@ void fgTimeUpdate(struct fgFLIGHT *f, struct fgTIME *t) { printf("Updating time\n"); /* get current Unix calendar time (in seconds) */ - /* warp = 60; */ t->warp += t->warp_delta; t->cur_time = time(NULL) + t->warp; printf(" Current Unix calendar time = %ld warp = %ld delta = %ld\n", @@ -298,9 +298,13 @@ void fgTimeUpdate(struct fgFLIGHT *f, struct fgTIME *t) { /* $Log$ -/* Revision 1.26 1998/01/05 18:44:36 curt -/* Add an option to advance/decrease time from keyboard. +/* Revision 1.27 1998/01/13 00:23:13 curt +/* 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.26 1998/01/05 18:44:36 curt + * Add an option to advance/decrease time from keyboard. + * * Revision 1.25 1997/12/31 17:46:50 curt * Tweaked fg_time.c to be able to use ftime() instead of gettimeofday() *