]> git.mxchange.org Git - flightgear.git/commitdiff
Working on redoing internal coordinate systems & scenery transformations.
authorcurt <curt>
Thu, 31 Jul 1997 22:52:21 +0000 (22:52 +0000)
committercurt <curt>
Thu, 31 Jul 1997 22:52:21 +0000 (22:52 +0000)
Main/GLmain.c
Main/Makefile
Main/depend
Main/mesh2GL.c
Simulator/Makefile
Simulator/constants.h
Time/Makefile
Weather/weather.c

index 9da31b1eadd9a417df7f5b478162ca299f106428..c7bf6d2ece315a2126177489c52de91f33a2220c 100644 (file)
@@ -47,7 +47,7 @@
 #include "../Math/fg_random.h"
 #include "../Math/mat3.h"
 #include "../Math/polar.h"
-#include "../Timer/fg_timer.h"
+#include "../Time/fg_timer.h"
 #include "../Weather/weather.h"
 
 
@@ -71,7 +71,7 @@ static GLfloat sun_vec[4] = {-3.0, 1.0, 2.0, 0.0 };
 /* static GLint scenery, runway; */
 
 /* Another hack */
-double fogDensity = 60.0; /* in meters = about 70 miles */
+double fogDensity = 60000.0; /* in meters */
 double view_offset = 0.0;
 double goal_view_offset = 0.0;
 
