]> git.mxchange.org Git - flightgear.git/blobdiff - Time/sunpos.c
Add xgl wrappers for debugging.
[flightgear.git] / Time / sunpos.c
index 25cfc09812f4a441c14a195d4fd20369bd9f07fb..e1b0e16a602a664c1f808c8f0c07d2202e95bb7a 100644 (file)
@@ -45,7 +45,7 @@
 
 #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"
@@ -261,51 +261,85 @@ 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 fgLIGHT *l;
     struct fgTIME *t;
-    struct VIEW *v;
+    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 += 0; /* increase this to make the world spin real fast */
 
-    fgSunPosition(t->cur_time + 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 */
-    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;
+    /* 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); */
+
+    /* 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);
+
+    /* 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] = t->fg_sunpos.x; 
-    nsun[1] = t->fg_sunpos.y;
-    nsun[2] = t->fg_sunpos.z;
+    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);
 
-    t->sun_angle = acos(MAT3_DOT_PRODUCT(nup, nsun));
+    l->sun_angle = acos(MAT3_DOT_PRODUCT(nup, nsun));
     printf("SUN ANGLE relative to current location = %.3f rads.\n", 
-          t->sun_angle);
+          l->sun_angle);
 }
 
 
 /* $Log$
-/* Revision 1.11  1997/10/28 21:07:21  curt
-/* Changed GLUT/ -> Main/
+/* 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.