]> git.mxchange.org Git - flightgear.git/commitdiff
Working on correct real time sun lighting.
authorcurt <curt>
Wed, 6 Aug 1997 00:24:22 +0000 (00:24 +0000)
committercurt <curt>
Wed, 6 Aug 1997 00:24:22 +0000 (00:24 +0000)
Main/GLUTmain.c
Main/depend
Scenery/depend
Scenery/mesh.c
Scenery/scenery.c
Scenery/scenery.h
Time/Makefile
Time/depend
Time/sunpos.c
Time/sunpos.h

index 904fb3e4e402c522d1e5ec6647101588c1346a8f..03fd7cf4faf995d77ecbc634e094937b269f54f1 100644 (file)
 #include "../Aircraft/aircraft.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"
 #include "../Time/fg_timer.h"
+#include "../Time/sunpos.h"
 #include "../Weather/weather.h"
 
 
@@ -55,7 +57,7 @@ struct aircraft_params current_aircraft;
 static GLfloat win_ratio = 1.0;
 
 /* sun direction */
-static GLfloat sun_vec[4] = {0.2948, 0.7816, -0.5498, 0.0 };
+static GLfloat sun_vec[4] = {1.0, 0.0, 0.0, 0.0 };
 
 /* temporary hack */
 /* extern struct mesh *mesh_ptr; */
@@ -136,9 +138,15 @@ static void fgUpdateViewParams() {
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
     
+    glLightfv( GL_LIGHT0, GL_POSITION, sun_vec );
+
     /* calculate view position in current FG view coordinate system */
     view_pos = fgPolarToCart(FG_Longitude, FG_Lat_geocentric, 
                             FG_Radius_to_vehicle * FEET_TO_METER + 1.0);
+    view_pos.x -= scenery.center.x;
+    view_pos.y -= scenery.center.y;
+    view_pos.z -= scenery.center.z;
+
     printf("View pos = %.4f, %.4f, %.4f\n", view_pos.x, view_pos.y, view_pos.z);
 
     /* Derive the LOCAL aircraft rotation matrix (roll, pitch, yaw) */
@@ -214,8 +222,6 @@ static void fgUpdateViewParams() {
              view_pos.x + view_forward[0], view_pos.y + view_forward[1], 
              view_pos.z + view_forward[2],
              view_up[0], view_up[1], view_up[2]);
-
-    glLightfv( GL_LIGHT0, GL_POSITION, sun_vec );
 }
 
 
