Complete overhaul of the sky/sun/moon/stars/planets. It is now an ssg

model that get's inserted into the scene graph.
This commit is contained in:
curt 2000-03-16 03:17:04 +00:00
parent 84482ad30d
commit 427f309aea
13 changed files with 690 additions and 605 deletions

View File

@ -1,9 +1,11 @@
noinst_LIBRARIES = libSky.a
libSky_a_SOURCES = \
skydome.cxx skydome.hxx \
skymoon.cxx skymoon.hxx \
skysun.cxx skysun.hxx \
sphere.cxx sphere.hxx
dome.cxx dome.hxx \
moon.cxx moon.hxx \
oursun.cxx oursun.hxx \
sky.cxx sky.hxx \
sphere.cxx sphere.hxx \
stars.cxx stars.hxx
INCLUDES += -I$(top_builddir) -I$(top_builddir)/src

View File

@ -1,4 +1,4 @@
// skydome.cxx -- model sky with an upside down "bowl"
// dome.cxx -- model sky with an upside down "bowl"
//
// Written by Curtis Olson, started December 1997.
// SSG-ified by Curtis Olson, February 2000.
@ -39,13 +39,7 @@
#include <simgear/debug/logstream.hxx>
#include <simgear/math/fg_random.h>
// #include <Aircraft/aircraft.hxx>
// #include <FDM/flight.hxx>
// #include <Main/views.hxx>
// #include <Time/event.hxx>
// #include <Time/fg_time.hxx>
#include "skydome.hxx"
#include "dome.hxx"
#ifdef __MWERKS__
@ -69,27 +63,43 @@
#define BOTTOM_ELEV -2000.0
// Set up dome rendering callbacks
static int sgSkyDomePreDraw( ssgEntity *e ) {
/* cout << endl << "Dome Pre Draw" << endl << "----------------"
<< endl << endl; */
glDisable( GL_DEPTH_TEST );
glDisable( GL_FOG );
return true;
}
static int sgSkyDomePostDraw( ssgEntity *e ) {
/* cout << endl << "Dome Post Draw" << endl << "----------------"
<< endl << endl; */
glEnable( GL_DEPTH_TEST );
glEnable( GL_FOG );
return true;
}
// Constructor
FGSkyDome::FGSkyDome( void ) {
SGSkyDome::SGSkyDome( void ) {
}
// Destructor
FGSkyDome::~FGSkyDome( void ) {
SGSkyDome::~SGSkyDome( void ) {
}
// initialize the sky object and connect it into our scene graph
bool FGSkyDome::initialize( ) {
ssgBranch * SGSkyDome::build( ) {
sgVec4 color;
float theta;
int i;
// create the scene graph for the dome
dome = new ssgRoot;
dome->setName( "Sky Dome" );
// set up the state
dome_state = new ssgSimpleState();
dome_state->setShadeModel( GL_SMOOTH );
@ -209,9 +219,6 @@ bool FGSkyDome::initialize( ) {
// build the ssg scene graph sub tree for the sky and connected
// into the provide scene graph branch
dome_selector = new ssgSelector;
dome_transform = new ssgTransform;
ssgVtxTable *center_disk, *upper_ring, *middle_ring, *lower_ring;
center_disk = new ssgVtxTable( GL_TRIANGLE_FAN,
@ -231,17 +238,27 @@ bool FGSkyDome::initialize( ) {
middle_ring->setState( dome_state );
lower_ring->setState( dome_state );
dome_transform = new ssgTransform;
dome_transform->addKid( center_disk );
dome_transform->addKid( upper_ring );
dome_transform->addKid( middle_ring );
dome_transform->addKid( lower_ring );
dome_selector->addKid( dome_transform );
dome_selector->clrTraversalMaskBits( SSGTRAV_HOT );
// not entirely satisfying. We are depending here that the first
// thing we add to a parent is the first drawn
center_disk->setCallback( SSG_CALLBACK_PREDRAW, sgSkyDomePreDraw );
center_disk->setCallback( SSG_CALLBACK_POSTDRAW, sgSkyDomePostDraw );
dome->addKid( dome_selector );
upper_ring->setCallback( SSG_CALLBACK_PREDRAW, sgSkyDomePreDraw );
upper_ring->setCallback( SSG_CALLBACK_POSTDRAW, sgSkyDomePostDraw );
return true;
middle_ring->setCallback( SSG_CALLBACK_PREDRAW, sgSkyDomePreDraw );
middle_ring->setCallback( SSG_CALLBACK_POSTDRAW, sgSkyDomePostDraw );
lower_ring->setCallback( SSG_CALLBACK_PREDRAW, sgSkyDomePreDraw );
lower_ring->setCallback( SSG_CALLBACK_POSTDRAW, sgSkyDomePostDraw );
return dome_transform;
}
@ -251,7 +268,7 @@ bool FGSkyDome::initialize( ) {
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool FGSkyDome::repaint( sgVec4 sky_color, sgVec4 fog_color, double sun_angle )
bool SGSkyDome::repaint( sgVec4 sky_color, sgVec4 fog_color, double sun_angle )
{
double diff;
sgVec3 outer_param, outer_amt, outer_diff;
@ -452,7 +469,7 @@ bool FGSkyDome::repaint( sgVec4 sky_color, sgVec4 fog_color, double sun_angle )
// lat specifies a rotation about the new Y axis
// spin specifies a rotation about the new Z axis (and orients the
// sunrise/set effects
bool FGSkyDome::reposition( sgVec3 p, double lon, double lat, double spin ) {
bool SGSkyDome::reposition( sgVec3 p, double lon, double lat, double spin ) {
sgMat4 T, LON, LAT, SPIN;
sgVec3 axis;
@ -493,316 +510,3 @@ bool FGSkyDome::reposition( sgVec3 p, double lon, double lat, double spin ) {
return true;
}
// Draw the skydome
bool FGSkyDome::draw() {
ssgCullAndDraw( dome );
return true;
}
#if 0
// depricated code from here to the end
// Calculate the sky structure vertices
void fgSkyVerticesInit() {
float theta;
int i;
FG_LOG(FG_ASTRO, FG_INFO, " Generating the sky dome vertices.");
for ( i = 0; i < 12; i++ ) {
theta = (i * 30.0) * DEG_TO_RAD;
inner_vertex[i][0] = cos(theta) * UPPER_RADIUS;
inner_vertex[i][1] = sin(theta) * UPPER_RADIUS;
inner_vertex[i][2] = UPPER_ELEV;
// printf(" %.2f %.2f\n", cos(theta) * UPPER_RADIUS,
// sin(theta) * UPPER_RADIUS);
middle_vertex[i][0] = cos((double)theta) * MIDDLE_RADIUS;
middle_vertex[i][1] = sin((double)theta) * MIDDLE_RADIUS;
middle_vertex[i][2] = MIDDLE_ELEV;
outer_vertex[i][0] = cos((double)theta) * LOWER_RADIUS;
outer_vertex[i][1] = sin((double)theta) * LOWER_RADIUS;
outer_vertex[i][2] = LOWER_ELEV;
bottom_vertex[i][0] = cos((double)theta) * BOTTOM_RADIUS;
bottom_vertex[i][1] = sin((double)theta) * BOTTOM_RADIUS;
bottom_vertex[i][2] = BOTTOM_ELEV;
}
}
// (Re)calculate the sky colors at each vertex
void fgSkyColorsInit() {
fgLIGHT *l;
double sun_angle, diff;
double outer_param[3], outer_amt[3], outer_diff[3];
double middle_param[3], middle_amt[3], middle_diff[3];
int i, j;
l = &cur_light_params;
FG_LOG( FG_ASTRO, FG_INFO,
" Generating the sky colors for each vertex." );
// setup for the possibility of sunset effects
sun_angle = l->sun_angle * RAD_TO_DEG;
// fgPrintf( FG_ASTRO, FG_INFO,
// " Sun angle in degrees = %.2f\n", sun_angle);
if ( (sun_angle > 80.0) && (sun_angle < 100.0) ) {
// 0.0 - 0.4
outer_param[0] = (10.0 - fabs(90.0 - sun_angle)) / 20.0;
outer_param[1] = (10.0 - fabs(90.0 - sun_angle)) / 40.0;
outer_param[2] = -(10.0 - fabs(90.0 - sun_angle)) / 30.0;
// outer_param[2] = 0.0;
middle_param[0] = (10.0 - fabs(90.0 - sun_angle)) / 40.0;
middle_param[1] = (10.0 - fabs(90.0 - sun_angle)) / 80.0;
middle_param[2] = 0.0;
outer_diff[0] = outer_param[0] / 6.0;
outer_diff[1] = outer_param[1] / 6.0;
outer_diff[2] = outer_param[2] / 6.0;
middle_diff[0] = middle_param[0] / 6.0;
middle_diff[1] = middle_param[1] / 6.0;
middle_diff[2] = middle_param[2] / 6.0;
} else {
outer_param[0] = outer_param[1] = outer_param[2] = 0.0;
middle_param[0] = middle_param[1] = middle_param[2] = 0.0;
outer_diff[0] = outer_diff[1] = outer_diff[2] = 0.0;
middle_diff[0] = middle_diff[1] = middle_diff[2] = 0.0;
}
// printf(" outer_red_param = %.2f outer_red_diff = %.2f\n",
// outer_red_param, outer_red_diff);
// calculate transition colors between sky and fog
for ( j = 0; j < 3; j++ ) {
outer_amt[j] = outer_param[j];
middle_amt[j] = middle_param[j];
}
for ( i = 0; i < 6; i++ ) {
for ( j = 0; j < 3; j++ ) {
diff = l->sky_color[j] - l->fog_color[j];
// printf("sky = %.2f fog = %.2f diff = %.2f\n",
// l->sky_color[j], l->fog_color[j], diff);
upper_color[i][j] = (GLubyte)((l->sky_color[j] - diff * 0.3) * 255);
middle_color[i][j] = (GLubyte)((l->sky_color[j] - diff * 0.9
+ middle_amt[j]) * 255);
lower_color[i][j] = (GLubyte)((l->fog_color[j] + outer_amt[j])
* 255);
if ( upper_color[i][j] > 255 ) { upper_color[i][j] = 255; }
if ( upper_color[i][j] < 25 ) { upper_color[i][j] = 25; }
if ( middle_color[i][j] > 255 ) { middle_color[i][j] = 255; }
if ( middle_color[i][j] < 25 ) { middle_color[i][j] = 25; }
if ( lower_color[i][j] > 255 ) { lower_color[i][j] = 255; }
if ( lower_color[i][j] < 25 ) { lower_color[i][j] = 25; }
}
upper_color[i][3] = middle_color[i][3] = lower_color[i][3] =
(GLubyte)(l->sky_color[3] * 255);
for ( j = 0; j < 3; j++ ) {
outer_amt[j] -= outer_diff[j];
middle_amt[j] -= middle_diff[j];
}
/*
printf("upper_color[%d] = %.2f %.2f %.2f %.2f\n", i, upper_color[i][0],
upper_color[i][1], upper_color[i][2], upper_color[i][3]);
printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i,
middle_color[i][0], middle_color[i][1], middle_color[i][2],
middle_color[i][3]);
printf("lower_color[%d] = %.2f %.2f %.2f %.2f\n", i,
lower_color[i][0], lower_color[i][1], lower_color[i][2],
lower_color[i][3]);
*/
}
for ( j = 0; j < 3; j++ ) {
outer_amt[j] = 0.0;
middle_amt[j] = 0.0;
}
for ( i = 6; i < 12; i++ ) {
for ( j = 0; j < 3; j++ ) {
diff = l->sky_color[j] - l->fog_color[j];
// printf("sky = %.2f fog = %.2f diff = %.2f\n",
// l->sky_color[j], l->fog_color[j], diff);
upper_color[i][j] = (GLubyte)((l->sky_color[j] - diff * 0.3) * 255);
middle_color[i][j] = (GLubyte)((l->sky_color[j] - diff * 0.9
+ middle_amt[j]) * 255);
lower_color[i][j] = (GLubyte)((l->fog_color[j] + outer_amt[j])
* 255);
if ( upper_color[i][j] > 255 ) { upper_color[i][j] = 255; }
if ( upper_color[i][j] < 25 ) { upper_color[i][j] = 25; }
if ( middle_color[i][j] > 255 ) { middle_color[i][j] = 255; }
if ( middle_color[i][j] < 25 ) { middle_color[i][j] = 25; }
if ( lower_color[i][j] > 255 ) { lower_color[i][j] = 255; }
if ( lower_color[i][j] < 35 ) { lower_color[i][j] = 35; }
}
upper_color[i][3] = middle_color[i][3] = lower_color[i][3] =
(GLubyte)(l->sky_color[3] * 255);
for ( j = 0; j < 3; j++ ) {
outer_amt[j] += outer_diff[j];
middle_amt[j] += middle_diff[j];
}
/*
printf("upper_color[%d] = %.2f %.2f %.2f %.2f\n", i, upper_color[i][0],
upper_color[i][1], upper_color[i][2], upper_color[i][3]);
printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i,
middle_color[i][0], middle_color[i][1], middle_color[i][2],
middle_color[i][3]);
printf("lower_color[%d] = %.2f %.2f %.2f %.2f\n", i,
lower_color[i][0], lower_color[i][1], lower_color[i][2],
lower_color[i][3]);
*/
}
}
// Initialize the sky structure and colors
void fgSkyInit() {
FG_LOG( FG_ASTRO, FG_INFO, "Initializing the sky" );
fgSkyVerticesInit();
// regester fgSkyColorsInit() as an event to be run periodically
global_events.Register( "fgSkyColorsInit()", fgSkyColorsInit,
fgEVENT::FG_EVENT_READY, 30000);
}
// Draw the Sky
void fgSkyRender() {
FGInterface *f;
fgLIGHT *l;
GLubyte sky_color[4];
GLubyte upper_color[4];
GLubyte middle_color[4];
GLubyte lower_color[4];
double diff;
int i;
f = current_aircraft.fdm_state;
l = &cur_light_params;
// printf("Rendering the sky.\n");
// calculate the proper colors
for ( i = 0; i < 3; i++ ) {
diff = l->sky_color[i] - l->adj_fog_color[i];
// printf("sky = %.2f fog = %.2f diff = %.2f\n",
// l->sky_color[j], l->adj_fog_color[j], diff);
upper_color[i] = (GLubyte)((l->sky_color[i] - diff * 0.3) * 255);
middle_color[i] = (GLubyte)((l->sky_color[i] - diff * 0.9) * 255);
lower_color[i] = (GLubyte)(l->adj_fog_color[i] * 255);
}
upper_color[3] = middle_color[3] = lower_color[3] =
(GLubyte)(l->adj_fog_color[3] * 255);
xglPushMatrix();
// Translate to view position
Point3D zero_elev = current_view.get_cur_zero_elev();
xglTranslatef( zero_elev.x(), zero_elev.y(), zero_elev.z() );
// printf(" Translated to %.2f %.2f %.2f\n",
// zero_elev.x, zero_elev.y, zero_elev.z );
// Rotate to proper orientation
// printf(" lon = %.2f lat = %.2f\n", FG_Longitude * RAD_TO_DEG,
// FG_Latitude * RAD_TO_DEG);
xglRotatef( f->get_Longitude() * RAD_TO_DEG, 0.0, 0.0, 1.0 );
xglRotatef( 90.0 - f->get_Latitude() * RAD_TO_DEG, 0.0, 1.0, 0.0 );
xglRotatef( l->sun_rotation * RAD_TO_DEG, 0.0, 0.0, 1.0 );
// Draw inner/center section of sky*/
xglBegin( GL_TRIANGLE_FAN );
for ( i = 0; i < 4; i++ ) {
sky_color[i] = (GLubyte)(l->sky_color[i] * 255);
}
xglColor4fv(l->sky_color);
xglVertex3f(0.0, 0.0, CENTER_ELEV);
for ( i = 11; i >= 0; i-- ) {
xglColor4ubv( upper_color );
xglVertex3fv( inner_vertex[i] );
}
xglColor4ubv( upper_color );
xglVertex3fv( inner_vertex[11] );
xglEnd();
// Draw the middle ring
xglBegin( GL_TRIANGLE_STRIP );
for ( i = 0; i < 12; i++ ) {
xglColor4ubv( middle_color );
// printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i,
// middle_color[i][0], middle_color[i][1], middle_color[i][2],
// middle_color[i][3]);
// xglColor4f(1.0, 0.0, 0.0, 1.0);
xglVertex3fv( middle_vertex[i] );
xglColor4ubv( upper_color );
// printf("upper_color[%d] = %.2f %.2f %.2f %.2f\n", i,
// upper_color[i][0], upper_color[i][1], upper_color[i][2],
// upper_color[i][3]);
// xglColor4f(0.0, 0.0, 1.0, 1.0);
xglVertex3fv( inner_vertex[i] );
}
xglColor4ubv( middle_color );
// xglColor4f(1.0, 0.0, 0.0, 1.0);
xglVertex3fv( middle_vertex[0] );
xglColor4ubv( upper_color );
// xglColor4f(0.0, 0.0, 1.0, 1.0);
xglVertex3fv( inner_vertex[0] );
xglEnd();
// Draw the outer ring
xglBegin( GL_TRIANGLE_STRIP );
for ( i = 0; i < 12; i++ ) {
xglColor4ubv( lower_color );
xglVertex3fv( outer_vertex[i] );
xglColor4ubv( middle_color );
xglVertex3fv( middle_vertex[i] );
}
xglColor4ubv( lower_color );
xglVertex3fv( outer_vertex[0] );
xglColor4ubv( middle_color );
xglVertex3fv( middle_vertex[0] );
xglEnd();
// Draw the bottom skirt
xglBegin( GL_TRIANGLE_STRIP );
xglColor4ubv( lower_color );
for ( i = 0; i < 12; i++ ) {
xglVertex3fv( bottom_vertex[i] );
xglVertex3fv( outer_vertex[i] );
}
xglVertex3fv( bottom_vertex[0] );
xglVertex3fv( outer_vertex[0] );
xglEnd();
xglPopMatrix();
}
#endif

View File

@ -1,4 +1,4 @@
// skydome.hxx -- model sky with an upside down "bowl"
// dome.hxx -- model sky with an upside down "bowl"
//
// Written by Curtis Olson, started December 1997.
// SSG-ified by Curtis Olson, February 2000.
@ -34,11 +34,7 @@
#include <plib/ssg.h> // plib include
class FGSkyDome {
// scene graph root for the skydome
ssgRoot *dome;
ssgSelector *dome_selector;
class SGSkyDome {
ssgTransform *dome_transform;
ssgSimpleState *dome_state;
@ -57,14 +53,14 @@ class FGSkyDome {
public:
// Constructor
FGSkyDome( void );
SGSkyDome( void );
// Destructor
~FGSkyDome( void );
~SGSkyDome( void );
// initialize the sky object and connect it into our scene graph
// root
bool initialize();
ssgBranch *build();
// repaint the sky colors based on current value of sun_angle,
// sky, and fog colors. This updates the color arrays for
@ -81,31 +77,7 @@ public:
// spin specifies a rotation about the new Z axis (and orients the
// sunrise/set effects
bool reposition( sgVec3 p, double lon, double lat, double spin );
// Draw the skydome
bool draw();
// enable the sky in the scene graph (default)
void enable() { dome_selector->select( 1 ); }
// disable the sky in the scene graph. The leaf node is still
// there, how ever it won't be traversed on the cullandrender
// phase.
void disable() { dome_selector->select( 0 ); }
};
// (Re)generate the display list
// void fgSkyInit();
// (Re)calculate the sky colors at each vertex
// void fgSkyColorsInit();
// Draw the Sky
// void fgSkyRender();
#endif // _SKYDOM_HXX
#endif // _SKYDOME_HXX

View File

@ -1,4 +1,4 @@
// skymoon.hxx -- draw a moon object
// moon.hxx -- model earth's moon
//
// Written by Durk Talsma. Originally started October 1997, for distribution
// with the FlightGear project. Version 2 was written in August and
@ -30,43 +30,81 @@
#include <plib/ssg.h>
#include <simgear/constants.h>
#include <simgear/misc/fgpath.hxx>
#include "sphere.hxx"
#include "skymoon.hxx"
#include "moon.hxx"
// Set up moon rendering call backs
static int sgMoonOrbPreDraw( ssgEntity *e ) {
/* cout << endl << "Moon orb pre draw" << endl << "----------------"
<< endl << endl; */
glDisable( GL_DEPTH_TEST );
glDisable( GL_FOG );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE ) ;
// sgVec4 color;
// sgSetVec4( color, 0.0, 0.0, 0.0, 1.0 );
// glMaterialfv ( GL_FRONT_AND_BACK, GL_AMBIENT, color ) ;
return true;
}
static int sgMoonOrbPostDraw( ssgEntity *e ) {
/* cout << endl << "Moon orb post draw" << endl << "----------------"
<< endl << endl; */
glEnable( GL_DEPTH_TEST );
glEnable( GL_FOG );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
return true;
}
static int sgMoonHaloPreDraw( ssgEntity *e ) {
/* cout << endl << "Moon halo pre draw" << endl << "----------------"
<< endl << endl; */
glDisable( GL_DEPTH_TEST );
glDisable( GL_FOG );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
return true;
}
static int sgMoonHaloPostDraw( ssgEntity *e ) {
/* cout << endl << "Moon halo post draw" << endl << "----------------"
<< endl << endl; */
glEnable( GL_DEPTH_TEST );
glEnable( GL_FOG );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
return true;
}
// Constructor
FGSkyMoon::FGSkyMoon( void ) {
SGMoon::SGMoon( void ) {
}
// Destructor
FGSkyMoon::~FGSkyMoon( void ) {
SGMoon::~SGMoon( void ) {
}
// initialize the moon object and connect it into our scene graph root
bool FGSkyMoon::initialize( const FGPath& path ) {
// create the scene graph for the moon/halo
FGPath moontex = path;
moontex.append( "moon.rgba" );
skymoon = new ssgRoot;
skymoon->setName( "Sky Moon" );
// build the moon object
ssgBranch * SGMoon::build( FGPath path, double moon_size ) {
// set up the orb state
path.append( "moon.rgba" );
orb_state = new ssgSimpleState();
orb_state->setTexture( (char *)moontex.c_str() );
orb_state->setTexture( (char *)path.c_str() );
orb_state->setShadeModel( GL_SMOOTH );
orb_state->enable( GL_LIGHTING );
orb_state->enable( GL_CULL_FACE );
orb_state->enable( GL_TEXTURE_2D );
orb_state->enable( GL_COLOR_MATERIAL );
orb_state->setColourMaterial( GL_DIFFUSE );
orb_state->setMaterial( GL_AMBIENT, 0.0, 0.0, 0.0, 0.0 );
orb_state->setMaterial( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
orb_state->setMaterial( GL_AMBIENT, 0.0, 0.0, 0.0, 1.0 );
orb_state->setMaterial( GL_SPECULAR, 0.0, 0.0, 0.0, 1.0 );
orb_state->enable( GL_BLEND );
orb_state->enable( GL_ALPHA_TEST );
orb_state->setAlphaClamp( 0.01 );
@ -76,7 +114,8 @@ bool FGSkyMoon::initialize( const FGPath& path ) {
sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
cl->add( color );
ssgBranch *orb = ssgMakeSphere( orb_state, cl, 550.0, 15, 15 );
ssgBranch *orb = ssgMakeSphere( orb_state, cl, moon_size, 15, 15,
sgMoonOrbPreDraw, sgMoonOrbPostDraw );
// force a repaint of the moon colors with arbitrary defaults
repaint( 0.0 );
@ -86,9 +125,10 @@ bool FGSkyMoon::initialize( const FGPath& path ) {
// moon_texid = makeHalo( moon_texbuf, 64 );
// my_glWritePPMFile("moonhalo.ppm", moon_texbuf, 64, 64, RGB);
#if 0
// set up the halo state
halo_state = new ssgSimpleState();
halo_state->setTexture( "halo.rgba" );
halo_state->setTexture( "halo.rgb" );
// halo_state->setTexture( moon_texid );
halo_state->enable( GL_TEXTURE_2D );
halo_state->disable( GL_LIGHTING );
@ -101,23 +141,22 @@ bool FGSkyMoon::initialize( const FGPath& path ) {
halo_state -> setMaterial ( GL_EMISSION, 0, 0, 0, 1 ) ;
halo_state -> setMaterial ( GL_SPECULAR, 0, 0, 0, 1 ) ;
// halo_state -> setShininess ( 0 ) ;
halo_state->setTranslucent();
halo_state->enable( GL_ALPHA_TEST );
halo_state->setAlphaClamp(0.01);
halo_state->enable ( GL_BLEND ) ;
// Build ssg structure
double size = moon_size * 10.0;
sgVec3 v3;
halo_vl = new ssgVertexArray;
sgSetVec3( v3, -5000.0, 0.0, -5000.0 );
sgSetVec3( v3, -size, 0.0, -size );
halo_vl->add( v3 );
sgSetVec3( v3, 5000.0, 0.0, -5000.0 );
sgSetVec3( v3, size, 0.0, -size );
halo_vl->add( v3 );
sgSetVec3( v3, -5000.0, 0.0, 5000.0 );
sgSetVec3( v3, -size, 0.0, size );
halo_vl->add( v3 );
sgSetVec3( v3, 5000.0, 0.0, 5000.0 );
sgSetVec3( v3, size, 0.0, size );
halo_vl->add( v3 );
sgVec2 v2;
@ -134,21 +173,16 @@ bool FGSkyMoon::initialize( const FGPath& path ) {
ssgLeaf *halo =
new ssgVtxTable ( GL_TRIANGLE_STRIP, halo_vl, NULL, halo_tl, cl );
halo->setState( halo_state );
#endif
// build the ssg scene graph sub tree for the sky and connected
// into the provide scene graph branch
moon_selector = new ssgSelector;
moon_transform = new ssgTransform;
moon_selector->addKid( moon_transform );
moon_selector->clrTraversalMaskBits( SSGTRAV_HOT );
skymoon->addKid( moon_selector );
// moon_transform->addKid( halo );
moon_transform->addKid( orb );
return true;
return moon_transform;
}
@ -157,7 +191,7 @@ bool FGSkyMoon::initialize( const FGPath& path ) {
// 0 degrees = high noon
// 90 degrees = moon rise/set
// 180 degrees = darkest midnight
bool FGSkyMoon::repaint( double moon_angle ) {
bool SGMoon::repaint( double moon_angle ) {
if ( moon_angle * RAD_TO_DEG < 100 ) {
// else moon is well below horizon (so no point in repainting it)
@ -197,8 +231,9 @@ bool FGSkyMoon::repaint( double moon_angle ) {
// declination, offset by our current position (p) so that it appears
// fixed at a great distance from the viewer. Also add in an optional
// rotation (i.e. for the current time of day.)
bool FGSkyMoon::reposition( sgVec3 p, double angle,
double rightAscension, double declination )
bool SGMoon::reposition( sgVec3 p, double angle,
double rightAscension, double declination,
double moon_dist )
{
sgMat4 T1, T2, GST, RA, DEC;
sgVec3 axis;
@ -235,11 +270,3 @@ bool FGSkyMoon::reposition( sgVec3 p, double angle,
return true;
}
// Draw the moon
bool FGSkyMoon::draw() {
ssgCullAndDraw( skymoon );
return true;
}

View File

@ -1,4 +1,4 @@
// skymoon.hxx -- draw a moon object
// moon.hxx -- model earth's moon
//
// Written by Durk Talsma. Originally started October 1997, for distribution
// with the FlightGear project. Version 2 was written in August and
@ -25,20 +25,17 @@
// $Id$
#ifndef _SKYMOON_HXX_
#define _SKYMOON_HXX_
#ifndef _SG_MOON_HXX_
#define _SG_MOON_HXX_
#include <plib/ssg.h>
#include <simgear/misc/fgpath.hxx>
class FGSkyMoon {
class SGMoon {
// scene graph root for the skymoon
ssgRoot *skymoon;
ssgSelector *moon_selector;
ssgTransform *moon_transform;
ssgSimpleState *orb_state;
ssgSimpleState *halo_state;
@ -48,20 +45,16 @@ class FGSkyMoon {
ssgVertexArray *halo_vl;
ssgTexCoordArray *halo_tl;
GLuint moon_texid;
GLubyte *moon_texbuf;
public:
// Constructor
FGSkyMoon( void );
SGMoon( void );
// Destructor
~FGSkyMoon( void );
~SGMoon( void );
// initialize the moon object and connect it into our scene graph
// root
bool initialize( const FGPath& path );
// build the moon object
ssgBranch *build( FGPath path, double moon_size );
// repaint the moon colors based on current value of moon_anglein
// degrees relative to verticle
@ -75,34 +68,9 @@ public:
// appears fixed at a great distance from the viewer. Also add in
// an optional rotation (i.e. for the current time of day.)
bool reposition( sgVec3 p, double angle,
double rightAscension, double declination );
// Draw the moon
bool draw();
// enable the moon in the scene graph (default)
void enable() { moon_selector->select( 1 ); }
// disable the moon in the scene graph. The leaf node is still
// there, how ever it won't be traversed on the cullandrender
// phase.
void disable() { moon_selector->select( 0 ); }
double rightAscension, double declination,
double moon_dist );
};
#endif // _SKYMOON_HXX_
#endif // _SG_MOON_HXX_

View File

@ -1,4 +1,4 @@
// skysun.hxx -- draw a sun object
// oursun.hxx -- model earth's sun
//
// Written by Durk Talsma. Originally started October 1997, for distribution
// with the FlightGear project. Version 2 was written in August and
@ -30,19 +30,57 @@
#include <plib/ssg.h>
#include <simgear/constants.h>
#include <simgear/misc/fgpath.hxx>
#include "sphere.hxx"
#include "skysun.hxx"
#include "oursun.hxx"
// Set up sun rendering call backs
static int sgSunOrbPreDraw( ssgEntity *e ) {
/* cout << endl << "Sun orb pre draw" << endl << "----------------"
<< endl << endl; */
glDisable( GL_DEPTH_TEST );
glDisable( GL_FOG );
return true;
}
static int sgSunOrbPostDraw( ssgEntity *e ) {
/* cout << endl << "Sun orb post draw" << endl << "----------------"
<< endl << endl; */
glEnable( GL_DEPTH_TEST );
glEnable( GL_FOG );
return true;
}
static int sgSunHaloPreDraw( ssgEntity *e ) {
/* cout << endl << "Sun halo pre draw" << endl << "----------------"
<< endl << endl; */
glDisable( GL_DEPTH_TEST );
glDisable( GL_FOG );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
return true;
}
static int sgSunHaloPostDraw( ssgEntity *e ) {
/* cout << endl << "Sun halo post draw" << endl << "----------------"
<< endl << endl; */
glEnable( GL_DEPTH_TEST );
glEnable( GL_FOG );
return true;
}
// Constructor
FGSkySun::FGSkySun( void ) {
SGSun::SGSun( void ) {
}
// Destructor
FGSkySun::~FGSkySun( void ) {
SGSun::~SGSun( void ) {
}
@ -156,10 +194,7 @@ void my_glWritePPMFile(const char *filename, GLubyte *buffer, int win_width, int
// initialize the sun object and connect it into our scene graph root
bool FGSkySun::initialize( const FGPath& path ) {
// create the scene graph for the sun/halo
skysun = new ssgRoot;
skysun->setName( "Sky Sun" );
ssgBranch * SGSun::build( FGPath path, double sun_size ) {
// set up the orb state
orb_state = new ssgSimpleState();
@ -177,7 +212,8 @@ bool FGSkySun::initialize( const FGPath& path ) {
sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
cl->add( color );
ssgBranch *orb = ssgMakeSphere( orb_state, cl, 550.0, 10, 10 );
ssgBranch *orb = ssgMakeSphere( orb_state, cl, sun_size, 10, 10,
sgSunOrbPreDraw, sgSunOrbPostDraw );
// force a repaint of the sun colors with arbitrary defaults
repaint( 0.0 );
@ -188,40 +224,31 @@ bool FGSkySun::initialize( const FGPath& path ) {
// my_glWritePPMFile("sunhalo.ppm", sun_texbuf, 64, 64, RGB);
// set up the halo state
FGPath halo_path = path;
halo_path.append( "halo.rgba" );
path.append( "halo.rgba" );
halo_state = new ssgSimpleState();
halo_state->setTexture( (char *)halo_path.c_str() );
halo_state->setTexture( (char *)path.c_str() );
// halo_state->setTexture( sun_texid );
halo_state->enable( GL_TEXTURE_2D );
halo_state->disable( GL_LIGHTING );
halo_state->setShadeModel( GL_SMOOTH );
halo_state->disable( GL_CULL_FACE );
halo_state->disable( GL_COLOR_MATERIAL );
halo_state->enable( GL_COLOR_MATERIAL );
halo_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
halo_state->setMaterial ( GL_AMBIENT_AND_DIFFUSE, 1, 1, 1, 1 ) ;
halo_state -> setMaterial ( GL_EMISSION, 0, 0, 0, 1 ) ;
halo_state -> setMaterial ( GL_SPECULAR, 0, 0, 0, 1 ) ;
// halo_state -> setShininess ( 0 ) ;
halo_state->setTranslucent();
halo_state->enable( GL_ALPHA_TEST );
halo_state->setAlphaClamp(0.01);
halo_state->enable ( GL_BLEND ) ;
// Build ssg structure
double size = sun_size * 10.0;
sgVec3 v3;
halo_vl = new ssgVertexArray;
sgSetVec3( v3, -5000.0, 0.0, -5000.0 );
sgSetVec3( v3, -size, 0.0, -size );
halo_vl->add( v3 );
sgSetVec3( v3, 5000.0, 0.0, -5000.0 );
sgSetVec3( v3, size, 0.0, -size );
halo_vl->add( v3 );
sgSetVec3( v3, -5000.0, 0.0, 5000.0 );
sgSetVec3( v3, -size, 0.0, size );
halo_vl->add( v3 );
sgSetVec3( v3, 5000.0, 0.0, 5000.0 );
sgSetVec3( v3, size, 0.0, size );
halo_vl->add( v3 );
sgVec2 v2;
@ -241,18 +268,14 @@ bool FGSkySun::initialize( const FGPath& path ) {
// build the ssg scene graph sub tree for the sky and connected
// into the provide scene graph branch
sun_selector = new ssgSelector;
sun_transform = new ssgTransform;
sun_selector->addKid( sun_transform );
sun_selector->clrTraversalMaskBits( SSGTRAV_HOT );
skysun->addKid( sun_selector );
sun_transform->addKid( halo );
halo->setCallback( SSG_CALLBACK_PREDRAW, sgSunHaloPreDraw );
halo->setCallback( SSG_CALLBACK_POSTDRAW, sgSunHaloPostDraw );
sun_transform->addKid( orb );
return true;
return sun_transform;
}
@ -261,7 +284,7 @@ bool FGSkySun::initialize( const FGPath& path ) {
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool FGSkySun::repaint( double sun_angle ) {
bool SGSun::repaint( double sun_angle ) {
if ( sun_angle * RAD_TO_DEG < 100 ) {
// else sun is well below horizon (so no point in repainting it)
@ -300,8 +323,9 @@ bool FGSkySun::repaint( double sun_angle ) {
// declination, offset by our current position (p) so that it appears
// fixed at a great distance from the viewer. Also add in an optional
// rotation (i.e. for the current time of day.)
bool FGSkySun::reposition( sgVec3 p, double angle,
double rightAscension, double declination )
bool SGSun::reposition( sgVec3 p, double angle,
double rightAscension, double declination,
double sun_dist )
{
sgMat4 T1, T2, GST, RA, DEC;
sgVec3 axis;
@ -338,11 +362,3 @@ bool FGSkySun::reposition( sgVec3 p, double angle,
return true;
}
// Draw the sun
bool FGSkySun::draw() {
ssgCullAndDraw( skysun );
return true;
}

View File

@ -1,4 +1,4 @@
// skysun.hxx -- draw a sun object
// oursun.hxx -- model earth's sun
//
// Written by Durk Talsma. Originally started October 1997, for distribution
// with the FlightGear project. Version 2 was written in August and
@ -25,19 +25,17 @@
// $Id$
#ifndef _SKYSUN_HXX_
#define _SKYSUN_HXX_
#ifndef _SG_SUN_HXX_
#define _SG_SUN_HXX_
#include <plib/ssg.h>
#include <simgear/misc/fgpath.hxx>
class FGSkySun {
// scene graph root for the skysun
ssgRoot *skysun;
class SGSun {
ssgSelector *sun_selector;
ssgTransform *sun_transform;
ssgSimpleState *orb_state;
ssgSimpleState *halo_state;
@ -53,15 +51,13 @@ class FGSkySun {
public:
// Constructor
FGSkySun( void );
SGSun( void );
// Destructor
~FGSkySun( void );
~SGSun( void );
// initialize the sun object and connect it into our scene graph
// root. Pass in the path to your texture directory so
// initialize() can find the halo.rgba texture
bool initialize( const FGPath& path );
// return the sun object
ssgBranch *build( FGPath path, double sun_size );
// repaint the sun colors based on current value of sun_anglein
// degrees relative to verticle
@ -75,89 +71,9 @@ public:
// appears fixed at a great distance from the viewer. Also add in
// an optional rotation (i.e. for the current time of day.)
bool reposition( sgVec3 p, double angle,
double rightAscension, double declination );
// Draw the sun
bool draw();
// enable the sun in the scene graph (default)
void enable() { sun_selector->select( 1 ); }
// disable the sun in the scene graph. The leaf node is still
// there, how ever it won't be traversed on the cullandrender
// phase.
void disable() { sun_selector->select( 0 ); }
double rightAscension, double declination,
double sun_dist );
};
#if 0
class Star : public CelestialBody
{
private:
//double longitude; // the sun's true longitude - this is depreciated by
// CelestialBody::lonEcl
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:
Star (FGTime *t);
~Star();
void updatePosition(FGTime *t);
double getM();
double getw();
//double getLon();
double getxs();
double getys();
double getDistance();
void newImage();
};
inline double Star::getM()
{
return M;
}
inline double Star::getw()
{
return w;
}
inline double Star::getxs()
{
return xs;
}
inline double Star::getys()
{
return ys;
}
inline double Star::getDistance()
{
return distance;
}
#endif
#endif // _SKYSUN_HXX_
#endif // _SG_SUN_HXX_

117
simgear/sky/sky.cxx Normal file
View File

@ -0,0 +1,117 @@
// sky.cxx -- ssg based sky model
//
// Written by Curtis Olson, started December 1997.
// SSG-ified by Curtis Olson, February 2000.
//
// Copyright (C) 1997-2000 Curtis L. Olson - curt@flightgear.org
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// $Id$
#include <plib/ssg.h> // plib include
#include "sky.hxx"
// Constructor
SGSky::SGSky( void ) {
}
// Destructor
SGSky::~SGSky( void ) {
}
// initialize the sky and connect the components to the scene graph at
// the provided branch
ssgBranch * SGSky::build( double sun_size, double moon_size,
int nplanets, sgdVec3 *planet_data,
double planet_dist,
int nstars, sgdVec3 *star_data, double star_dist )
{
sky_selector = new ssgSelector;
sky_transform = new ssgTransform;
dome = new SGSkyDome;
sky_transform -> addKid( dome->build() );
planets = new SGStars;
sky_transform -> addKid( planets->build(nplanets, planet_data,
planet_dist)
);
stars = new SGStars;
sky_transform -> addKid( stars->build(nstars, star_data, star_dist) );
moon = new SGMoon;
sky_transform -> addKid( moon->build(tex_path, moon_size) );
oursun = new SGSun;
sky_transform -> addKid( oursun->build(tex_path, sun_size) );
sky_selector->addKid( sky_transform );
sky_selector->clrTraversalMaskBits( SSGTRAV_HOT );
return sky_selector;
}
// repaint the sky components based on current value of sun_angle,
// sky, and fog colors.
//
// sun angle in degrees relative to verticle
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool SGSky::repaint( sgVec4 sky_color, sgVec4 fog_color,
double sun_angle, double moon_angle,
int nplanets, sgdVec3 *planet_data,
int nstars, sgdVec3 *star_data )
{
dome->repaint( sky_color, fog_color, sun_angle );
oursun->repaint( sun_angle );
moon->repaint( moon_angle );
planets->repaint( sun_angle, nplanets, planet_data );
stars->repaint( sun_angle, nstars, star_data );
return true;
}
// reposition the sky at the specified origin and orientation
//
// lon specifies a rotation about the Z axis
// lat specifies a rotation about the new Y axis
// spin specifies a rotation about the new Z axis (this allows
// additional orientation for the sunrise/set effects and is used by
// the skydome and perhaps clouds.
bool SGSky::reposition( sgVec3 view_pos, sgVec3 zero_elev,
double lon, double lat, double spin,
double gst,
double sun_ra, double sun_dec, double sun_dist,
double moon_ra, double moon_dec, double moon_dist )
{
double angle = gst * 15; // degrees
dome->reposition( zero_elev, lon, lat, spin );
oursun->reposition( view_pos, angle, sun_ra, sun_dec, sun_dist );
moon->reposition( view_pos, angle, moon_ra, moon_dec, moon_dist );
planets->reposition( view_pos, angle );
stars->reposition( view_pos, angle );
return true;
}

113
simgear/sky/sky.hxx Normal file
View File

@ -0,0 +1,113 @@
// sky.hxx -- ssg based sky model
//
// Written by Curtis Olson, started December 1997.
// SSG-ified by Curtis Olson, February 2000.
//
// Copyright (C) 1997-2000 Curtis L. Olson - curt@flightgear.org
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// $Id$
#ifndef _SG_SKY_HXX
#define _SG_SKY_HXX
#ifndef __cplusplus
# error This library requires C++
#endif
#include <plib/ssg.h> // plib include
#include <simgear/misc/fgpath.hxx>
#include "dome.hxx"
#include "moon.hxx"
#include "oursun.hxx"
#include "stars.hxx"
class SGSky {
// components of the sky
SGSkyDome *dome;
SGSun *oursun;
SGMoon *moon;
SGStars *planets;
SGStars *stars;
ssgSelector *sky_selector;
ssgTransform *sky_transform;
FGPath tex_path;
public:
// Constructor
SGSky( void );
// Destructor
~SGSky( void );
// initialize the sky and connect the components to the scene
// graph at the provided branch
ssgBranch *build( double sun_size, double moon_size,
int nplanets, sgdVec3 *planet_data, double planet_dist,
int nstars, sgdVec3 *star_data, double star_dist );
// repaint the sky components based on current value of sun_angle,
// sky, and fog colors.
//
// sun angle in degrees relative to verticle
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool repaint( sgVec4 sky_color, sgVec4 fog_color,
double sun_angle, double moon_angle,
int nplanets, sgdVec3 *planet_data,
int nstars, sgdVec3 *star_data );
// reposition the sky at the specified origin and orientation
//
// lon specifies a rotation about the Z axis
// lat specifies a rotation about the new Y axis
// spin specifies a rotation about the new Z axis (this allows
// additional orientation for the sunrise/set effects and is used
// by the skydome and perhaps clouds.
bool reposition( sgVec3 view_pos, sgVec3 zero_elev,
double lon, double lat, double spin,
double gst,
double sun_ra, double sun_dec, double sun_dist,
double moon_ra, double moon_dec, double moon_dist );
// specify the texture path (optional, defaults to current directory)
inline void texture_path( const string& path ) {
tex_path = FGPath( path );
}
// enable the sky in the scene graph (default)
inline void enable() { sky_selector->select( 1 ); }
// disable the sky in the scene graph. The leaf node is still
// there, how ever it won't be traversed on by ssgCullandRender()
inline void disable() { sky_selector->select( 0 ); }
};
#endif // _SG_SKY_HXX

View File

@ -27,7 +27,8 @@
// return a sphere object as an ssgBranch
ssgBranch *ssgMakeSphere( ssgSimpleState *state, ssgColourArray *cl,
double radius, int slices, int stacks )
double radius, int slices, int stacks,
ssgCallback predraw, ssgCallback postdraw )
{
float rho, drho, theta, dtheta;
float x, y, z;
@ -119,6 +120,8 @@ ssgBranch *ssgMakeSphere( ssgSimpleState *state, ssgColourArray *cl,
ssgLeaf *slice =
new ssgVtxTable ( GL_TRIANGLE_STRIP, vl, nl, tl, cl );
slice->setState( state );
slice->setCallback( SSG_CALLBACK_PREDRAW, predraw );
slice->setCallback( SSG_CALLBACK_POSTDRAW, postdraw );
sphere->addKid( slice );

View File

@ -28,6 +28,7 @@
// return a sphere object as an ssgBranch (and connect in the
// specified ssgSimpleState
ssgBranch *ssgMakeSphere( ssgSimpleState *state, ssgColourArray *cl,
double radius, int slices, int stacks );
double radius, int slices, int stacks,
ssgCallback predraw, ssgCallback postdraw );

177
simgear/sky/stars.cxx Normal file
View File

@ -0,0 +1,177 @@
// stars.cxx -- model the stars
//
// Written by Durk Talsma. Originally started October 1997, for distribution
// with the FlightGear project. Version 2 was written in August and
// September 1998. This code is based upon algorithms and data kindly
// provided by Mr. Paul Schlyter. (pausch@saaf.se).
//
// Separated out rendering pieces and converted to ssg by Curt Olson,
// March 2000
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// $Id$
#include <stdio.h>
#include <iostream>
#include <plib/ssg.h>
#include <simgear/constants.h>
#include "stars.hxx"
// Set up star rendering call backs
static int sgStarPreDraw( ssgEntity *e ) {
/* cout << endl << "Star pre draw" << endl << "----------------"
<< endl << endl; */
glDisable( GL_DEPTH_TEST );
glDisable( GL_FOG );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
return true;
}
static int sgStarPostDraw( ssgEntity *e ) {
/* cout << endl << "Star post draw" << endl << "----------------"
<< endl << endl; */
glEnable( GL_DEPTH_TEST );
glEnable( GL_FOG );
return true;
}
// Constructor
SGStars::SGStars( void ) {
}
// Destructor
SGStars::~SGStars( void ) {
}
// initialize the stars object and connect it into our scene graph root
ssgBranch * SGStars::build( int num, sgdVec3 *star_data, double star_dist ) {
sgVec4 color;
if ( star_data == NULL ) {
cout << "WARNING: null star data passed to SGStars::build()" << endl;
}
// set up the orb state
state = new ssgSimpleState();
state->disable( GL_LIGHTING );
state->disable( GL_CULL_FACE );
state->disable( GL_TEXTURE_2D );
state->enable( GL_COLOR_MATERIAL );
state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
state->enable( GL_BLEND );
state->disable( GL_ALPHA_TEST );
vl = new ssgVertexArray( num );
cl = new ssgColourArray( num );
// cl = new ssgColourArray( 1 );
// sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
// cl->add( color );
// Build ssg structure
sgVec3 p;
for ( int i = 0; i < num; ++i ) {
// position seeded to arbitrary values
sgSetVec3( p,
star_dist * cos( star_data[i][0] )
* cos( star_data[i][1] ),
star_dist * sin( star_data[i][0] )
* cos( star_data[i][1] ),
star_dist * sin( star_data[i][1] )
);
vl->add( p );
// color (magnitude)
sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
cl->add( color );
}
ssgLeaf *stars_obj =
new ssgVtxTable ( GL_POINTS, vl, NULL, NULL, cl );
stars_obj->setState( state );
stars_obj->setCallback( SSG_CALLBACK_PREDRAW, sgStarPreDraw );
stars_obj->setCallback( SSG_CALLBACK_POSTDRAW, sgStarPostDraw );
// build the ssg scene graph sub tree for the sky and connected
// into the provide scene graph branch
stars_transform = new ssgTransform;
stars_transform->addKid( stars_obj );
cout << "stars = " << stars_transform << endl;
return stars_transform;
}
// repaint the sun colors based on current value of sun_angle in
// degrees relative to verticle
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool SGStars::repaint( double sun_angle, int num, sgdVec3 *star_data ) {
// TEST return true;
float *color;
for ( int i = 0; i < num; ++i ) {
// color (magnitude)
double magnitude = (0.0 - star_data[i][2]) / 5.0 + 1.0;
magnitude = magnitude * 0.7 + (3 * 0.1);
if (magnitude > 1.0) magnitude = 1.0;
if (magnitude < 0.0) magnitude = 0.0;
color = cl->get( i );
sgSetVec4( color, 1.0, 1.0, 1.0, magnitude );
// sgSetVec4( color, 1, 1, 1, 1.0 );
// cout << "color[" << i << "] = " << magnitude << endl;
}
return true;
}
// reposition the stars for the specified time (GST rotation),
// offset by our current position (p) so that it appears fixed at a
// great distance from the viewer.
bool SGStars::reposition( sgVec3 p, double angle )
{
sgMat4 T1, GST;
sgVec3 axis;
sgMakeTransMat4( T1, p );
sgSetVec3( axis, 0.0, 0.0, -1.0 );
sgMakeRotMat4( GST, angle, axis );
sgMat4 TRANSFORM;
sgCopyMat4( TRANSFORM, T1 );
sgPreMultMat4( TRANSFORM, GST );
sgCoord skypos;
sgSetCoord( &skypos, TRANSFORM );
stars_transform->setTransform( &skypos );
return true;
}

69
simgear/sky/stars.hxx Normal file
View File

@ -0,0 +1,69 @@
// stars.hxx -- model the stars
//
// Written by Durk Talsma. Originally started October 1997, for distribution
// with the FlightGear project. Version 2 was written in August and
// September 1998. This code is based upon algorithms and data kindly
// provided by Mr. Paul Schlyter. (pausch@saaf.se).
//
// Separated out rendering pieces and converted to ssg by Curt Olson,
// March 2000
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// $Id$
#ifndef _SG_STARS_HXX_
#define _SG_STARS_HXX_
#include <plib/ssg.h>
class SGStars {
ssgTransform *stars_transform;
ssgSimpleState *state;
ssgColourArray *cl;
ssgVertexArray *vl;
public:
// Constructor
SGStars( void );
// Destructor
~SGStars( void );
// initialize the stars structure
ssgBranch *build( int num, sgdVec3 *star_data, double star_dist );
// repaint the planet magnitudes based on current value of
// sun_angle in degrees relative to verticle (so we can make them
// relatively dimmer during dawn and dusk
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool repaint( double sun_angle, int num, sgdVec3 *star_data );
// reposition the stars for the specified time (GST rotation),
// offset by our current position (p) so that it appears fixed at
// a great distance from the viewer.
bool reposition( sgVec3 p, double angle );
};
#endif // _SG_STARS_HXX_