@@ -125,28 +125,56 @@ static void fgInitVisuals() {
  **************************************************************************/
 
 static void fgUpdateViewParams() {
-    struct fgCartesianPoint view_pos;
+    struct fgCartesianPoint view_pos /*, alt_up */;
     struct flight_params *f;
-    MAT3mat R, TMP;
-    MAT3vec vec, up, forward, fwrd_view;
+    MAT3mat R, TMP, UP, LOCAL, VIEW;
+    MAT3vec vec, view_up, forward, view_forward, local_up;
 
     f = &current_aircraft.flight;
 
     /* Tell GL we are about to modify the projection parameters */
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
-    gluPerspective(45.0, 1.0/win_ratio, 0.001, 2000.0);
+    gluPerspective(45.0, 1.0/win_ratio, 1.0, 200000.0);
 
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
     
-    /* calculate position in current FG view coordinate system */
-    view_pos = fgGeodetic2Cartesian(FG_Longitude, FG_Latitude);
-    view_pos = fgRotateCartesianPoint(view_pos);
+    /* calculate view position in current FG view coordinate system */
+    view_pos = fgPolarToCart(FG_Lon_geocentric, FG_Lat_geocentric, 
+                            FG_Radius_to_vehicle * FEET_TO_METER + 1.0);
+    printf("View pos = %.4f, %.4f, %.4f\n", view_pos.x, view_pos.y, view_pos.z);
 
-    printf("*** Altitude = %.2f meters\n", FG_Altitude * FEET_TO_METER);
+    /* Derive the local UP transformation matrix based on *geodetic*
+     * coordinates */
+    MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
+    MAT3rotate(R, vec, FG_Longitude);     /* R = rotate about Z axis */
+    /* printf("Longitude matrix\n"); */
+    /* MAT3print(R, stdout); */
+
+    MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
+    MAT3mult_vec(vec, vec, R);
+    MAT3rotate(TMP, vec, -FG_Latitude);  /* TMP = rotate about X axis */
+    /* printf("Latitude matrix\n"); */
+    /* MAT3print(TMP, stdout); */
+
+    MAT3mult(UP, R, TMP);
+    printf("Local up matrix\n");
+    MAT3print(UP, stdout);
+
+    MAT3_SET_VEC(local_up, 1.0, 0.0, 0.0);
+    MAT3mult_vec(local_up, local_up, UP);
+
+    printf("    Local Up = (%.4f, %.4f, %.4f)\n", local_up[0], local_up[1], 
+          local_up[2]);
+    
+    /* Alternative method to Derive local up vector based on
+     * *geodetic* coordinates */
+    /* alt_up = fgPolarToCart(FG_Longitude, FG_Latitude, 1.0); */
+    /* printf("    Alt Up = (%.4f, %.4f, %.4f)\n", 
+       alt_up.x, alt_up.y, alt_up.z); */
 
-    /* build current rotation matrix */
+    /* Derive the LOCAL aircraft rotation matrix (roll, pitch, yaw) */
     MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
     MAT3rotate(R, vec, FG_Phi);
     /* printf("Roll matrix\n"); */
@@ -163,30 +191,33 @@ static void fgUpdateViewParams() {
     /* MAT3mult_vec(vec, vec, R); */
     /* MAT3rotate(TMP, vec, FG_PI + FG_PI_2 + FG_Psi + view_offset); */
     MAT3rotate(TMP, vec, FG_Psi - FG_PI_2);
- /* printf("Yaw matrix\n");
   /* printf("Yaw matrix\n");
     MAT3print(TMP, stdout); */
-    MAT3mult(R, R, TMP);
+    MAT3mult(LOCAL, R, TMP);
+    printf("LOCAL matrix\n");
+    MAT3print(LOCAL, stdout);
 
-    /* MAT3print(R, stdout); */
+    /* Derive the VIEW matrix */
+    MAT3mult(VIEW, UP, LOCAL);
+    printf("VIEW matrix\n");
+    MAT3print(VIEW, stdout);
 
     /* generate the current up, forward, and fwrd-view vectors */
-    MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
-    MAT3mult_vec(up, vec, R);
-
     MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
-    MAT3mult_vec(forward, vec, R);
+    MAT3mult_vec(view_up, vec, VIEW);
+
+    MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
+    MAT3mult_vec(forward, vec, VIEW);
     printf("Forward vector is (%.2f,%.2f,%.2f)\n", forward[0], forward[1], 
           forward[2]);
 
-    MAT3rotate(TMP, up, view_offset);
-    MAT3mult_vec(fwrd_view, forward, TMP);
+    MAT3rotate(TMP, view_up, view_offset);
+    MAT3mult_vec(view_forward, forward, TMP);
 
-    printf("View pos = %.4f, %.4f, %.4f\n", view_pos.y, view_pos.z,  
-          FG_Altitude * FEET_TO_METER);
-    gluLookAt(view_pos.y, view_pos.z,  FG_Altitude*FEET_TO_METER * 0.001,
-             view_pos.y + fwrd_view[0], view_pos.z + fwrd_view[1], 
-             FG_Altitude*FEET_TO_METER * 0.001 + fwrd_view[2],
-             up[0], up[1], up[2]);
+    gluLookAt(view_pos.x, view_pos.y, view_pos.z,
+             view_pos.x + view_forward[0], view_pos.y + view_forward[1], 
+             view_pos.z + view_forward[2],
+             local_up[0], local_up[1], local_up[2]);
 
     glLightfv( GL_LIGHT0, GL_POSITION, sun_vec );
 }
@@ -621,9 +652,12 @@ int printf (const char *format, ...) {
 
 
 /* $Log$
-/* Revision 1.40  1997/07/30 16:12:42  curt
-/* Moved fg_random routines from Util/ to Math/
+/* Revision 1.41  1997/07/31 22:52:37  curt
+/* Working on redoing internal coordinate systems & scenery transformations.
 /*
+ * Revision 1.40  1997/07/30 16:12:42  curt
+ * Moved fg_random routines from Util/ to Math/
+ *
  * Revision 1.39  1997/07/21 14:45:01  curt
  * Minor tweaks.
  *
index 4d072da7b5f2fc00832b38d4b2dbf4f082ed7bd4..bfee17cee7603b4e3ee7ec62a4d40656443c200a 100644 (file)
@@ -32,7 +32,7 @@ AFILES = ../Aircraft/libAircraft.a ../Controls/libControls.a \
        ../Flight/libFlight.a ../Flight/LaRCsim/libLaRCsim.a \
        ../Flight/Slew/libSlew.a ../Math/libMath.a \
        ../Scenery/libScenery.a \
-       ../Timer/libTimer.a ../Weather/libWeather.a
+       ../Time/libTime.a ../Weather/libWeather.a
 
 
 include ../make.inc
@@ -76,6 +76,9 @@ mesh2GL.o:
 
 #---------------------------------------------------------------------------
 # $Log$
+# Revision 1.27  1997/07/31 22:52:39  curt
+# Working on redoing internal coordinate systems & scenery transformations.
+#
 # Revision 1.26  1997/07/30 16:12:42  curt
 # Moved fg_random routines from Util/ to Math/
 #
index a7b028cfdb1586bd7a1d08568d1165f58be1a3c9..9d73b07c2a5f7a2ab45bf58f452ed7e9ac74f7f5 100644 (file)
@@ -18,8 +18,8 @@ GLmain.o: GLmain.c ../constants.h ../Aircraft/aircraft.h \
  ../Aircraft/../Controls/controls.h \
  ../Aircraft/../Controls/../limits.h ../Scenery/mesh.h \
  ../Scenery/scenery.h ../Math/fg_random.h ../Math/mat3.h \
- ../Math/polar.h ../Math/../types.h ../Timer/fg_timer.h \
+ ../Math/polar.h ../Math/../types.h ../Time/fg_timer.h \
  ../Weather/weather.h
 mesh2GL.o: mesh2GL.c ../constants.h ../Scenery/mesh.h \
- ../Scenery/scenery.h ../Math/fg_random.h ../Math/mat3.h \
- ../Math/polar.h ../Math/../types.h
+ ../Scenery/scenery.h ../Math/fg_geodesy.h ../Math/fg_random.h \
+ ../Math/mat3.h ../Math/polar.h ../Math/../types.h
index 36f3bf1449d8df370585499f39f92f4df2533d17..8d081b00df6e95576f494283de10fb7886525ce2 100644 (file)
@@ -33,6 +33,7 @@
 #include "../constants.h"
 #include "../Scenery/mesh.h"
 #include "../Scenery/scenery.h"
+#include "../Math/fg_geodesy.h"
 #include "../Math/fg_random.h"
 #include "../Math/mat3.h"
 #include "../Math/polar.h"
@@ -40,7 +41,7 @@
 
 /* The following routine is a real hack used for testing puposes only
  * and should probably be removed. */
-void mesh_make_test_object(double lon, double lat) {
+/* void mesh_make_test_object(double lon, double lat) {
     struct fgCartesianPoint origin;
     double elev;
     double b = 0.10;
@@ -77,7 +78,7 @@ void mesh_make_test_object(double lon, double lat) {
     glVertex3d(origin.y - b, origin.z - b, elev);
     glVertex3d(origin.y, origin.z, elev+h);
     glEnd();
-}
+} */
 
 /* walk through mesh and make ogl calls */
 GLint mesh2GL(struct mesh *m) {
@@ -88,6 +89,7 @@ GLint mesh2GL(struct mesh *m) {
 
     float x1, y1, x2, y2, z11, z12, z21, z22;
     struct fgCartesianPoint p11, p12, p21, p22;
+    double gc_lon, gc_lat, sl_radius;
 
     MAT3vec v1, v2, normal; 
     int i, j, istep, jstep, iend, jend;
@@ -100,9 +102,6 @@ GLint mesh2GL(struct mesh *m) {
      * .../Scenery/scenery.c:fgSceneryInit() */
     istep = jstep = cur_scenery_params.terrain_skip ;
 
-    /* setup the batch transformation */
-    fgRotateBatchInit(-m->originx * ARCSEC_TO_RAD, -m->originy * ARCSEC_TO_RAD);
-
     mesh = glGenLists(1);
     glNewList(mesh, GL_COMPILE);
 
@@ -121,25 +120,32 @@ GLint mesh2GL(struct mesh *m) {
        glBegin(GL_TRIANGLE_STRIP);
 
        for ( j = 0; j < jend; j += jstep ) {
-           p11 = fgGeodetic2Cartesian(x1*ARCSEC_TO_RAD, y1*ARCSEC_TO_RAD);
-           /* printf("A geodetic is (%.2f, %.2f)\n", x1, y1); */
-           /* printf("A cart is (%.8f, %.8f, %.8f)\n", p11.x, p11.y, p11.z); */
-           p11 = fgRotateCartesianPoint(p11);
-           /* printf("A point is (%.8f, %.8f, %.8f)\n", p11.y, p11.z, z11); */
-
-           p12 = fgGeodetic2Cartesian(x1*ARCSEC_TO_RAD, y2*ARCSEC_TO_RAD);
-           p12 = fgRotateCartesianPoint(p12);
-
-           p21 = fgGeodetic2Cartesian(x2*ARCSEC_TO_RAD, y1*ARCSEC_TO_RAD);
-           p21 = fgRotateCartesianPoint(p21);
-
-           p22 = fgGeodetic2Cartesian(x2*ARCSEC_TO_RAD, y2*ARCSEC_TO_RAD);
-           p22 = fgRotateCartesianPoint(p22);
-
-           z11 = 0.001 * m->mesh_data[i         * m->cols + j        ];
-           z12 = 0.001 * m->mesh_data[(i+istep) * m->cols + j        ];
-           z21 = 0.001 * m->mesh_data[i         * m->cols + (j+jstep)];
-           z22 = 0.001 * m->mesh_data[(i+istep) * m->cols + (j+jstep)];
+           z11 = m->mesh_data[i         * m->cols + j        ];
+           z12 = m->mesh_data[(i+istep) * m->cols + j        ];
+           z21 = m->mesh_data[i         * m->cols + (j+jstep)];
+           z22 = m->mesh_data[(i+istep) * m->cols + (j+jstep)];
+
+           /* printf("A geodetic point is (%.2f, %.2f, %.2f)\n", 
+              x1, y1, z11); */
+           gc_lon = x1*ARCSEC_TO_RAD;
+           fgGeodToGeoc(y1*ARCSEC_TO_RAD, z11, &sl_radius, &gc_lat);
+           /* printf("A geocentric point is (%.2f, %.2f, %.2f)\n", gc_lon, 
+              gc_lat, sl_radius+z11); */
+           p11 = fgPolarToCart(gc_lon, gc_lat, sl_radius+z11);
+           /* printf("A cart point is (%.8f, %.8f, %.8f)\n", 
+              p11.x, p11.y, p11.z); */
+
+           gc_lon = x1*ARCSEC_TO_RAD;
+           fgGeodToGeoc(y2*ARCSEC_TO_RAD, z12, &sl_radius, &gc_lat);
+           p12 = fgPolarToCart(gc_lon, gc_lat, sl_radius+z12);
+
+           gc_lon = x2*ARCSEC_TO_RAD;
+           fgGeodToGeoc(y1*ARCSEC_TO_RAD, z21, &sl_radius, &gc_lat);
+           p21 = fgPolarToCart(gc_lon, gc_lat, sl_radius+z21);
+
+           gc_lon = x2*ARCSEC_TO_RAD;
+           fgGeodToGeoc(y2*ARCSEC_TO_RAD, z22, &sl_radius, &gc_lat);
+           p22 = fgPolarToCart(gc_lon, gc_lat, sl_radius+z22);
 
            v1[0] = p22.y - p11.y; v1[1] = p22.z - p11.z; v1[2] = z22 - z11;
            v2[0] = p12.y - p11.y; v2[1] = p12.z - p11.z; v2[2] = z12 - z11;
@@ -151,11 +157,11 @@ GLint mesh2GL(struct mesh *m) {
            
            if ( j == 0 ) {
                /* first time through */
-               glVertex3d(p12.y, p12.z, z12);
-               glVertex3d(p11.y, p11.z, z11);
+               glVertex3d(p12.x, p12.y, p12.z);
+               glVertex3d(p11.x, p11.y, p11.z);
            }
            
-           glVertex3d(p22.y, p22.z, z22);
+           glVertex3d(p22.x, p22.y, p22.z);
     
            v2[0] = p21.y - p11.y; v2[1] = p21.z - p11.z; v2[2] = z21 - z11;
            MAT3cross_product(normal, v2, v1);
@@ -164,7 +170,7 @@ GLint mesh2GL(struct mesh *m) {
            /* printf("normal 2 = (%.2f %.2f %.2f\n", normal[0], normal[1], 
                   normal[2]); */
 
-           glVertex3d(p21.y, p21.z, z21);
+           glVertex3d(p21.x, p21.y, p21.z);
 
            x1 += m->row_step * jstep;
            x2 += m->row_step * jstep;
@@ -181,7 +187,7 @@ GLint mesh2GL(struct mesh *m) {
        randx = fg_random() * 3600.0;
        randy = fg_random() * 3600.0;
 
-       mesh_make_test_object(m->originx + randx, m->originy + randy);
+       /* mesh_make_test_object(m->originx + randx, m->originy + randy); */
     }
 
     glEndList();
@@ -192,9 +198,12 @@ GLint mesh2GL(struct mesh *m) {
 
 
 /* $Log$
-/* Revision 1.40  1997/07/30 16:12:43  curt
-/* Moved fg_random routines from Util/ to Math/
+/* Revision 1.41  1997/07/31 22:52:40  curt
+/* Working on redoing internal coordinate systems & scenery transformations.
 /*
+ * Revision 1.40  1997/07/30 16:12:43  curt
+ * Moved fg_random routines from Util/ to Math/
+ *
  * Revision 1.39  1997/07/21 21:20:48  curt
  * Twiddled with random object placement.
  *
index 0ab10174389f93fec6b10d082e1fa5e56f02baf5..75e0dcc02369cc8be45277e7e361cc86272b6dde 100644 (file)
@@ -28,7 +28,7 @@ include make.inc
 
 
 SUBSUBDIRS = Flight/LaRCsim Flight/Slew
-SUBDIRS = Aircraft Controls Flight Math Scenery Timer Weather
+SUBDIRS = Aircraft Controls Flight Math Scenery Time Weather
 MAIN = OpenGL
 
 
@@ -71,6 +71,9 @@ zip: clean
 
 #---------------------------------------------------------------------------
 # $Log$
+# Revision 1.22  1997/07/31 22:52:21  curt
+# Working on redoing internal coordinate systems & scenery transformations.
+#
 # Revision 1.21  1997/07/30 16:12:38  curt
 # Moved fg_random routines from Util/ to Math/
 #
index edc521580269b49557e65aa4d91a5ad098debf9f..0bd37ad9994622d7a968b852d82d44db2cdfeeec 100644 (file)
 #define EARTH_RAD 6378.155
 
 
+/* Earth parameters for WGS 84, taken from LaRCsim/ls_constants.h */
+
+/* Value of earth radius from [8] */
+#define EQUATORIAL_RADIUS_FT 20925650.    /* ft */
+#define EQUATORIAL_RADIUS_KM 6378138.12   /* meter */
+/* Radius squared */
+#define RESQ_FT 437882827922500.          /* ft */
+#define RESQ_KM 40680645877797.1344       /* meter */
+
+/* Value of earth flattening parameter from ref [8] 
+ *
+ *      Note: FP = f
+ *            E  = 1-f
+ *            EPS = sqrt(1-(1-f)^2)
+ */
+              
+#define FP    0.003352813178
+#define E     0.996647186
+#define EPS   0.081819221
+#define INVG  0.031080997
+
+
+/* Conversions */
+
 /* Degrees to Radians */
 #define DEG_TO_RAD       0.017453292          /* deg*pi/180 = rad */
 
 
 
 /* $Log$
-/* Revision 1.7  1997/07/23 21:52:10  curt
-/* Put comments around the text after an #endif for increased portability.
+/* Revision 1.8  1997/07/31 22:52:22  curt
+/* Working on redoing internal coordinate systems & scenery transformations.
 /*
+ * Revision 1.7  1997/07/23 21:52:10  curt
+ * Put comments around the text after an #endif for increased portability.
+ *
  * Revision 1.6  1997/07/21 14:45:01  curt
  * Minor tweaks.
  *
index a12b3e3636f54ffdf6a2ea256908e02e3bc98e76..360884b06b52e219658e8329ee6be752f92fe046 100644 (file)
@@ -24,7 +24,7 @@
 #---------------------------------------------------------------------------
 
 
-TARGET = libTimer.a
+TARGET = libTime.a
 
 CFILES = fg_timer.c
 HFILES = fg_timer.h
@@ -63,6 +63,9 @@ fg_timer.o:
 
 #---------------------------------------------------------------------------
 # $Log$
+# Revision 1.10  1997/07/31 22:52:40  curt
+# Working on redoing internal coordinate systems & scenery transformations.
+#
 # Revision 1.9  1997/07/20 02:19:12  curt
 # First stab at a system to generate os2 makefiles automatically.
 #
index f805e91003d540b337c5eff29be643c7d428da9d..e7f2b8701cff836ce64625efd45ab8fe3545983b 100644 (file)
@@ -40,6 +40,7 @@ void fgWeatherUpdate(double lon, double lat, double alt) {
 
     /* Configure some wind */
     FG_V_north_airmass = 15; /* ft/s =~ 10mph */
+    FG_V_north_airmass = 0; 
 
     /* Add some random turbulence */
     FG_U_gust = fg_random() * 1.0 - 0.5;
@@ -49,9 +50,12 @@ void fgWeatherUpdate(double lon, double lat, double alt) {
 }
 
 /* $Log$
-/* Revision 1.2  1997/07/30 16:12:44  curt
-/* Moved fg_random routines from Util/ to Math/
+/* Revision 1.3  1997/07/31 22:52:41  curt
+/* Working on redoing internal coordinate systems & scenery transformations.
 /*
+ * Revision 1.2  1997/07/30 16:12:44  curt
+ * Moved fg_random routines from Util/ to Math/
+ *
  * Revision 1.1  1997/07/19 23:03:57  curt
  * Initial revision.
  *