From 134081456f4c47b5eb68deb8629dd7eba626790f Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 8 Jul 1997 18:20:11 +0000 Subject: [PATCH] Working on establishing a hard ground. --- Main/GLmain.c | 60 ++++++++++++++++++++++++++++++------------- Main/depend | 5 ++-- Main/mesh2GL.c | 11 +++++--- Scenery/geometry.c | 16 ++++++++---- Scenery/mesh.c | 31 +++++++++++++++++++--- Scenery/mesh.h | 13 +++++++--- Simulator/constants.h | 12 ++++++--- 7 files changed, 110 insertions(+), 38 deletions(-) diff --git a/Main/GLmain.c b/Main/GLmain.c index 404633118..998a4e328 100644 --- a/Main/GLmain.c +++ b/Main/GLmain.c @@ -41,6 +41,7 @@ #include "../constants.h" #include "../Aircraft/aircraft.h" +#include "../Scenery/mesh.h" #include "../Scenery/scenery.h" #include "../Math/mat3.h" #include "../Math/polar.h" @@ -372,6 +373,10 @@ void fgInitTimeDepCalcs() { static void fgMainLoop( void ) { static int remainder = 0; int elapsed, multi_loop; + double rough_elev; + struct flight_params *f; + + f = ¤t_aircraft.flight; elapsed = fgGetTimeInterval(); printf("Time interval is = %d, previous remainder is = %d\n", elapsed, @@ -390,6 +395,17 @@ static void fgMainLoop( void ) { if ( ! use_signals ) { fgUpdateTimeDepCalcs(multi_loop); } + + /* I'm just sticking this here for now, it should probably move + * eventually */ + rough_elev = mesh_altitude(FG_Longitude * RAD_TO_DEG * 3600.0, + FG_Latitude * RAD_TO_DEG * 3600.0); + printf("Ground elevation is about %.2f meters here.\n", rough_elev); + /* FG_Runway_altitude = rough_elev * METER_TO_FEET; */ + + if ( FG_Altitude < FG_Runway_altitude ) { + FG_Altitude = FG_Runway_altitude + 3.758099; + } } @@ -419,6 +435,7 @@ static void fgReshape( int width, int height ) { int main( int argc, char *argv[] ) { struct flight_params *f; + double rough_elev; f = ¤t_aircraft.flight; @@ -513,6 +530,25 @@ int main( int argc, char *argv[] ) { /* fgSlewInit(-335340,162540, 15, 4.38); */ /* fgSlewInit(-398673.28,120625.64, 53, 4.38); */ + /* Initialize the Scenery Management system */ + fgSceneryInit(); + + /* Tell the Scenery Management system where we are so it can load + * the correct scenery data */ + fgSceneryUpdate(FG_Latitude, FG_Longitude, FG_Altitude); + + /* I'm just sticking this here for now, it should probably move + * eventually */ + rough_elev = mesh_altitude(FG_Longitude * RAD_TO_DEG * 3600.0, + FG_Latitude * RAD_TO_DEG * 3600.0); + printf("Ground elevation is about %.2f meters here.\n", rough_elev); + FG_Runway_altitude = rough_elev * METER_TO_FEET; + + if ( FG_Altitude < FG_Runway_altitude ) { + FG_Altitude = FG_Runway_altitude + 3.758099; + } + /* end of thing that I just stuck in that I should probably move */ + /* Initialize the flight model data structures base on above values */ fgFlightModelInit( FG_LARCSIM, f, 1.0 / DEFAULT_MODEL_HZ ); @@ -522,21 +558,6 @@ int main( int argc, char *argv[] ) { fgInitTimeDepCalcs(); } - - /********************************************************************** - * The following section (and the functions elsewhere in this file) - * set up the scenery management system. This part is a big hack, - * and needs to be moved to it's own area. - **********************************************************************/ - - /* Initialize the Scenery Management system */ - fgSceneryInit(); - - /* Tell the Scenery Management system where we are so it can load - * the correct scenery data */ - fgSceneryUpdate(FG_Latitude, FG_Longitude, FG_Altitude); - - /********************************************************************** * Initialize the Event Handlers. **********************************************************************/ @@ -582,10 +603,13 @@ int main( int argc, char *argv[] ) { /* $Log$ -/* Revision 1.27 1997/07/07 20:59:49 curt -/* Working on scenery transformations to enable us to fly fluidly over the -/* poles with no discontinuity/distortion in scenery. +/* Revision 1.28 1997/07/08 18:20:12 curt +/* Working on establishing a hard ground. /* + * Revision 1.27 1997/07/07 20:59:49 curt + * Working on scenery transformations to enable us to fly fluidly over the + * poles with no discontinuity/distortion in scenery. + * * Revision 1.26 1997/07/05 20:43:34 curt * renamed mat3 directory to Math so we could add other math related routines. * diff --git a/Main/depend b/Main/depend index cb706147b..d507caa67 100644 --- a/Main/depend +++ b/Main/depend @@ -16,7 +16,8 @@ GLmain.o: GLmain.c ../constants.h ../Aircraft/aircraft.h \ ../Aircraft/../Flight/LaRCsim/ls_interface.h \ ../Aircraft/../Flight/LaRCsim/../flight.h \ ../Aircraft/../Controls/controls.h \ - ../Aircraft/../Controls/../limits.h ../Scenery/scenery.h \ - ../Math/mat3.h ../Math/polar.h ../Math/../types.h ../Timer/fg_timer.h + ../Aircraft/../Controls/../limits.h ../Scenery/mesh.h \ + ../Scenery/scenery.h ../Math/mat3.h ../Math/polar.h \ + ../Math/../types.h ../Timer/fg_timer.h mesh2GL.o: mesh2GL.c ../constants.h ../Scenery/mesh.h ../Math/mat3.h \ ../Math/polar.h ../Math/../types.h diff --git a/Main/mesh2GL.c b/Main/mesh2GL.c index 846fb73d5..88ed7acaf 100644 --- a/Main/mesh2GL.c +++ b/Main/mesh2GL.c @@ -47,7 +47,7 @@ GLint mesh2GL(struct mesh *m) { printf("In mesh2GL(), generating GL call list.\n"); - istep = jstep = 25; /* Detail level 1 -- 1200 ... */ + istep = jstep = 4; /* Detail level 1 -- 1200 ... */ /* setup the batch transformation */ fgRotateBatchInit(-m->originx * ARCSEC_TO_RAD, -m->originy * ARCSEC_TO_RAD); @@ -133,10 +133,13 @@ GLint mesh2GL(struct mesh *m) { /* $Log$ -/* Revision 1.25 1997/07/07 20:59:50 curt -/* Working on scenery transformations to enable us to fly fluidly over the -/* poles with no discontinuity/distortion in scenery. +/* Revision 1.26 1997/07/08 18:20:13 curt +/* Working on establishing a hard ground. /* + * Revision 1.25 1997/07/07 20:59:50 curt + * Working on scenery transformations to enable us to fly fluidly over the + * poles with no discontinuity/distortion in scenery. + * * Revision 1.24 1997/07/05 20:43:35 curt * renamed mat3 directory to Math so we could add other math related routines. * diff --git a/Scenery/geometry.c b/Scenery/geometry.c index d81c862a9..84499f0e2 100644 --- a/Scenery/geometry.c +++ b/Scenery/geometry.c @@ -33,7 +33,7 @@ static vrmlGeometryType; -static struct mesh eg; +struct mesh eg; /* Begin a new vrml geometry statement */ @@ -109,17 +109,23 @@ int vrmlFreeGeometry() { switch(vrmlGeometryType) { case VRML_ELEV_GRID: - free(eg.mesh_data); + /* We need to rethink this here, we can't just free the data, + * because we need it to calculate current ground elevation + * ... */ + /* free(eg.mesh_data); */ } return(vrmlGeometryType); } /* $Log$ -/* Revision 1.2 1997/07/07 20:59:51 curt -/* Working on scenery transformations to enable us to fly fluidly over the -/* poles with no discontinuity/distortion in scenery. +/* Revision 1.3 1997/07/08 18:20:13 curt +/* Working on establishing a hard ground. /* + * Revision 1.2 1997/07/07 20:59:51 curt + * Working on scenery transformations to enable us to fly fluidly over the + * poles with no discontinuity/distortion in scenery. + * * Revision 1.1 1997/06/29 21:16:48 curt * More twiddling with the Scenery Management system. * diff --git a/Scenery/mesh.c b/Scenery/mesh.c index 89fa0d7ce..579d1f34f 100644 --- a/Scenery/mesh.c +++ b/Scenery/mesh.c @@ -37,7 +37,7 @@ /* Temporary hack until we get the scenery management system running */ extern GLint mesh_hack; - +extern struct mesh eg; /* initialize the non-array mesh values */ void mesh_init(struct mesh *m) { @@ -150,10 +150,35 @@ void mesh_do_it(struct mesh *m) { } +/* return the current altitude based on mesh data. We should rewrite + * this to interpolate exact values, but for now this is good enough */ +double mesh_altitude(double lon, double lat) { + /* we expect things in arcsec for now */ + + double xoffset, yoffset; + int xindex, yindex; + + xoffset = lon - eg.originx; + yoffset = lat - eg.originy; + + xindex = xoffset / eg.col_step; + yindex = yoffset / eg.row_step; + + if ( (xindex >= 0) && (xindex < eg.cols) ) { + if ( (yindex >= 0) && (yindex < eg.rows) ) { + return( eg.mesh_data[xindex * eg.rows + yindex] ); + } + } +} + + /* $Log$ -/* Revision 1.6 1997/06/29 21:16:49 curt -/* More twiddling with the Scenery Management system. +/* Revision 1.7 1997/07/08 18:20:13 curt +/* Working on establishing a hard ground. /* + * Revision 1.6 1997/06/29 21:16:49 curt + * More twiddling with the Scenery Management system. + * * Revision 1.5 1997/06/22 21:44:41 curt * Working on intergrating the VRML (subset) parser. * diff --git a/Scenery/mesh.h b/Scenery/mesh.h index 7d6217269..75a144852 100644 --- a/Scenery/mesh.h +++ b/Scenery/mesh.h @@ -64,17 +64,24 @@ void mesh_set_option_name(struct mesh *m, char *name); void mesh_set_option_value(struct mesh *m, char *value); /* do whatever needs to be done with the mesh now that it's been - loaded, such as generating the OpenGL call list. */ + * loaded, such as generating the OpenGL call list. */ void mesh_do_it(struct mesh *m); +/* return the current altitude based on mesh data. We should rewrite + * this to interpolate exact values, but for now this is good enough */ +double mesh_altitude(double lon, double lat); + #endif MESH_H /* $Log$ -/* Revision 1.3 1997/06/22 21:44:41 curt -/* Working on intergrating the VRML (subset) parser. +/* Revision 1.4 1997/07/08 18:20:14 curt +/* Working on establishing a hard ground. /* + * Revision 1.3 1997/06/22 21:44:41 curt + * Working on intergrating the VRML (subset) parser. + * * Revision 1.2 1997/05/23 15:40:42 curt * Added GNU copyright headers. * diff --git a/Simulator/constants.h b/Simulator/constants.h index 79c765207..a06d76e6c 100644 --- a/Simulator/constants.h +++ b/Simulator/constants.h @@ -45,11 +45,17 @@ /* Feet to Meters */ #define FEET_TO_METER 0.3048 +/* Meters to Feet */ +#define METER_TO_FEET 3.28083989501312335958 + #endif CONSTANTS_H /* $Log$ -/* Revision 1.1 1997/07/07 21:02:36 curt -/* Initial revision. -/* */ +/* Revision 1.2 1997/07/08 18:20:11 curt +/* Working on establishing a hard ground. +/* + * Revision 1.1 1997/07/07 21:02:36 curt + * Initial revision. + * */