Working on ssg-ifying the sky dome. Added the moon and other various tweaks.

This commit is contained in:
curt 2000-03-06 22:27:52 +00:00
parent 99a59763f1
commit a8d8c9d24e
7 changed files with 62 additions and 167 deletions

View File

@ -28,12 +28,14 @@
// Constructor
FGEphemeris::FGEphemeris( void ) {
our_sun = new Star;
moon = new Moon;
}
// Destructor
FGEphemeris::~FGEphemeris( void ) {
delete our_sun;
delete moon;
}
@ -41,5 +43,6 @@ FGEphemeris::~FGEphemeris( void ) {
// time
void FGEphemeris::update( FGTime *t ) {
our_sun->updatePosition( t );
moon->updatePosition( t, our_sun );
}

View File

@ -29,11 +29,13 @@
#include <Time/fg_time.hxx>
#include "star.hxx"
#include "moon.hxx"
class FGEphemeris {
Star *our_sun;
Moon *moon;
public:
@ -55,6 +57,13 @@ public:
return our_sun->getDeclination();
}
// moon position
inline double getMoonRightAscension() {
return moon->getRightAscension();
}
inline double getMoonDeclination() {
return moon->getDeclination();
}
};

View File

@ -40,6 +40,7 @@
#include "moon.hxx"
/*************************************************************************
* Moon::Moon(FGTime *t)
* Public constructor for class Moon. Initializes the orbital elements and
@ -56,6 +57,7 @@ Moon::Moon(FGTime *t) :
0.054900, 0.000000,
115.3654, 13.0649929509, t)
{
#if 0
int width, height;
FG_LOG( FG_GENERAL, FG_INFO, "Initializing Moon Texture");
@ -125,16 +127,29 @@ Moon::Moon(FGTime *t) :
GL_RGBA, GL_UNSIGNED_BYTE,
moon_halotexbuf);
moonObject = gluNewQuadric();
#endif
}
Moon::Moon() :
CelestialBody(125.1228, -0.0529538083,
5.1454, 0.00000,
318.0634, 0.1643573223,
60.266600, 0.000000,
0.054900, 0.000000,
115.3654, 13.0649929509)
{
}
Moon::~Moon()
{
//delete moonObject;
delete moon_texbuf;
delete moon_halotexbuf;
// delete moon_texbuf;
// delete moon_halotexbuf;
}
#if 0
static int texWidth = 256; /* 64x64 is plenty */
void Moon::setHalo()
@ -182,6 +197,7 @@ void Moon::setHalo()
// GL_UNSIGNED_BYTE, textureBuf);
//free(textureBuf);
}
#endif
/*****************************************************************************
@ -255,7 +271,7 @@ void Moon::updatePosition(FGTime *t, Star *ourSun)
r += (-0.58 * cos(M - 2*D)
-0.46 * cos(2*D)
);
FG_LOG(FG_GENERAL, FG_INFO, "Running moon update");
// FG_LOG(FG_GENERAL, FG_INFO, "Running moon update");
xg = r * cos(lonEcl) * cos(latEcl);
yg = r * sin(lonEcl) * cos(latEcl);
zg = r * sin(latEcl);
@ -308,6 +324,7 @@ void Moon::updatePosition(FGTime *t, Star *ourSun)
}
#if 0
/************************************************************************
* void Moon::newImage()
*
@ -396,3 +413,4 @@ void Moon::newImage()
{
}
}
#endif

View File

@ -24,6 +24,7 @@
#ifndef _MOON_HXX_
#define _MOON_HXX_
#include <simgear/constants.h>
#include <Aircraft/aircraft.hxx>
@ -35,22 +36,27 @@
class Moon : public CelestialBody
{
private:
void TexInit(); // This should move to the constructor eventually.
GLUquadricObj *moonObject;
GLuint Sphere;
GLuint moon_texid;
GLuint moon_halotexid;
GLubyte *moon_texbuf;
GLubyte *moon_halotexbuf;
// void TexInit(); // This should move to the constructor eventually.
// GLUquadricObj *moonObject;
// GLuint Sphere;
// GLuint moon_texid;
// GLuint moon_halotexid;
// GLubyte *moon_texbuf;
// GLubyte *moon_halotexbuf;
// void setHalo();
void setHalo();
public:
Moon ( FGTime *t);
Moon( FGTime *t);
Moon();
~Moon();
void updatePosition(FGTime *t, Star *ourSun);
void newImage();
// void newImage();
};

View File

@ -107,6 +107,7 @@ void SolarSystem::rebuild()
//GLfloat ambient;
//GLfloat amb[4];
#if 0
glDisable(GL_LIGHTING);
// Step 1: update all the positions
@ -155,6 +156,7 @@ void SolarSystem::rebuild()
xglEnable(GL_LIGHTING);
}
xglEndList();
#endif
}
/*****************************************************************************
@ -193,6 +195,7 @@ void SolarSystem::addPlanetToList(double ra, double dec, double magn)
fgLIGHT *l = &cur_light_params;
#if 0
if ((double) (l->sun_angle - FG_PI_2) >
((magnitude - 1.0) * - 20 * DEG_TO_RAD))
{
@ -201,6 +204,7 @@ void SolarSystem::addPlanetToList(double ra, double dec, double magn)
50000.0 * sin (ra) * cos (dec),
50000.0 * sin (dec));
}
#endif
}

View File

@ -22,6 +22,7 @@
* $Id$
**************************************************************************/
#ifdef __BORLANDC__
# define exception c_exception
#endif
@ -35,6 +36,7 @@
#include "star.hxx"
/*************************************************************************
* Star::Star(FGTime *t)
* Public constructor for class Star
@ -68,67 +70,11 @@ Star::Star() :
Star::~Star()
{
#if 0
//delete SunObject;
delete [] sun_texbuf;
#endif
}
#if 0
static int texWidth = 256; /* 64x64 is plenty */
void Star::setTexture()
{
int texSize;
//void *textureBuf;
GLubyte *p;
int i,j;
double radius;
texSize = texWidth*texWidth;
sun_texbuf = new GLubyte[texSize*4];
if (!sun_texbuf)
return; // Ugly!
p = sun_texbuf;
radius = (double)(texWidth / 2);
for (i=0; i < texWidth; i++) {
for (j=0; j < texWidth; j++) {
double x, y, d;
*p = 0xff;
*(p+1) = 0xff;
*(p+2) = 0xff;
x = fabs((double)(i - (texWidth / 2)));
y = fabs((double)(j - (texWidth / 2)));
d = sqrt((x * x) + (y * y));
if (d < radius) {
double t = 1.0 - (d / radius); // t is 1.0 at center, 0.0 at edge */
// inverse square looks nice
*(p+3) = (int)((double) 0xff * (t*t));
} else {
*(p+3) = 0x00;
}
p += 4;
}
}
//gluBuild2DMipmaps(GL_TEXTURE_2D, 1, texWidth, texWidth,
// GL_LUMINANCE,
// GL_UNSIGNED_BYTE, textureBuf);
//free(textureBuf);
}
#endif
/*************************************************************************
* void Jupiter::updatePosition(FGTime *t, Star *ourSun)
* void Star::updatePosition(FGTime *t, Star *ourSun)
*
* calculates the current position of our sun.
*************************************************************************/
@ -169,90 +115,3 @@ void Star::updatePosition(FGTime *t)
rightAscension = atan2 (ye, xe);
declination = atan2 (ze, sqrt (xe*xe + ye*ye));
}
#if 0
void Star::newImage(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 = 550;
// 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
// glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc ( GL_SRC_ALPHA, 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
xglDisable(GL_BLEND); // BLEND DISABLED
}
glPopMatrix();
glDisable(GL_LIGHTING); // LIGHTING DISABLED
glDisable(GL_BLEND); // BLEND DISABLED
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);
xglColor4fv(amb);
xglTranslatef(0,60000,0);
gluSphere( SunObject, sun_size, 10, 10 );
}
glPopMatrix();
glDisable(GL_TEXTURE_2D); // TEXTURE DISABLED
glDisable(GL_BLEND); // BLEND DISABLED
}
}
#endif

View File

@ -24,6 +24,7 @@
#ifndef _STAR_HXX_
#define _STAR_HXX_
#include <Time/fg_time.hxx>
#include "celestialBody.hxx"
@ -35,10 +36,6 @@ private:
double xs, ys; // the sun's rectangular geocentric coordinates
double distance; // the sun's distance to the earth
// GLUquadricObj *SunObject;
// GLuint sun_texid;
// GLubyte *sun_texbuf;
// void setTexture();
public:
@ -52,7 +49,6 @@ public:
double getxs();
double getys();
double getDistance();
// void newImage();
};