From bf40d877a115717f01d1b79bb638cb6525b87cfb Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 14 Jul 1997 16:26:03 +0000 Subject: [PATCH] Testing/playing -- placed objects randomly across the entire terrain. --- Main/mesh2GL.c | 45 +++++++++++++++++++++++++++++++++---------- Scenery/depend | 2 +- Scenery/mesh.c | 38 +++++++++++++++++++++++------------- Scenery/scenery.c | 11 +++++++---- Simulator/constants.h | 11 +++++++++-- Time/Makefile | 5 ++++- 6 files changed, 81 insertions(+), 31 deletions(-) diff --git a/Main/mesh2GL.c b/Main/mesh2GL.c index b6f7106ca..a671816d9 100644 --- a/Main/mesh2GL.c +++ b/Main/mesh2GL.c @@ -30,6 +30,8 @@ #include +#include /* for random(), srandom() */ + #include "../constants.h" #include "../Scenery/mesh.h" #include "../Scenery/scenery.h" @@ -59,15 +61,23 @@ void mesh_make_test_object(double lon, double lat) { origin = fgRotateCartesianPoint(origin); printf("Center of structure is: (%.4f, %.4f\n", origin.y, origin.z); - glBegin(GL_TRIANGLE_STRIP); - glVertex3d(origin.y + b, origin.z-b, elev); - glVertex3d(origin.y - b, origin.z-b, elev); + glBegin(GL_TRIANGLES); + glVertex3d(origin.y - b, origin.z - b, elev); + glVertex3d(origin.y + b, origin.z - b, elev); + glVertex3d(origin.y, origin.z, elev+h); + + glVertex3d(origin.y + b, origin.z - b, elev); + glVertex3d(origin.y + b, origin.z + b, elev); glVertex3d(origin.y, origin.z, elev+h); - glVertex3d(origin.y - b, origin.z+b, elev); - glVertex3d(origin.y + b, origin.z+b, elev); - glVertex3d(origin.y + b, origin.z-b, elev); - glEnd(); + glVertex3d(origin.y + b, origin.z + b, elev); + glVertex3d(origin.y - b, origin.z + b, elev); + glVertex3d(origin.y, origin.z, elev+h); + + glVertex3d(origin.y - b, origin.z + b, elev); + glVertex3d(origin.y - b, origin.z - b, elev); + glVertex3d(origin.y, origin.z, elev+h); + glEnd(); } /* walk through mesh and make ogl calls */ @@ -166,7 +176,19 @@ GLint mesh2GL(struct mesh *m) { } /* this will go, it's only here for testing/debugging */ - mesh_make_test_object(-398391.28, 120070.41); + + /* + for ( i = m->originy; i < m->originy + (m->row_step * iend); i += 120 ) { + for ( j = m->originx; j < m->originx + (m->col_step * jend); j += 120) { + mesh_make_test_object(j, i); + } + } + */ + + for ( i = 0; i < 800; i++ ) { + mesh_make_test_object(m->originx + (random() * 3600.0 / RAND_MAX) , + m->originy + (random() * 3600.0 / RAND_MAX) ); + } glEndList(); @@ -176,9 +198,12 @@ GLint mesh2GL(struct mesh *m) { /* $Log$ -/* Revision 1.32 1997/07/12 03:50:21 curt -/* Added an #include to help compiling for Win32 +/* Revision 1.33 1997/07/14 16:26:04 curt +/* Testing/playing -- placed objects randomly across the entire terrain. /* + * Revision 1.32 1997/07/12 03:50:21 curt + * Added an #include to help compiling for Win32 + * * Revision 1.31 1997/07/12 02:27:07 curt * Looking at potential scenery transformation/coordinate system problems. * diff --git a/Scenery/depend b/Scenery/depend index 0dbd7ff05..463f07901 100644 --- a/Scenery/depend +++ b/Scenery/depend @@ -1,6 +1,6 @@ common.o: common.c common.h geometry.o: geometry.c geometry.h mesh.h -mesh.o: mesh.c scenery.h mesh.h common.h +mesh.o: mesh.c ../constants.h scenery.h mesh.h common.h parser.o: parser.c parsevrml.h geometry.h common.h mesh.h scenery.h scanner.o: scanner.c parser.h scenery.o: scenery.c scenery.h parsevrml.h diff --git a/Scenery/mesh.c b/Scenery/mesh.c index f9ecdc35a..0e3d93f79 100644 --- a/Scenery/mesh.c +++ b/Scenery/mesh.c @@ -38,6 +38,7 @@ #include +#include "../constants.h" #include "scenery.h" #include "mesh.h" #include "common.h" @@ -196,7 +197,7 @@ double mesh_altitude(double lon, double lat) { if ( dx > dy ) { /* lower triangle */ - /* printf(" Lower triangle\n"); */ + printf(" Lower triangle\n"); x1 = xindex; y1 = yindex; @@ -210,20 +211,24 @@ double mesh_altitude(double lon, double lat) { y3 = yindex + skip; z3 = eg.mesh_data[y3 * eg.cols + x3]; - /* printf(" dx = %.2f dy = %.2f\n", dx, dy); + printf(" dx = %.2f dy = %.2f\n", dx, dy); printf(" (x1,y1,z1) = (%d,%d,%d)\n", x1, y1, z1); printf(" (x2,y2,z2) = (%d,%d,%d)\n", x2, y2, z2); - printf(" (x3,y3,z3) = (%d,%d,%d)\n", x3, y3, z3); */ + printf(" (x3,y3,z3) = (%d,%d,%d)\n", x3, y3, z3); zA = dx * (z2 - z1) / skip + z1; zB = dx * (z3 - z1) / skip + z1; - /* printf(" zA = %.2f zB = %.2f\n", zA, zB); */ + printf(" zA = %.2f zB = %.2f\n", zA, zB); - elev = dy * (zB - zA) / dx + zA; + if ( dx > EPSILON ) { + elev = dy * (zB - zA) / dx + zA; + } else { + elev = zA; + } } else { /* upper triangle */ - /* printf(" Upper triangle\n"); */ + printf(" Upper triangle\n"); x1 = xindex; y1 = yindex; @@ -237,18 +242,22 @@ double mesh_altitude(double lon, double lat) { y3 = yindex + skip; z3 = eg.mesh_data[y3 * eg.cols + x3]; - /* printf(" dx = %.2f dy = %.2f\n", dx, dy); + printf(" dx = %.2f dy = %.2f\n", dx, dy); printf(" (x1,y1,z1) = (%d,%d,%d)\n", x1, y1, z1); printf(" (x2,y2,z2) = (%d,%d,%d)\n", x2, y2, z2); - printf(" (x3,y3,z3) = (%d,%d,%d)\n", x3, y3, z3); */ + printf(" (x3,y3,z3) = (%d,%d,%d)\n", x3, y3, z3); zA = dy * (z2 - z1) / skip + z1; zB = dy * (z3 - z1) / skip + z1; - /* printf(" zA = %.2f zB = %.2f\n", zA, zB ); - printf(" xB - xA = %.2f\n", eg.col_step * dy / eg.row_step); */ + printf(" zA = %.2f zB = %.2f\n", zA, zB ); + printf(" xB - xA = %.2f\n", eg.col_step * dy / eg.row_step); - elev = dx * (zB - zA) / dy + zA; + if ( dy > EPSILON ) { + elev = dx * (zB - zA) / dy + zA; + } else { + elev = zA; + } } return(elev); @@ -256,9 +265,12 @@ double mesh_altitude(double lon, double lat) { /* $Log$ -/* Revision 1.14 1997/07/12 04:01:14 curt -/* Added #include to help Win32 compiling. +/* Revision 1.15 1997/07/14 16:26:04 curt +/* Testing/playing -- placed objects randomly across the entire terrain. /* + * Revision 1.14 1997/07/12 04:01:14 curt + * Added #include to help Win32 compiling. + * * Revision 1.13 1997/07/12 02:27:11 curt * Looking at potential scenery transformation/coordinate system problems. * diff --git a/Scenery/scenery.c b/Scenery/scenery.c index 922dbe429..c474910ab 100644 --- a/Scenery/scenery.c +++ b/Scenery/scenery.c @@ -41,7 +41,7 @@ struct scenery_params cur_scenery_params; /* Initialize the Scenery Management system */ void fgSceneryInit() { /* set the default terrain detail level */ - cur_scenery_params.terrain_skip = 4; + cur_scenery_params.terrain_skip = 5; } @@ -65,10 +65,13 @@ void fgSceneryRender() { /* $Log$ -/* Revision 1.5 1997/07/11 03:23:19 curt -/* Solved some scenery display/orientation problems. Still have a positioning -/* (or transformation?) problem. +/* Revision 1.6 1997/07/14 16:26:05 curt +/* Testing/playing -- placed objects randomly across the entire terrain. /* + * Revision 1.5 1997/07/11 03:23:19 curt + * Solved some scenery display/orientation problems. Still have a positioning + * (or transformation?) problem. + * * Revision 1.4 1997/07/11 01:30:03 curt * More tweaking of terrian floor. * diff --git a/Simulator/constants.h b/Simulator/constants.h index a06d76e6c..c735bfcae 100644 --- a/Simulator/constants.h +++ b/Simulator/constants.h @@ -49,13 +49,20 @@ #define METER_TO_FEET 3.28083989501312335958 +/* For divide by zero avoidance, this will be close enough to zero */ +#define EPSILON 0.000001 + + #endif CONSTANTS_H /* $Log$ -/* Revision 1.2 1997/07/08 18:20:11 curt -/* Working on establishing a hard ground. +/* Revision 1.3 1997/07/14 16:26:03 curt +/* Testing/playing -- placed objects randomly across the entire terrain. /* + * 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. * */ diff --git a/Time/Makefile b/Time/Makefile index 47af6b17a..e19d25553 100644 --- a/Time/Makefile +++ b/Time/Makefile @@ -58,11 +58,14 @@ clean: include depend fg_timer.o: - $(CC) $(CFLAGS) $(INCLUDES) -c fg_timer.c + $(CC) $(CFLAGS) -c fg_timer.c #--------------------------------------------------------------------------- # $Log$ +# Revision 1.8 1997/07/14 16:26:05 curt +# Testing/playing -- placed objects randomly across the entire terrain. +# # Revision 1.7 1997/07/12 02:24:48 curt # Added ranlib. # -- 2.39.2