]> git.mxchange.org Git - flightgear.git/blobdiff - Time/sunpos.c
Integrated new event manager with subsystem initializations.
[flightgear.git] / Time / sunpos.c
index ecb8fcffc6fa6cba294979a4959d338dd95c031b..74e2276a5623ea5e68a84e1d4ca57e2f482522ae 100644 (file)
 
 #include "sunpos.h"
 #include "fg_time.h"
-#include "../constants.h"
+#include "../Include/constants.h"
+#include "../Main/views.h"
 #include "../Math/fg_geodesy.h"
+#include "../Math/mat3.h"
 #include "../Math/polar.h"
 
+
 #undef E
 
 
@@ -259,27 +262,120 @@ void fgSunPosition(time_t ssue, double *lon, double *lat) {
 
 /* update the cur_time_params structure with the current sun position */
 void fgUpdateSunPos() {
-    struct time_params *t;
-    double sun_gd_lat, sl_radius;
+    struct fgLIGHT *l;
+    struct fgTIME *t;
+    struct fgVIEW *v;
+    MAT3vec nup, nsun;
+    double sun_gd_lat, sl_radius, temp;
     static int time_warp = 0;
 
+    l = &cur_light_params;
     t = &cur_time_params;
+    v = &current_view;
+
+    printf("  Updating Sun position\n");
+
+    time_warp += 0; /* increase this to make the world spin real fast */
+
+    fgSunPosition(t->cur_time + time_warp, &l->sun_lon, &sun_gd_lat);
+
+    fgGeodToGeoc(sun_gd_lat, 0.0, &sl_radius, &l->sun_gc_lat);
+
+    l->fg_sunpos = fgPolarToCart(l->sun_lon, l->sun_gc_lat, sl_radius);
 
-    time_warp += 600; /* increase this to make the world spin real fast */
+    /* printf("  Geodetic lat = %.5f Geocentric lat = %.5f\n", sun_gd_lat,
+       t->sun_gc_lat); */
 
-    fgSunPosition(time(NULL) + time_warp, &t->sun_lon, &sun_gd_lat);
+    /* FALSE! (?> the sun position has to be translated just like
+     * everything else */
+    /* l->sun_vec_inv[0] = l->fg_sunpos.x - scenery_center.x;  */
+    /* l->sun_vec_inv[1] = l->fg_sunpos.y - scenery_center.y; */
+    /* l->sun_vec_inv[2] = l->fg_sunpos.z - scenery_center.z; */
+    /* MAT3_SCALE_VEC(l->sun_vec, l->sun_vec_inv, -1.0); */
 
-    fgGeodToGeoc(sun_gd_lat, 0.0, &sl_radius, &t->sun_gc_lat);
+    /* I think this will work better for generating the sun light vector */
+    l->sun_vec[0] = l->fg_sunpos.x;
+    l->sun_vec[1] = l->fg_sunpos.y;
+    l->sun_vec[2] = l->fg_sunpos.z;
+    MAT3_NORMALIZE_VEC(l->sun_vec, temp);
+    MAT3_SCALE_VEC(l->sun_vec_inv, l->sun_vec, -1.0);
 
-    t->fg_sunpos = fgPolarToCart(t->sun_lon, t->sun_gc_lat, sl_radius);
+    /* make these are directional light sources only */
+    l->sun_vec[3] = 0.0;
+    l->sun_vec_inv[3] = 0.0;
+
+    /* calculate the sun's relative angle to local up */
+    MAT3_COPY_VEC(nup, v->local_up);
+    nsun[0] = l->fg_sunpos.x; 
+    nsun[1] = l->fg_sunpos.y;
+    nsun[2] = l->fg_sunpos.z;
+    MAT3_NORMALIZE_VEC(nup, temp);
+    MAT3_NORMALIZE_VEC(nsun, temp);
+
+    l->sun_angle = acos(MAT3_DOT_PRODUCT(nup, nsun));
+    printf("  SUN ANGLE relative to current location = %.3f rads.\n", 
+          l->sun_angle);
 }
 
 
 /* $Log$
-/* Revision 1.3  1997/08/13 20:23:49  curt
-/* The interface to sunpos now updates a global structure rather than returning
-/* current sun position.
+/* Revision 1.19  1997/12/30 20:47:59  curt
+/* Integrated new event manager with subsystem initializations.
 /*
+ * Revision 1.18  1997/12/23 04:58:40  curt
+ * Tweaked the sky coloring a bit to build in structures to allow finer rgb
+ * control.
+ *
+ * Revision 1.17  1997/12/15 23:55:08  curt
+ * Add xgl wrappers for debugging.
+ * Generate terrain normals on the fly.
+ *
+ * Revision 1.16  1997/12/11 04:43:57  curt
+ * Fixed sun vector and lighting problems.  I thing the moon is now lit
+ * correctly.
+ *
+ * Revision 1.15  1997/12/10 22:37:55  curt
+ * Prepended "fg" on the name of all global structures that didn't have it yet.
+ * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
+ *
+ * Revision 1.14  1997/12/09 04:25:39  curt
+ * Working on adding a global lighting params structure.
+ *
+ * Revision 1.13  1997/11/25 19:25:42  curt
+ * Changes to integrate Durk's moon/sun code updates + clean up.
+ *
+ * Revision 1.12  1997/11/15 18:15:39  curt
+ * Reverse direction of sun vector, so object normals can be more normal.
+ *
+ * Revision 1.11  1997/10/28 21:07:21  curt
+ * Changed GLUT/ -> Main/
+ *
+ * Revision 1.10  1997/09/13 02:00:09  curt
+ * Mostly working on stars and generating sidereal time for accurate star
+ * placement.
+ *
+ * Revision 1.9  1997/09/05 14:17:31  curt
+ * More tweaking with stars.
+ *
+ * Revision 1.8  1997/09/05 01:36:04  curt
+ * Working on getting stars right.
+ *
+ * Revision 1.7  1997/09/04 02:17:40  curt
+ * Shufflin' stuff.
+ *
+ * Revision 1.6  1997/08/27 03:30:37  curt
+ * Changed naming scheme of basic shared structures.
+ *
+ * Revision 1.5  1997/08/22 21:34:41  curt
+ * Doing a bit of reorganizing and house cleaning.
+ *
+ * Revision 1.4  1997/08/19 23:55:09  curt
+ * Worked on better simulating real lighting.
+ *
+ * Revision 1.3  1997/08/13 20:23:49  curt
+ * The interface to sunpos now updates a global structure rather than returning
+ * current sun position.
+ *
  * Revision 1.2  1997/08/06 00:24:32  curt
  * Working on correct real time sun lighting.
  *