From 749d282dcf94d46555517b1c2852a9547c3f9208 Mon Sep 17 00:00:00 2001 From: curt Date: Sun, 11 Apr 1999 13:19:29 +0000 Subject: [PATCH] Changes contributed by Durk Talsma to allow the user to specify a startup date/time. --- Simulator/Astro/moon.cxx | 71 +++++++++++++++---- Simulator/Astro/moon.hxx | 1 + Simulator/Astro/solarsystem.cxx | 4 +- Simulator/Astro/star.cxx | 104 +++++++++++++++++++++++++-- Simulator/Astro/star.hxx | 1 + Simulator/Main/3dfx.sh | 2 +- Simulator/Main/GLUTmain.cxx | 1 + Simulator/Main/options.cxx | 122 +++++++++++++++++++++++++++++++- Simulator/Main/options.hxx | 5 ++ Simulator/Main/views.cxx | 2 - Simulator/Time/fg_time.cxx | 63 +++++++++++++---- Simulator/Time/fg_time.hxx | 4 +- 12 files changed, 344 insertions(+), 36 deletions(-) diff --git a/Simulator/Astro/moon.cxx b/Simulator/Astro/moon.cxx index 4df64ae12..970328a23 100644 --- a/Simulator/Astro/moon.cxx +++ b/Simulator/Astro/moon.cxx @@ -308,8 +308,8 @@ void Moon::newImage() int moonSize = 750; GLfloat moonColor[4] = {0.85, 0.75, 0.35, 1.0}; - GLfloat black[4] = {0.0, 0.0,0.0,1.0}; - GLfloat white[4] = {1.0, 1.0,1.0,1.0}; + GLfloat black[4] = {0.0, 0.0, 0.0, 1.0}; + GLfloat white[4] = {1.0, 1.0, 1.0, 0.0}; if( moon_angle*RAD_TO_DEG < 100 ) { @@ -341,7 +341,7 @@ void Moon::newImage() FG_LOG( FG_GENERAL, FG_INFO, "Ra = (" << (RAD_TO_DEG *rightAscension) << "), Dec= (" << (RAD_TO_DEG *declination) << ")" ); - xglTranslatef(0.0, 58600.0, 0.0); + xglTranslatef(0.0, 60000.0, 0.0); glEnable(GL_BLEND); // BLEND ENABLED if (current_options.get_textures()) @@ -375,16 +375,24 @@ void Moon::newImage() if (current_options.get_textures()) { glBindTexture(GL_TEXTURE_2D, moon_texid); - //glDisable(GL_LIGHTING); // LIGHTING DISABLED - gluQuadricTexture(moonObject, GL_TRUE ); + // glDisable(GL_LIGHTING); // LIGHTING DISABLED + gluQuadricTexture(moonObject, GL_TRUE ); + // glDisable(GL_LIGHTING); + // glDisable(GL_TEXTURE_2D); // TEXTURE DISABLED } + //glDisable(GL_LIGHTING); // for testing + //glDisable(GL_BLEND); // also for testing + //glColor3f(1.0, 0.0, 0.0); // also also for testing gluSphere(moonObject, moonSize, 12, 12 ); - glDisable(GL_TEXTURE_2D); // TEXTURE DISABLED - glDisable(GL_BLEND); // BLEND DISABLED + //glDisable(GL_LIGHTING); // LIGHTING DISABLED + //glColor4fv(white); + //glBlendFunc(GL_ZERO, GL_SRC_COLOR); // Set alpha to zero + //gluSphere(moonObject, moonSize, 12, 12 ); + glDisable(GL_TEXTURE_2D); // TEXTURE DISABLED + glDisable(GL_BLEND); // BLEND DISABLED } xglPopMatrix(); - glDisable(GL_LIGHTING); // LIGHTING DISABLED - + glDisable(GL_LIGHTING); } else { @@ -392,8 +400,47 @@ void Moon::newImage() } +void Moon::castShadow() +{ + fgLIGHT *l = &cur_light_params; + float moon_angle = l->moon_angle; + + /*double x_2, x_4, x_8, x_10; + GLfloat ambient; + GLfloat amb[4];*/ + int moonSize = 750; + GLfloat moonColor[4] = {0.85, 0.75, 0.35, 1.0}; + GLfloat black[4] = {0.0, 0.0, 0.0, 1.0}; + GLfloat white[4] = {1.0, 1.0, 1.0, 0.0}; + + if( moon_angle*RAD_TO_DEG < 100 ) + { + xglPushMatrix(); + { + //xglRotatef(-90, 0.0, 0.0, 1.0); + xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0); + xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0); + + FG_LOG( FG_GENERAL, FG_INFO, + "Ra = (" << (RAD_TO_DEG *rightAscension) + << "), Dec= (" << (RAD_TO_DEG *declination) << ")" ); + xglTranslatef(0.0, 60000.0, 0.0); + glEnable(GL_BLEND); // BLEND ENABLED + + glDisable(GL_LIGHTING); // LIGHTING DISABLED + //glColor4fv(white); + glColor4f(1.0, 1.0, 1.0, 0.0); + glBlendFunc(GL_ZERO, GL_SRC_COLOR); // Set alpha to zero + //glBlendFunc(GL_ZERO,GL_ZERO); + gluSphere(moonObject, moonSize, 12, 12 ); + glDisable(GL_TEXTURE_2D); // TEXTURE DISABLED + glDisable(GL_BLEND); // BLEND DISABLED + } + xglPopMatrix(); - - - + } + else + { + } +} diff --git a/Simulator/Astro/moon.hxx b/Simulator/Astro/moon.hxx index 62451601e..5f728bea2 100644 --- a/Simulator/Astro/moon.hxx +++ b/Simulator/Astro/moon.hxx @@ -50,6 +50,7 @@ public: ~Moon(); void updatePosition(FGTime *t, Star *ourSun); void newImage(); + void castShadow(); }; diff --git a/Simulator/Astro/solarsystem.cxx b/Simulator/Astro/solarsystem.cxx index 33bbe5456..d72147265 100644 --- a/Simulator/Astro/solarsystem.cxx +++ b/Simulator/Astro/solarsystem.cxx @@ -140,7 +140,9 @@ void SolarSystem::rebuild() // Step 2b: Add the sun //xglPushMatrix(); //{ - ourSun->newImage(); + //ourSun->drawHalo(); + //earthsMoon->castShadow(); + ourSun->newImage(); //} //xglPopMatrix(); // Step 2c: Add the planets diff --git a/Simulator/Astro/star.cxx b/Simulator/Astro/star.cxx index 8fa7fa906..2e7393d8f 100644 --- a/Simulator/Astro/star.cxx +++ b/Simulator/Astro/star.cxx @@ -242,9 +242,9 @@ void Star::newImage(void) //glEnable(GL_BLEND); //glDisable(GL_LIGHTING); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D, sun_texid); - + glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-5000, 0.0, -5000); glTexCoord2f(1.0f, 0.0f); glVertex3f( 5000, 0.0, -5000); @@ -252,19 +252,111 @@ void Star::newImage(void) glTexCoord2f(0.0f, 1.0f); glVertex3f(-5000, 0.0, 5000); glEnd(); } - xglDisable(GL_TEXTURE_2D); - glDisable(GL_BLEND); + xglDisable(GL_TEXTURE_2D); // TEXTURE DISABLED + glDisable(GL_BLEND); // BLEND DISABLED } + glPopMatrix(); - glPushMatrix(); + glDisable(GL_LIGHTING); + /*glPushMatrix(); // Draw a black object, that serves as the moon's shadow. { xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0); xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0); - xglTranslatef(0,58600,0); + xglTranslatef(0,60000,0); + //xglTranslatef(0,58600,0); + //gluSphere( SunObject, sun_size, 10, 10 ); + glEnable(GL_BLEND); + glBlendFunc(GL_ZERO, GL_ZERO); + xglColor4f(0.0, 0.0, 0.0, 0.0); gluSphere( SunObject, sun_size, 10, 10 ); } + glPopMatrix();*/ + glDisable(GL_BLEND); + glPushMatrix(); + { + //xglEnable(GL_BLEND); + //xglBlendFunc(GL_SRC_ALPHA, GL_ONE); + xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0); + xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0); + xglColor4fv(amb); + xglTranslatef(0,60000,0); + gluSphere( SunObject, sun_size, 10, 10 ); + } glPopMatrix(); glDisable(GL_TEXTURE_2D); // TEXTURE DISABLED glDisable(GL_BLEND); // BLEND DISABLED } } + + +void Star::drawHalo(void) +{ + /*static float stars[3]; + stars[0] = 0.0; + stars[1] = 0.0; + stars[2] = 1.0;*/ + + fgLIGHT *l = &cur_light_params; + float sun_angle = l->sun_angle; + + if( sun_angle*RAD_TO_DEG < 100 ) { // else no need to draw sun + + + double x_2, x_4, x_8, x_10; + GLfloat ambient; + GLfloat amb[4]; + int sun_size = 750; + + // daily variation sun gets larger near horizon + /*if(sun_angle*RAD_TO_DEG > 84.0 && sun_angle*RAD_TO_DEG < 95) + { + double sun_grow = 9*fabs(94-sun_angle*RAD_TO_DEG); + sun_size = (int)(sun_size + sun_size * cos(sun_grow*DEG_TO_RAD)); + }*/ + x_2 = sun_angle * sun_angle; + x_4 = x_2 * x_2; + x_8 = x_4 * x_4; + x_10 = x_8 * x_2; + ambient = (float)(0.4 * pow (1.1, - x_10 / 30.0)); + if (ambient < 0.3) ambient = 0.3; + if (ambient > 1.0) ambient = 1.0; + + amb[0] = ((ambient * 6.0) - 1.0); // minimum value = 0.8 + amb[1] = ((ambient * 11.0) - 3.0); // minimum value = 0.3 + amb[2] = ((ambient * 12.0) - 3.6); // minimum value = 0.0 + amb[3] = 1.00; + + if (amb[0] > 1.0) amb[0] = 1.0; + if (amb[1] > 1.0) amb[1] = 1.0; + if (amb[2] > 1.0) amb[2] = 1.0; + xglColor3fv(amb); + glPushMatrix(); + { + xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0); + xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0); + xglTranslatef(0,60000,0); + if (current_options.get_textures()) + { + glEnable(GL_TEXTURE_2D); // TEXTURE ENABLED + glEnable(GL_BLEND); // BLEND ENABLED + + //glEnable(GL_TEXTURE_2D); + //glEnable(GL_BLEND); + //glDisable(GL_LIGHTING); + //glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glBindTexture(GL_TEXTURE_2D, sun_texid); + + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex3f(-5000, 0.0, -5000); + glTexCoord2f(1.0f, 0.0f); glVertex3f( 5000, 0.0, -5000); + glTexCoord2f(1.0f, 1.0f); glVertex3f( 5000, 0.0, 5000); + glTexCoord2f(0.0f, 1.0f); glVertex3f(-5000, 0.0, 5000); + glEnd(); + } + xglDisable(GL_TEXTURE_2D); // TEXTURE DISABLED + glDisable(GL_BLEND); // BLEND DISABLED + } + glPopMatrix(); + } +} diff --git a/Simulator/Astro/star.hxx b/Simulator/Astro/star.hxx index 6eb7a4c90..0de6713ac 100644 --- a/Simulator/Astro/star.hxx +++ b/Simulator/Astro/star.hxx @@ -51,6 +51,7 @@ public: double getys(); double getDistance(); void newImage(); + void drawHalo(); }; diff --git a/Simulator/Main/3dfx.sh b/Simulator/Main/3dfx.sh index cb766b743..9f15e8f53 100755 --- a/Simulator/Main/3dfx.sh +++ b/Simulator/Main/3dfx.sh @@ -1,6 +1,6 @@ #!/bin/sh -WINDOW=YES +WINDOW=NO if [ $WINDOW = "YES" ]; then # in a window (slow hack) diff --git a/Simulator/Main/GLUTmain.cxx b/Simulator/Main/GLUTmain.cxx index f50784ec4..8e561e2a2 100644 --- a/Simulator/Main/GLUTmain.cxx +++ b/Simulator/Main/GLUTmain.cxx @@ -304,6 +304,7 @@ static void fgRenderFrame( void ) { // draw stars and planets fgStarsRender(); + //xglEnable(GL_DEPTH_TEST); SolarSystem::theSolarSystem->draw(); xglPopMatrix(); diff --git a/Simulator/Main/options.cxx b/Simulator/Main/options.cxx index 9bc2f3b04..2ee0db0ed 100644 --- a/Simulator/Main/options.cxx +++ b/Simulator/Main/options.cxx @@ -42,6 +42,7 @@ bool global_fullscreen = true; #include #include #include +#include