]> git.mxchange.org Git - flightgear.git/commitdiff
Worked on better simulating real lighting.
authorcurt <curt>
Tue, 19 Aug 1997 23:55:03 +0000 (23:55 +0000)
committercurt <curt>
Tue, 19 Aug 1997 23:55:03 +0000 (23:55 +0000)
Main/GLUTmain.c
Scenery/mesh.c
Scenery/scenery.c
Time/sunpos.c

index b16b0d52f0a12c985fdc33ae1a60b76e77287ffe..731fb15ae87971aab22096eaf4f782632078f86e 100644 (file)
@@ -60,6 +60,12 @@ static GLfloat win_ratio = 1.0;
 /* sun direction */
 static GLfloat sun_vec[4] = {1.0, 0.0, 0.0, 0.0 };
 
+/* if the 4th field is 0.0, this specifies a direction ... */
+/* clear color (sky) */
+static GLfloat fgClearColor[4] = {0.60, 0.60, 0.90, 1.0};
+/* fog color */
+static GLfloat fgFogColor[4] =   {0.65, 0.65, 0.85, 1.0};
+
 /* temporary hack */
 /* extern struct mesh *mesh_ptr; */
 /* Function prototypes */
@@ -90,9 +96,6 @@ int use_signals = 0;
  **************************************************************************/
 
 static void fgInitVisuals() {
-    /* if the 4th field is 0.0, this specifies a direction ... */
-    static GLfloat fogColor[4] = {0.65, 0.65, 0.85, 1.0};
-    
     glEnable( GL_DEPTH_TEST );
     /* glFrontFace(GL_CW); */
     glEnable( GL_CULL_FACE );
@@ -111,11 +114,12 @@ static void fgInitVisuals() {
     glFogi (GL_FOG_MODE, GL_LINEAR);
     /* glFogf (GL_FOG_START, 1.0); */
     glFogf (GL_FOG_END, fogDensity);
-    glFogfv (GL_FOG_COLOR, fogColor);
+    glFogfv (GL_FOG_COLOR, fgFogColor);
     /* glFogf (GL_FOG_DENSITY, fogDensity); */
     /* glHint (GL_FOG_HINT, GL_FASTEST); */
 
-    glClearColor(0.6, 0.6, 0.9, 1.0);
+    glClearColor(fgClearColor[0], fgClearColor[1], fgClearColor[2], 
+                fgClearColor[3]);
 }
 
 
@@ -129,9 +133,9 @@ static void fgUpdateViewParams() {
     struct time_params *t;
     MAT3mat R, TMP, UP, LOCAL, VIEW;
     MAT3vec vec, view_up, forward, view_forward, local_up, nup, nsun;
-    double sun_angle, temp, ambient, diffuse;
+    double sun_angle, temp, ambient, diffuse, sky;
     GLfloat color[4] = { 1.0, 1.0, 0.50, 1.0 };
-    GLfloat amb[4], diff[4];
+    GLfloat amb[3], diff[3], fog[4], clear[4];
 
     f = &current_aircraft.flight;
     t = &cur_time_params;
@@ -241,31 +245,43 @@ static void fgUpdateViewParams() {
     MAT3_NORMALIZE_VEC(nsun, temp);
 
     sun_angle = acos(MAT3_DOT_PRODUCT(nup, nsun));
-    printf("SUN ANGLE relative to current location = %.3f\n", sun_angle);
-
-    if ( (sun_angle >= -FG_PI) && (sun_angle <= FG_PI) ) {
-       /* day time */
-       /* ya kind'a have to plot this to see the magic */
-       ambient = 0.4 * cos(0.15*sun_angle*sun_angle);
-       diffuse = 0.4 * cos(0.45*sun_angle);
-    } else {
-       /* night time */
-       ambient = 0.4;
-       diffuse = 0.0;
-    }
+    printf("SUN ANGLE relative to current location = %.3f rads.\n", sun_angle);
+
+    /* ya kind'a have to plot this to see the magic */
+    ambient = 0.4 * pow(2.4, -sun_angle*sun_angle*sun_angle*sun_angle/3.0);
+    diffuse = 0.4 * cos(0.6*sun_angle*sun_angle);
+    sky = 0.85 * pow(1.6, -sun_angle*sun_angle*sun_angle*sun_angle/2.0) + 0.15;
+
+    if ( ambient < 0.1 ) { ambient = 0.1; }
+    if ( diffuse < 0.0 ) { diffuse = 0.0; }
+
+    if ( sky < 0.0 ) { sky = 0.0; }
 
     amb[0] = color[0] * ambient;
     amb[1] = color[1] * ambient;
     amb[2] = color[2] * ambient;
-    amb[3] = color[3];
 
     diff[0] = color[0] * diffuse;
     diff[1] = color[1] * diffuse;
     diff[2] = color[2] * diffuse;
-    diff[3] = color[3];
 
-    glMaterialfv(GL_FRONT, GL_AMBIENT, amb );
-    glMaterialfv(GL_FRONT, GL_DIFFUSE, diff );
+    /* set lighting parameters */
+    glLightfv(GL_LIGHT0, GL_AMBIENT, amb );
+    glLightfv(GL_LIGHT0, GL_DIFFUSE, diff );
+
+    /* set fog color */
+    fog[0] = fgFogColor[0] * (ambient + diffuse);
+    fog[1] = fgFogColor[1] * (ambient + diffuse);
+    fog[2] = fgFogColor[2] * (ambient + diffuse);
+    fog[3] = fgFogColor[3];
+    glFogfv (GL_FOG_COLOR, fog);
+
+    /* set sky color */
+    clear[0] = fgClearColor[0] * sky;
+    clear[1] = fgClearColor[1] * sky;
+    clear[2] = fgClearColor[2] * sky;
+    clear[3] = fgClearColor[3];
+    glClearColor(clear[0], clear[1], clear[2], clear[3]);
 }
 
 
@@ -684,9 +700,12 @@ int main( int argc, char *argv[] ) {
 
 
 /* $Log$
-/* Revision 1.7  1997/08/16 12:22:38  curt
-/* Working on improving the lighting/shading.
+/* Revision 1.8  1997/08/19 23:55:03  curt
+/* Worked on better simulating real lighting.
 /*
+ * Revision 1.7  1997/08/16 12:22:38  curt
+ * Working on improving the lighting/shading.
+ *
  * Revision 1.6  1997/08/13 20:24:56  curt
  * Changes due to changing sunpos interface.
  *
index cf154c72de58436d74b16b0818b9cedd53959904..ccde7ab0dbda995341df2474c55229dc88e05e8c 100644 (file)
@@ -302,7 +302,8 @@ GLint mesh_to_OpenGL(struct mesh *m) {
     mesh = glGenLists(1);
     glNewList(mesh, GL_COMPILE);
 
-    glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color );
+    /* glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color ); */
+    glColor3fv(color);
 
     iend = m->cols - 1;
     jend = m->rows - 1;
@@ -394,9 +395,12 @@ GLint mesh_to_OpenGL(struct mesh *m) {
 
 
 /* $Log$
-/* Revision 1.19  1997/08/06 00:24:28  curt
-/* Working on correct real time sun lighting.
+/* Revision 1.20  1997/08/19 23:55:08  curt
+/* Worked on better simulating real lighting.
 /*
+ * Revision 1.19  1997/08/06 00:24:28  curt
+ * Working on correct real time sun lighting.
+ *
  * Revision 1.18  1997/08/02 19:10:14  curt
  * Incorporated mesh2GL.c into mesh.c
  *
index b13b16f5aa672661fa35c611d77753cc9e9966e0..f1b745bc6009a2082e2adb0aae5d2cf5a00ac535 100644 (file)
@@ -45,7 +45,7 @@ struct scenery_params scenery;
 /* Initialize the Scenery Management system */
 void fgSceneryInit() {
     /* set the default terrain detail level */
-    scenery.terrain_skip = 10;
+    scenery.terrain_skip = 5;
 }
 
 
@@ -69,9 +69,12 @@ void fgSceneryRender() {
 
 
 /* $Log$
-/* Revision 1.11  1997/08/13 20:24:22  curt
-/* Changed default detail level.
+/* Revision 1.12  1997/08/19 23:55:08  curt
+/* Worked on better simulating real lighting.
 /*
+ * Revision 1.11  1997/08/13 20:24:22  curt
+ * Changed default detail level.
+ *
  * Revision 1.10  1997/08/06 00:24:30  curt
  * Working on correct real time sun lighting.
  *
index ecb8fcffc6fa6cba294979a4959d338dd95c031b..1c1bf77df479e9fc06d1ddbb17693ad1282f2e53 100644 (file)
@@ -265,7 +265,7 @@ void fgUpdateSunPos() {
 
     t = &cur_time_params;
 
-    time_warp += 600; /* increase this to make the world spin real fast */
+    time_warp += 300; /* increase this to make the world spin real fast */
 
     fgSunPosition(time(NULL) + time_warp, &t->sun_lon, &sun_gd_lat);
 
@@ -276,10 +276,13 @@ void fgUpdateSunPos() {
 
 
 /* $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.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.
  *