@@ -248,6 +254,8 @@ static void fgUpdateVisuals( void ) {
 
 void fgUpdateTimeDepCalcs(int multi_loop) {
     struct flight_params *f;
+    struct fgCartesianPoint sunpos;
+    double sun_lon, sun_gd_lat, sun_gc_lat, sl_radius;
     int i;
 
     f = &current_aircraft.flight;
@@ -260,6 +268,21 @@ void fgUpdateTimeDepCalcs(int multi_loop) {
     /* printf("updating flight model x %d\n", multi_loop); */
     fgFlightModelUpdate(FG_LARCSIM, f, multi_loop);
 
+    /* refresh sun position */
+    fgSunPosition(time(NULL), &sun_lon, &sun_gd_lat);
+    fgGeodToGeoc(sun_gd_lat, 0, &sl_radius, &sun_gc_lat);
+    sunpos = fgPolarToCart(sun_lon, sun_gc_lat, sl_radius);
+    printf("Sun position is (%.2f, %.2f, %.2f)\n", 
+          sunpos.x, sunpos.y, sunpos.z);
+    /* not necessary to divide, but I'm just doing it by a "random"
+     * constant to get near the magnitude of the number down to the
+     * 0.0 - 1.0 range */
+    sun_vec[0] = -sunpos.x; 
+    sun_vec[1] = -sunpos.y;
+    sun_vec[2] = -sunpos.z;
+    sun_vec[3] = 0.0;       /* make this a directional light source only */
+
+    /* update the view angle */
     for ( i = 0; i < multi_loop; i++ ) {
        if ( fabs(goal_view_offset - view_offset) < 0.05 ) {
            view_offset = goal_view_offset;
@@ -620,9 +643,12 @@ int main( int argc, char *argv[] ) {
 
 
 /* $Log$
-/* Revision 1.2  1997/08/04 20:25:15  curt
-/* Organizational tweaking.
+/* Revision 1.3  1997/08/06 00:24:22  curt
+/* Working on correct real time sun lighting.
 /*
+ * Revision 1.2  1997/08/04 20:25:15  curt
+ * Organizational tweaking.
+ *
  * Revision 1.1  1997/08/02 18:45:00  curt
  * Renamed GLmain.c GLUTmain.c
  *
index 98e04a03c3bcde2b1864afa0fc0afe98830570f2..084a1f8cf8968223e04ae0c980d13e86a9a8caaa 100644 (file)
@@ -1,22 +1,15 @@
-GLTKkey.o: GLTKkey.c /usr/include/gltk.h GLTKkey.h \
- ../Aircraft/aircraft.h ../Aircraft/../Flight/flight.h \
- ../Aircraft/../Flight/Slew/slew.h \
- ../Aircraft/../Flight/LaRCsim/ls_interface.h \
- ../Aircraft/../Flight/LaRCsim/../flight.h \
- ../Aircraft/../Controls/controls.h \
- ../Aircraft/../Controls/../limits.h
 GLUTkey.o: GLUTkey.c GLUTkey.h ../Aircraft/aircraft.h \
  ../Aircraft/../Flight/flight.h ../Aircraft/../Flight/Slew/slew.h \
  ../Aircraft/../Flight/LaRCsim/ls_interface.h \
  ../Aircraft/../Flight/LaRCsim/../flight.h \
  ../Aircraft/../Controls/controls.h \
  ../Aircraft/../Controls/../limits.h ../constants.h
-GLmain.o: GLmain.c ../constants.h ../Aircraft/aircraft.h \
+GLUTmain.o: GLUTmain.c ../constants.h ../Aircraft/aircraft.h \
  ../Aircraft/../Flight/flight.h ../Aircraft/../Flight/Slew/slew.h \
  ../Aircraft/../Flight/LaRCsim/ls_interface.h \
  ../Aircraft/../Flight/LaRCsim/../flight.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 ../Time/fg_timer.h \
- ../Weather/weather.h
+ ../Scenery/scenery.h ../Scenery/../types.h ../Math/fg_random.h \
+ ../Math/mat3.h ../Math/polar.h ../Math/../types.h ../Time/fg_timer.h \
+ ../Time/sunpos.h ../Weather/weather.h
index 463f07901842f0f3c4109b733983eb2092594a94..39f19db9bea60da2164249e960026e5e03f52bff 100644 (file)
@@ -1,6 +1,10 @@
+chunkmgr.o: chunkmgr.c chunkmgr.h mesh.h
 common.o: common.c common.h
 geometry.o: geometry.c geometry.h mesh.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
+mesh.o: mesh.c ../constants.h ../types.h ../Math/fg_geodesy.h \
+ ../Math/fg_random.h ../Math/mat3.h ../Math/polar.h ../Math/../types.h \
+ mesh.h common.h scenery.h
+parser.o: parser.c parsevrml.h geometry.h common.h mesh.h scenery.h \
+ ../types.h
 scanner.o: scanner.c parser.h
-scenery.o: scenery.c scenery.h parsevrml.h
+scenery.o: scenery.c scenery.h ../types.h parsevrml.h
index 45de26ad73875a7d5df9266ef8324c37cc46cb70..cf154c72de58436d74b16b0818b9cedd53959904 100644 (file)
@@ -175,7 +175,7 @@ double mesh_altitude(double lon, double lat) {
     int xindex, yindex;
     int skip;
 
-    skip = cur_scenery_params.terrain_skip;
+    skip = scenery.terrain_skip;
     /* determine if we are in the lower triangle or the upper triangle 
        ______
        |   /|
@@ -275,10 +275,11 @@ GLint mesh_to_OpenGL(struct mesh *m) {
     GLint mesh;
     /* static GLfloat color[4] = { 0.5, 0.4, 0.25, 1.0 }; */ /* dark desert */
     static GLfloat color[4] = { 0.5, 0.5, 0.25, 1.0 };
+    double centerx, centery;
     double randx, randy;
 
     float x1, y1, x2, y2, z11, z12, z21, z22;
-    struct fgCartesianPoint p11, p12, p21, p22;
+    struct fgCartesianPoint p11, p12, p21, p22, c;
     double gc_lon, gc_lat, sl_radius;
 
     MAT3vec v1, v2, normal; 
@@ -290,7 +291,13 @@ GLint mesh_to_OpenGL(struct mesh *m) {
     /* Detail level.  This is how big a step we take as we walk
      * through the DEM data set.  This value is initialized in
      * .../Scenery/scenery.c:fgSceneryInit() */
-    istep = jstep = cur_scenery_params.terrain_skip ;
+    istep = jstep = scenery.terrain_skip ;
+
+    centerx = m->originx + (m->rows * m->row_step) / 2.0;
+    centery = m->originy + (m->cols * m->col_step) / 2.0;
+    fgGeodToGeoc(centery*ARCSEC_TO_RAD, 0, &sl_radius, &gc_lat);
+    c = fgPolarToCart(centerx*ARCSEC_TO_RAD, gc_lat, sl_radius);
+    scenery.center = c;
 
     mesh = glGenLists(1);
     glNewList(mesh, GL_COMPILE);
@@ -347,11 +354,11 @@ GLint mesh_to_OpenGL(struct mesh *m) {
             
             if ( j == 0 ) {
                 /* first time through */
-                glVertex3d(p12.x, p12.y, p12.z);
-                glVertex3d(p11.x, p11.y, p11.z);
+                glVertex3d(p12.x - c.x, p12.y - c.y, p12.z - c.z);
+                glVertex3d(p11.x - c.x, p11.y - c.y, p11.z - c.z);
             }
             
-            glVertex3d(p22.x, p22.y, p22.z);
+            glVertex3d(p22.x - c.x, p22.y - c.y, p22.z - c.z);
     
             v2[0] = p21.y - p11.y; v2[1] = p21.z - p11.z; v2[2] = z21 - z11;
             MAT3cross_product(normal, v2, v1);
@@ -360,7 +367,7 @@ GLint mesh_to_OpenGL(struct mesh *m) {
             /* printf("normal 2 = (%.2f %.2f %.2f\n", normal[0], normal[1], 
                    normal[2]); */
 
-            glVertex3d(p21.x, p21.y, p21.z);
+            glVertex3d(p21.x - c.x, p21.y - c.y, p21.z - c.z);
 
             x1 += m->row_step * jstep;
             x2 += m->row_step * jstep;
@@ -387,9 +394,12 @@ GLint mesh_to_OpenGL(struct mesh *m) {
 
 
 /* $Log$
-/* Revision 1.18  1997/08/02 19:10:14  curt
-/* Incorporated mesh2GL.c into mesh.c
+/* Revision 1.19  1997/08/06 00:24:28  curt
+/* Working on correct real time sun lighting.
 /*
+ * Revision 1.18  1997/08/02 19:10:14  curt
+ * Incorporated mesh2GL.c into mesh.c
+ *
  * Revision 1.17  1997/07/18 23:41:26  curt
  * Tweaks for building with Cygnus Win32 compiler.
  *
index a865663747c1eeb5db8d97459d7e3db72a2bd6a7..bffe5db20f755c429a5d098fd491b32c57956cf2 100644 (file)
@@ -39,13 +39,13 @@ GLint mesh_hack;
 
 
 /* Shared structure to hold current scenery parameters */
-struct scenery_params cur_scenery_params;
+struct scenery_params scenery;
 
 
 /* Initialize the Scenery Management system */
 void fgSceneryInit() {
     /* set the default terrain detail level */
-    cur_scenery_params.terrain_skip = 5;
+    scenery.terrain_skip = 3;
 }
 
 
@@ -69,9 +69,12 @@ void fgSceneryRender() {
 
 
 /* $Log$
-/* Revision 1.9  1997/08/04 17:08:11  curt
-/* Testing cvs on IRIX 6.x
+/* Revision 1.10  1997/08/06 00:24:30  curt
+/* Working on correct real time sun lighting.
 /*
+ * Revision 1.9  1997/08/04 17:08:11  curt
+ * Testing cvs on IRIX 6.x
+ *
  * Revision 1.8  1997/07/18 23:41:27  curt
  * Tweaks for building with Cygnus Win32 compiler.
  *
index a3687dd6d1b1be0124626daa260c1d61e5f403d1..aea333f56100b97f94f9d446b5ad4540a0886f5b 100644 (file)
 #define SCENERY_H
 
 
+#include "../types.h"
+
+
 /* Define a structure containing global scenery parameters */
 struct scenery_params {
-    int terrain_skip;  /* number of terrain data points to skip */
+    /* number of terrain data points to skip */
+    int terrain_skip;
+
+    /* center of current scenery chunk */
+    struct fgCartesianPoint center;
 };
 
-extern struct scenery_params cur_scenery_params;
+extern struct scenery_params scenery;
 
 
 /* Initialize the Scenery Management system */
@@ -53,9 +60,12 @@ void fgSceneryRender();
 
 
 /* $Log$
-/* Revision 1.7  1997/07/23 21:52:27  curt
-/* Put comments around the text after an #endif for increased portability.
+/* Revision 1.8  1997/08/06 00:24:30  curt
+/* Working on correct real time sun lighting.
 /*
+ * Revision 1.7  1997/07/23 21:52:27  curt
+ * Put comments around the text after an #endif for increased portability.
+ *
  * Revision 1.6  1997/07/11 01:30:03  curt
  * More tweaking of terrian floor.
  *
index 0e21a5f63ca3320ffc9f2a7e3f5364282b97a38e..023960526b19c58d9ea820c47d032cc1349fc965 100644 (file)
@@ -26,8 +26,7 @@
 
 TARGET = libTime.a
 
-CFILES = fg_timer.c sunpos.c
-HFILES = fg_timer.h
+CFILES = fg_time.c fg_timer.c sunpos.c
 OFILES = $(CFILES:.c=.o)
 
 
@@ -63,6 +62,9 @@ fg_timer.o:
 
 #---------------------------------------------------------------------------
 # $Log$
+# Revision 1.12  1997/08/06 00:24:31  curt
+# Working on correct real time sun lighting.
+#
 # Revision 1.11  1997/08/01 15:28:44  curt
 # Added sunpos.c
 #
index 8c5772056171f93053b2ce04b5ee6ef51f087323..582f969dd235176dc60eeb2e8d4ab6088e957a0d 100644 (file)
@@ -1,2 +1,3 @@
+fg_time.o: fg_time.c fg_time.h ../types.h
 fg_timer.o: fg_timer.c fg_timer.h
 sunpos.o: sunpos.c sunpos.h ../constants.h
index c022b4b736f81573d6fdaffaf557f2301d8cab29..3eb00e22ba255b607d79826b05d4b6d2c344f51c 100644 (file)
@@ -41,7 +41,7 @@
 
 #include <math.h>
 #include <stdio.h>
-#include <sys/time.h>
+#include <time.h>
 
 #include "sunpos.h"
 #include "../constants.h"
@@ -254,7 +254,10 @@ void fgSunPosition(time_t ssue, double *lon, double *lat) {
 
 
 /* $Log$
-/* Revision 1.1  1997/08/01 15:27:56  curt
-/* Initial revision.
+/* Revision 1.2  1997/08/06 00:24:32  curt
+/* Working on correct real time sun lighting.
 /*
+ * Revision 1.1  1997/08/01 15:27:56  curt
+ * Initial revision.
+ *
  */
index d153042de6f3070821c582ab5f6bd9e89dd775b2..ded7a040c5c39a0b971154c65887ab0ad52da948 100644 (file)
@@ -40,7 +40,7 @@
 #define SUNPOS_H
 
 
-#include <sys/time.h>
+#include <time.h>
 
 
 /* given a particular time (expressed in seconds since the unix