]> git.mxchange.org Git - flightgear.git/blobdiff - Time/sunpos.c
Prepended "fg" on the name of all global structures that didn't have it yet.
[flightgear.git] / Time / sunpos.c
index ecb8fcffc6fa6cba294979a4959d338dd95c031b..e5b554db5ac125dd648a93daa74289e2e46521e4 100644 (file)
@@ -46,7 +46,9 @@
 #include "sunpos.h"
 #include "fg_time.h"
 #include "../constants.h"
+#include "../Main/views.h"
 #include "../Math/fg_geodesy.h"
+#include "../Math/mat3.h"
 #include "../Math/polar.h"
 
 #undef E
@@ -258,28 +260,96 @@ 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;
+void fgUpdateSunPos(struct fgCartesianPoint scenery_center) {
+    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;
 
-    time_warp += 600; /* increase this to make the world spin real fast */
+    time_warp += 0; /* increase this to make the world spin real fast */
 
-    fgSunPosition(time(NULL) + time_warp, &t->sun_lon, &sun_gd_lat);
+    fgSunPosition(t->cur_time + time_warp, &l->sun_lon, &sun_gd_lat);
 
-    fgGeodToGeoc(sun_gd_lat, 0.0, &sl_radius, &t->sun_gc_lat);
+    fgGeodToGeoc(sun_gd_lat, 0.0, &sl_radius, &l->sun_gc_lat);
 
-    t->fg_sunpos = fgPolarToCart(t->sun_lon, t->sun_gc_lat, sl_radius);
+    l->fg_sunpos = fgPolarToCart(l->sun_lon, l->sun_gc_lat, sl_radius);
+
+    /* printf("Geodetic lat = %.5f Geocentric lat = %.5f\n", sun_gd_lat,
+       t->sun_gc_lat); */
+
+    /* 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);
+
+    /* make these are directional light sources only */
+    l->sun_vec[3] = 0.0;
+    l->sun_vec_inv[3] = 0.0;
+
+    /* calculate thesun'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.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.
  *