]> git.mxchange.org Git - flightgear.git/blobdiff - Time/sunpos.c
Shufflin' stuff.
[flightgear.git] / Time / sunpos.c
index c022b4b736f81573d6fdaffaf557f2301d8cab29..186e6cfa99b716a70cd4c183d516c8eb3eb0b8f1 100644 (file)
 
 #include <math.h>
 #include <stdio.h>
-#include <sys/time.h>
+#include <time.h>
 
 #include "sunpos.h"
+#include "fg_time.h"
 #include "../constants.h"
+#include "../GLUT/views.h"
+#include "../Math/fg_geodesy.h"
+#include "../Math/mat3.h"
+#include "../Math/polar.h"
+
 #undef E
 
 
@@ -253,8 +259,70 @@ void fgSunPosition(time_t ssue, double *lon, double *lat) {
 }
 
 
+/* update the cur_time_params structure with the current sun position */
+void fgUpdateSunPos(struct fgCartesianPoint scenery_center) {
+    struct fgTIME *t;
+    struct VIEW *v;
+    MAT3vec nup, nsun;
+    double sun_gd_lat, sl_radius, temp;
+    static int time_warp = 0;
+
+    t = &cur_time_params;
+    v = &current_view;
+
+    time_warp += 200; /* increase this to make the world spin real fast */
+
+    fgSunPosition(time(NULL) + time_warp, &t->sun_lon, &sun_gd_lat);
+
+    fgGeodToGeoc(sun_gd_lat, 0.0, &sl_radius, &t->sun_gc_lat);
+
+    t->fg_sunpos = fgPolarToCart(t->sun_lon, t->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 */
+    t->sun_vec[0] = t->fg_sunpos.x - scenery_center.x; 
+    t->sun_vec[1] = t->fg_sunpos.y - scenery_center.y;
+    t->sun_vec[2] = t->fg_sunpos.z - scenery_center.z;
+    /* make this a directional light source only */
+    t->sun_vec[3] = 0.0;
+
+    /* calculate thesun's relative angle to local up */
+    MAT3_COPY_VEC(nup, v->local_up);
+    nsun[0] = t->fg_sunpos.x; 
+    nsun[1] = t->fg_sunpos.y;
+    nsun[2] = t->fg_sunpos.z;
+    MAT3_NORMALIZE_VEC(nup, temp);
+    MAT3_NORMALIZE_VEC(nsun, temp);
+
+    t->sun_angle = acos(MAT3_DOT_PRODUCT(nup, nsun));
+    printf("SUN ANGLE relative to current location = %.3f rads.\n", 
+          t->sun_angle);
+}
+
+
 /* $Log$
-/* Revision 1.1  1997/08/01 15:27:56  curt
-/* Initial revision.
+/* 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.
+ *
+ * Revision 1.1  1997/08/01 15:27:56  curt
+ * Initial revision.
+ *
  */