Commits

Anonymous committed 7ba5a7e

Sun changes direction with day/night cycle.

  • Participants
  • Parent commits 3820f0f

Comments (0)

Files changed (1)

 #include "texture.h"
 #include "world.h"
 
-#define TIME_SCALE          1000  //how many "milliseconds per in-game minute
+#define TIME_SCALE          250  //how many "milliseconds per in-game minute
 #define max_DISTANCE        450
 #define NIGHT_FOG           (max_DISTANCE / 5)
 #define ENV_TRANSITION      0.2f
 #define NIGHT_SCALING       glRgba (0.0f, 0.1f, 0.4f)
 #define DAY_SCALING         glRgba (1.0f)
 
+#define VECTOR_NIGHT        glVector ( 0.0f, 0.0f, -1.0f)
+#define VECTOR_SUNRISE      glVector (-0.8f, 0.0f, -0.2f)
+#define VECTOR_MORNING      glVector (-0.5f, 0.0f, -0.5f)
+#define VECTOR_AFTERNOON    glVector ( 0.5f, 0.0f, -0.5f)
+#define VECTOR_SUNSET       glVector ( 0.8f, 0.0f, -0.2f)
+
+
 static Env        desired;
 static Env        current;
 static long       seconds;
       desired.color[ENV_COLOR_LIGHT] = glRgba (1.0f, 1.0f, 0.5f);
     else
       glRgba (0.5f, 0.7f, 1.0f);
+    desired.light = glVectorInterpolate (VECTOR_SUNRISE, VECTOR_MORNING, fade);
   } else if (decimal_time >= TIME_DAY && decimal_time < TIME_SUNSET)  { //day
+    fade = (decimal_time - TIME_DAY) / (TIME_SUNSET - TIME_DAY);
     base_color = DAY_COLOR;
     desired.fog_max = max_DISTANCE;
     desired.fog_min = humid_fog;
     color_scaling = DAY_SCALING;
     desired.color[ENV_COLOR_LIGHT] = glRgba (1.0f) + r->color_atmosphere;
     desired.color[ENV_COLOR_LIGHT].Normalize ();
+    desired.light = glVector (0, 0.5f, -0.5f);
+    desired.light = glVectorInterpolate (VECTOR_MORNING, VECTOR_AFTERNOON, fade);
   } else if (decimal_time >= TIME_SUNSET && decimal_time < TIME_DUSK) { // sunset
     fade = (decimal_time - TIME_SUNSET) / (TIME_DUSK - TIME_SUNSET);
     base_color = glRgbaInterpolate (DAY_COLOR, NIGHT_COLOR, fade);
     desired.star_fade = fade;
     color_scaling = glRgbaInterpolate (DAY_SCALING, NIGHT_SCALING, fade);
     desired.color[ENV_COLOR_LIGHT] = glRgba (1.0f, 0.5f, 0.5f);
+    desired.light = glVector (0.8f, 0.0f, -0.2f);
+    desired.light = glVectorInterpolate (VECTOR_AFTERNOON, VECTOR_SUNSET, fade);
  } else { //night
     color_scaling = NIGHT_SCALING;
     base_color = NIGHT_COLOR;
     desired.fog_max = NIGHT_FOG;
     desired.star_fade = 1.0f;
     desired.color[ENV_COLOR_LIGHT] = glRgba (0.5f, 0.7f, 1.0f);
+    desired.light = VECTOR_NIGHT;
   }
   for (i = 0; i < ENV_COLOR_COUNT; i++) {
     if (i == ENV_COLOR_LIGHT) 
   current.fog_max = MathInterpolate (current.fog_max, desired.fog_max, delta);
   current.star_fade = MathInterpolate (current.star_fade, desired.star_fade, delta);
   current.light = glVectorInterpolate (current.light, desired.light, delta);
+  current.light.Normalize ();
 
 }