- update Sky code

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@4748 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 5c6aca7beb74929c9dc09bea39a4726c9d74dc49
Former-commit-id: a7a7b42d20f30ef32be2dbae0e2bf89af2aeb061
This commit is contained in:
torcs-ng 2012-06-13 22:52:39 +00:00
parent acd9ff59e5
commit ceb957a3e8
5 changed files with 359 additions and 336 deletions

View file

@ -50,38 +50,42 @@ cGrMoon::cGrMoon( void )
// Destructor
cGrMoon::~cGrMoon( void )
{
ssgDeRefDelete( moon_transform );
}
// build the moon object
ssgBranch * cGrMoon::build( const char *moon_path, double moon_size )
ssgBranch * cGrMoon::build( double moon_size )
{
orb_state = new ssgSimpleState();
orb_state->setTexture( moon_path );
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, 1.0 );
orb_state->setMaterial( GL_EMISSION, 0.0, 0.0, 0.0, 1 );
orb_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
orb_state->enable( GL_BLEND );
orb_state->enable( GL_ALPHA_TEST );
orb_state->setAlphaClamp( 0.01 );
ssgDeRefDelete( moon_transform );
moon_transform = new ssgTransform;
moon_transform->ref();
moon_state = new ssgSimpleState();
moon_state->setTexture( "data/textures/moon.rgba" );
moon_state->setShadeModel( GL_SMOOTH );
moon_state->enable( GL_LIGHTING );
moon_state->enable( GL_CULL_FACE );
moon_state->enable( GL_TEXTURE_2D );
moon_state->enable( GL_COLOR_MATERIAL );
moon_state->setColourMaterial( GL_DIFFUSE );
moon_state->setMaterial( GL_AMBIENT, 0, 0, 0, 1.0 );
moon_state->setMaterial( GL_EMISSION, 0.0, 0.0, 0.0, 1 );
moon_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
moon_state->enable( GL_BLEND );
moon_state->enable( GL_ALPHA_TEST );
moon_state->setAlphaClamp( 0.01 );
cl = new ssgColourArray( 1 );
sgVec4 color;
sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
cl->add( color );
ssgBranch *orb = grMakeSphere( orb_state, cl, moon_size, 15, 15,
ssgBranch *moon = grMakeSphere( moon_state, cl, moon_size, 15, 15,
grMoonOrbPreDraw, grMoonOrbPostDraw );
repaint( 0.0 );
moon_transform = new ssgTransform;
moon_transform->addKid( orb );
moon_transform->addKid( moon );
return moon_transform;
}
@ -92,7 +96,7 @@ bool cGrMoon::repaint( double moon_angle )
{
prev_moon_angle = moon_angle;
float moon_factor = 4*cos(moon_angle);
double moon_factor = 4*cos(moon_angle);
if (moon_factor > 1) moon_factor = 1.0;
if (moon_factor < -1) moon_factor = -1.0;
@ -115,7 +119,7 @@ bool cGrMoon::repaint( double moon_angle )
return true;
}
bool cGrMoon::reposition( sgVec3 p, double moonangle, double moonrightAscension, double moondeclination, double moon_dist )
bool cGrMoon::reposition(sgVec3 p, double moonangle, double moonrightAscension, double moondeclination, double moon_dist)
{
sgMat4 T1, T2, GST, RA, DEC;
sgVec3 axis;

View file

@ -63,6 +63,8 @@ cGrSky::~cGrSky( void )
void cGrSky::build( double h_radius, double v_radius,
double sun_size, double sun_dist,
double moon_size, double moon_dist,
int nplanets, sgdVec3 *planet_data,
int nstars, sgdVec3 *star_data )
{
@ -92,6 +94,14 @@ void cGrSky::build( double h_radius, double v_radius,
dome = new cGrSkyDome;
pre_transform -> addKid( dome->build( h_radius, v_radius ) );
sun = new cGrSun;
sun_transform -> addKid( sun->build( sun_size));
sun->setSunDistance( sun_dist );
moon = new cGrMoon;
moon_transform ->addKid( sun->build( moon_size));
moon->setMoonDist(moon_dist);
planets = new cGrStars;
stars_transform -> addKid( planets->build( nplanets, planet_data, h_radius ) );
@ -112,26 +122,6 @@ void cGrSky::build( double h_radius, double v_radius,
post_root->addKid( post_selector );
}
cGrSun*
cGrSky::addSun( const char *sun_path, const char *ihalo_path, const char* ohalo_path, double sun_size, double sun_dist, double humidity, double visibility )
{
cGrSun* sun = new cGrSun;
sun_transform->addKid( sun->build( sun_path, ihalo_path, ohalo_path, sun_size, humidity, visibility ) );
sun->setDistance(sun_dist);
return sun;
}
cGrMoon*
cGrSky::addMoon( const char *moon_path, double moon_size, double moon_dist )
{
cGrMoon* moon = new cGrMoon;
moon_transform->addKid( moon->build( moon_path, moon_size ));
moon->setmoonDist(moon_dist);
return moon;
}
cGrCloudLayer*
cGrSky::addCloud( const char *cloud_tex_path, float span, float elevation, float thickness, float transition )
@ -164,15 +154,15 @@ bool cGrSky::repositionFlat( sgVec3 view_pos, double spin, double dt )
moon->reposition( view_pos, 0 );
// Calc angles for rise/set effects
sun->getPosition ( &pos );
sun->getSunPosition ( &pos );
calc_celestial_angles( pos.xyz, view_pos, angle, rotation );
sun->setAngle( angle );
sun->setRotation( rotation );
sun->setSunAngle( angle );
sun->setSunRotation( rotation );
moon->getPosition(&pos);
moon->getMoonPosition(&pos);
calc_celestial_angles( pos.xyz, view_pos, angle, rotation );
moon->setAngle( angle );
moon->setRotation( rotation );
moon->setMoonAngle( angle );
moon->setMoonRotation( rotation );
for ( i = 0; i < clouds.getNum (); i++ )
{
@ -183,12 +173,12 @@ bool cGrSky::repositionFlat( sgVec3 view_pos, double spin, double dt )
stars->reposition( view_pos, 0 );
/*if ( sol_ref )
{
dome->repositionFlat( view_pos, sol_ref->getRotation() );
}
{*/
dome->repositionFlat( view_pos, sun->getSunRotation() );
/*}
else
{*/
dome->repositionFlat( view_pos, spin );
//dome->repositionFlat( view_pos, spin );
//}
return true;
@ -403,3 +393,4 @@ void cGrSky::modifyVisibility( float alt, float time_factor )
effective_visibility = effvis;
}

View file

@ -20,211 +20,35 @@
#ifndef _GRSKY_H_
#define _GRSKY_H_
#include "plib/sg.h"
#include "plib/ssg.h"
class cGrSun;
class cGrMoon;
typedef struct
{
float *view_pos, *zero_elev, *view_up;
double lon, lat, alt, spin;
double gst;
double sun_ra, sun_dec, sun_dist;
double moon_ra, moon_dec, moon_dist;
double sun_angle;
} cGrSkyState;
typedef struct
{
float *sky_color, *fog_color, *cloud_color;
double sun_angle, moon_angle;
int nplanets, nstars;
sgdVec3 *planet_data, *star_data;
} cGrSkyColor;
class cGrCloudLayer;
class cGrCloudLayerList;
class cGrSun;
class cGrMoon;
class cGrStars;
class cGrSkyDome;
class cGrSky;
class cGrMoon
{
ssgTransform *moon_transform;
ssgSimpleState *orb_state;
ssgSimpleState *halo_state;
ssgColourArray *cl;
ssgVertexArray *halo_vl;
ssgTexCoordArray *halo_tl;
double prev_moon_angle;
double moon_angle;
double moon_rotation;
double moon_size;
double moon_dist;
double moonAscension;
double moondeclination;
public:
// Constructor
cGrMoon( void );
// Destructor
~cGrMoon( void );
// build the moon object
ssgBranch *build( const char* moon_path, double moon_size );
// repaint the moon colors based on current value of moon_anglein
// degrees relative to verticle
// 0 degrees = high noon
// 90 degrees = moon rise/set
// 180 degrees = darkest midnight
//bool repaint(double moon_angle);
/*bool reposition( sgVec3 p, double angle,
double rightAscension, double declination,
double moon_dist );*/
bool reposition(sgVec3 p, double moon_angle)
{
return reposition (p, moon_angle, moonAscension, moondeclination, moon_dist);
}
bool reposition(sgVec3 p, double moon_angle, double moonAscension, double moondeclination, double moon_dist);
bool repaint(double moon_angle);
void getPosition (sgCoord* p)
{
sgMat4 Xform;
moon_transform->getTransform(Xform);
sgSetCoord(p, Xform);
}
void setAngle (double angle) { moon_angle = angle; }
double getAngle () { return moon_angle; }
void setRotation (double rotation) { moon_rotation = rotation; }
double getRotation () { return moon_rotation; }
void setmoonRightAscension ( double ra ) { moonAscension = ra; }
double getRightAscension () { return moonAscension; }
void setmoonDeclination ( double decl ) { moondeclination = decl; }
double getmoonDeclination () { return moondeclination; }
void setmoonDist ( double dist ) { moon_dist = dist; }
double getmoonDist() { return moon_dist; }
};
class cGrSun
{
ssgTransform *sun_transform;
ssgSimpleState *sun_state;
ssgSimpleState *ihalo_state;
ssgSimpleState *ohalo_state;
ssgColourArray *sun_cl;
ssgColourArray *ihalo_cl;
ssgColourArray *ohalo_cl;
ssgVertexArray *sun_vl;
ssgVertexArray *ihalo_vl;
ssgVertexArray *ohalo_vl;
ssgTexCoordArray *sun_tl;
ssgTexCoordArray *ihalo_tl;
ssgTexCoordArray *ohalo_tl;
GLuint sun_texid;
GLubyte *sun_texbuf;
double visibility;
double prev_sun_angle;
double sun_angle;
double sun_rotation;
// used by reposition
double sun_right_ascension;
double sun_declination;
double sun_dist;
double path_distance;
public:
// Constructor
cGrSun( void );
// Destructor
~cGrSun( void );
// return the sun object
ssgBranch *build( const char* sun_path, const char *ihalo_path, const char* ohalo_path, float sun_size, float humidity, float visibility );
// repaint the sun colors based on current value of sun_anglein
// degrees relative to verticle
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool repaint( double sun_angle, double new_visibility );
// reposition the sun at the specified right ascension and
// 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 reposition( sgVec3 p, double angle,
double rightAscension, double declination,
double sun_dist, double lat, double alt_asl, double sun_angle );*/
bool reposition( sgVec3 p, double sun_angle )
{
return reposition ( p, sun_angle, sun_right_ascension, sun_declination, sun_dist );
}
bool reposition( sgVec3 p, double sun_angle, double sun_right_ascension, double sun_declination, double sun_dist );
void getPosition (sgCoord* p)
{
sgMat4 Xform;
sun_transform->getTransform(Xform);
sgSetCoord(p, Xform);
}
void setAngle (double angle)
{
sun_angle = angle;
}
double getAngle ()
{
return sun_angle;
}
void setRotation (double rotation)
{
sun_rotation = rotation;
}
double getRotation ()
{
return sun_rotation;
}
void setRightAscension (double ra)
{
sun_right_ascension = ra;
}
double getRightAscension ()
{
return sun_right_ascension;
}
void setDeclination ( double decl )
{
sun_declination = decl;
}
double getDeclination ()
{
return sun_declination;
}
void setDistance ( double dist )
{
sun_dist = dist;
}
double getDistance ()
{
return sun_dist;
}
// retrun the current color of the sun
inline float *get_color() { return ohalo_cl->get( 0 ); }
double effective_visibility;
};
class cGrCloudLayer
{
@ -311,7 +135,174 @@ public:
delete get (i) ;
ssgSimpleList::removeAll () ;
}
} ;
};
class cGrMoon
{
private:
ssgTransform *moon_transform;
ssgSimpleState *moon_state;
ssgSimpleState *halo_state;
ssgColourArray *cl;
ssgVertexArray *halo_vl;
ssgTexCoordArray *halo_tl;
double prev_moon_angle;
double moon_angle;
double moon_rotation;
double moon_size;
double moon_dist;
double moonAscension;
double moondeclination;
public:
// Constructor
cGrMoon( void );
// Destructor
~cGrMoon( void );
// build the moon object
ssgBranch *build( double moon_size );
// repaint the moon colors based on current value of moon_anglein
// degrees relative to verticle
// 0 degrees = high noon
// 90 degrees = moon rise/set
// 180 degrees = darkest midnight
//bool repaint(double moon_angle);
/*bool reposition( sgVec3 p, double angle,
double rightAscension, double declination,
double moon_dist );*/
bool reposition(sgVec3 p, double moon_angle)
{
return reposition (p, moon_angle, moonAscension, moondeclination, moon_dist);
}
bool reposition(sgVec3 p, double moon_angle, double moonAscension, double moondeclination, double moon_dist);
bool repaint(double moon_angle);
void getMoonPosition (sgCoord* p)
{
sgMat4 Xform;
moon_transform->getTransform(Xform);
sgSetCoord(p, Xform);
}
void setMoonAngle (double angle) { moon_angle = angle; }
double getMoonAngle () { return moon_angle; }
void setMoonRotation (double rotation) { moon_rotation = rotation; }
double getMoonRotation () { return moon_rotation; }
void setMoonRightAscension ( double ra ) { moonAscension = ra; }
double getMoonRightAscension () { return moonAscension; }
void setMoonDeclination ( double decl ) { moondeclination = decl; }
double getMoonDeclination () { return moondeclination; }
void setMoonDist ( double dist ) { moon_dist = dist; }
double getMoonDist() { return moon_dist; }
};
class cGrSun
{
private:
ssgTransform *sun_transform;
ssgSimpleState *sun_state;
ssgSimpleState *ihalo_state;
ssgSimpleState *ohalo_state;
ssgColourArray *sun_cl;
ssgColourArray *ihalo_cl;
ssgColourArray *ohalo_cl;
ssgVertexArray *sun_vl;
ssgVertexArray *ihalo_vl;
ssgVertexArray *ohalo_vl;
ssgTexCoordArray *sun_tl;
ssgTexCoordArray *ihalo_tl;
ssgTexCoordArray *ohalo_tl;
float visibility;
double prev_sun_angle;
double sun_angle;
double sun_rotation;
// used by reposition
double sun_right_ascension;
double sun_declination;
double sun_dist;
double path_distance;
public:
// Constructor
cGrSun( void );
// Destructor
~cGrSun( void );
// return the sun object
ssgBranch *build( double sun_size );
// repaint the sun colors based on current value of sun_anglein
// degrees relative to verticle
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool repaint( double sun_angle, double new_visibility );
// reposition the sun at the specified right ascension and
// 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 reposition( sgVec3 p, double angle,
double rightAscension, double declination,
double sun_dist, double lat, double alt_asl, double sun_angle );*/
bool reposition( sgVec3 p, double sun_angle )
{
return reposition ( p, sun_angle, sun_right_ascension, sun_declination, sun_dist );
}
bool reposition( sgVec3 p, double sun_angle, double sun_right_ascension, double sun_declination, double sun_dist );
void getSunPosition (sgCoord* p)
{
sgMat4 Xform;
sun_transform->getTransform(Xform);
sgSetCoord(p, Xform);
}
void setSunAngle(double angle) { sun_angle = angle; }
double getSunAngle() { return sun_angle; }
void setSunRotation(double rotation) { sun_rotation = rotation; }
double getSunRotation() { return sun_rotation; }
void setSunRightAscension(double ra) { sun_right_ascension = ra; }
double getSunRightAscension() { return sun_right_ascension; }
void setSunDeclination( double decl ) { sun_declination = decl; }
double getSunDeclination() { return sun_declination; }
void setSunDistance( double dist ) { sun_dist = dist; }
double getSunDistance() { return sun_dist; }
// retrun the current color of the sun
inline float *get_color() { return ohalo_cl->get( 0 ); }
double effective_visibility;
};
class cGrStars
@ -376,83 +367,121 @@ public:
class cGrSky
{
private:
// components of the sky
cGrSkyDome *dome;
cGrSun *sun;
cGrMoon *moon;
cGrCloudLayerList clouds;
cGrStars *planets;
cGrStars *stars;
// components of the sky
cGrSkyDome *dome;
cGrSun *sun;
cGrMoon *moon;
cGrCloudLayerList clouds;
cGrStars *planets;
cGrStars *stars;
ssgRoot *pre_root, *post_root;
ssgRoot *pre_root, *post_root;
ssgSelector *pre_selector, *post_selector;
ssgTransform *pre_transform, *post_transform;
ssgTransform *sun_transform, *moon_transform, *stars_transform;
ssgSelector *pre_selector, *post_selector;
ssgTransform *pre_transform, *post_transform;
ssgTransform *sun_transform, *moon_transform, *stars_transform;
// visibility
float visibility;
float effective_visibility;
// visibility
float visibility;
float effective_visibility;
// near cloud visibility state variables
bool in_puff;
double puff_length; // in seconds
double puff_progression; // in seconds
double ramp_up; // in seconds
double ramp_down; // in seconds
// near cloud visibility state variables
bool in_puff;
double puff_length; // in seconds
double puff_progression; // in seconds
double ramp_up; // in seconds
double ramp_down; // in seconds
public:
cGrSky( void );
~cGrSky( void );
cGrSky( void );
~cGrSky( void );
void build( double h_radius, double v_radius,
void build( double h_radius, double v_radius,
double sun_size, double sun_dist,
double moon_size, double moon_dist,
int nplanets, sgdVec3 *planet_data,
int nstars, sgdVec3 *star_data );
cGrSun* addSun( const char *sun_path, const char *ihalo_path, const char* ohalo_path, double sun_size, double sun_dist, double humidity, double visibility );
cGrMoon* addMoon( const char *moon_path, double moon_size, double moon_dist );
cGrCloudLayer* addCloud( const char *cloud_tex_path, float span, float elevation, float thickness, float transition );
cGrCloudLayer* addCloud( ssgSimpleState *cloud_state, float span, float elevation, float thickness, float transition );
cGrCloudLayer* getCloud(int i) { return clouds.get(i); }
int getCloudCount() { return clouds.getNum(); }
cGrCloudLayer* addCloud( const char *cloud_tex_path, float span, float elevation, float thickness, float transition );
cGrCloudLayer* addCloud( ssgSimpleState *cloud_state, float span, float elevation, float thickness, float transition );
cGrCloudLayer* getCloud(int i) { return clouds.get(i); }
int getCloudCount() { return clouds.getNum(); }
bool repositionFlat( sgVec3 view_pos, double spin, double dt );
bool reposition( sgVec3 view_pos, sgVec3 zero_elev, sgVec3 view_up, double lon, double lat, double alt, double spin, double gst, double dt );
bool repositionFlat( sgVec3 view_pos, double spin, double dt );
bool reposition( sgVec3 view_pos, sgVec3 zero_elev, sgVec3 view_up, double lon, double lat, double alt, double spin, double gst, double dt );
bool repaint( sgVec4 sky_color, sgVec4 fog_color, sgVec4 cloud_color, double sol_angle,
bool repaint( sgVec4 sky_color, sgVec4 fog_color, sgVec4 cloud_color, double sol_angle,
int nplanets, sgdVec3 *planet_data,
int nstars, sgdVec3 *star_data );
// modify visibility based on cloud layers, thickness, transition range, and simulated "puffs".
void modifyVisibility( float alt, float time_factor );
// modify visibility based on cloud layers, thickness, transition range, and simulated "puffs".
void modifyVisibility( float alt, float time_factor );
// draw background portions of sky (do this before you draw rest of your scene).
void preDraw();
void setMA(double angle) { moon->setMoonAngle(angle); }
double getMA() { return moon->getMoonAngle(); }
// draw translucent clouds (do this after you've drawn all oapaque elements of your scene).
void postDraw( float alt );
void setMR(double rotation) { moon->setMoonRotation( rotation); }
double getMR() { return moon->getMoonRotation(); }
void setMRA( double ra ) { moon->setMoonRightAscension( ra ); }
double getMRA() { return moon->getMoonRightAscension(); }
// enable the sky
inline void enable() {
pre_selector->select( 1 );
post_selector->select( 1 );
}
void setMD( double decl ) { moon->setMoonDeclination( decl ); }
double getMD() { return moon->getMoonDeclination(); }
// disable the sky
inline void disable() {
pre_selector->select( 0 );
post_selector->select( 0 );
}
void setMDist( double dist ) { moon->setMoonDist(dist); }
double getMDist() { return moon->getMoonDist(); }
// current effective visibility
inline float getVisibility() const { return effective_visibility; }
inline void setVisibility( float v )
{
effective_visibility = visibility = v;
}
void setSA(double angle) { sun->setSunAngle(angle); }
double getSA() { return sun->getSunAngle(); }
void setSR(double rotation) { sun->setSunRotation( rotation ); }
double getSR() { return sun->getSunRotation(); }
void setSRA(double ra) { sun->setSunRightAscension( ra ); }
double getSRA() { return sun->getSunRightAscension(); }
void setSD( double decl ) { sun->setSunDeclination( decl ); }
double getSD() { return sun->getSunDeclination(); }
void setSDistance( double dist ) { sun->setSunDistance( dist ); }
double getSDistance() { return sun->getSunDistance(); }
void getSunPos(sgCoord* p)
{
sgMat4 Xform;
sun_transform->getTransform(Xform);
sgSetCoord(p, Xform);
}
// draw background portions of sky (do this before you draw rest of your scene).
void preDraw();
// draw translucent clouds (do this after you've drawn all oapaque elements of your scene).
void postDraw( float alt );
// enable the sky
inline void enable()
{
pre_selector->select( 1 );
post_selector->select( 1 );
}
// disable the sky
inline void disable()
{
pre_selector->select( 0 );
post_selector->select( 0 );
}
// current effective visibility
inline float getVisibility() const { return effective_visibility; }
inline void setVisibility( float v )
{
effective_visibility = visibility = v;
}
};

View file

@ -73,11 +73,17 @@ cGrSun::cGrSun( void )
// Destructor
cGrSun::~cGrSun( void )
{
ssgDeRefDelete( sun_transform );
}
ssgBranch * cGrSun::build( const char *sun_path, const char *ihalo_path, const char *ohalo_path, float sun_size, float humidity, float visibility )
ssgBranch * cGrSun::build( double sun_size )
{
sgVec4 color;
ssgDeRefDelete( sun_transform );
sun_transform = new ssgTransform;
sun_transform->ref();
sgVec4 color;
sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
sun_cl = new ssgColourArray( 1 );
@ -96,7 +102,7 @@ ssgBranch * cGrSun::build( const char *sun_path, const char *ihalo_path, const c
sun_state->setShadeModel( GL_SMOOTH );
sun_state->disable( GL_LIGHTING );
sun_state->disable( GL_CULL_FACE );
sun_state->setTexture( sun_path);
sun_state->setTexture( "data/textures/inner_halo.png");
sun_state->enable( GL_TEXTURE_2D );
sun_state->enable( GL_COLOR_MATERIAL );
sun_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
@ -136,7 +142,7 @@ ssgBranch * cGrSun::build( const char *sun_path, const char *ihalo_path, const c
repaint( 0.0, 1.0 );
ihalo_state = new ssgSimpleState();
ihalo_state->setTexture( ihalo_path );
ihalo_state->setTexture( "data/textures/inner_halo.png" );
ihalo_state->enable( GL_TEXTURE_2D );
ihalo_state->disable( GL_LIGHTING );
ihalo_state->setShadeModel( GL_SMOOTH );
@ -176,7 +182,7 @@ ssgBranch * cGrSun::build( const char *sun_path, const char *ihalo_path, const c
ihalo->setState( ihalo_state );
ohalo_state = new ssgSimpleState();
ohalo_state->setTexture( ohalo_path );
ohalo_state->setTexture( "data/textures/outer_halo.png" );
ohalo_state->enable( GL_TEXTURE_2D );
ohalo_state->disable( GL_LIGHTING );
ohalo_state->setShadeModel( GL_SMOOTH );
@ -215,8 +221,6 @@ ssgBranch * cGrSun::build( const char *sun_path, const char *ihalo_path, const c
ssgLeaf *ohalo = new ssgVtxTable ( GL_TRIANGLE_STRIP, ohalo_vl, NULL, ohalo_tl, ohalo_cl );
ohalo->setState( ohalo_state );
sun_transform = new ssgTransform;
ihalo->setCallback( SSG_CALLBACK_PREDRAW, grSunHaloPreDraw );
ihalo->setCallback( SSG_CALLBACK_POSTDRAW, grSunHaloPostDraw );
ohalo->setCallback( SSG_CALLBACK_PREDRAW, grSunHaloPreDraw );

View file

@ -23,7 +23,7 @@
#include <portability.h> // snprintf
#include <glfeatures.h>
#include <plib/ssgAux.h>
//#include <plib/ssgAux.h>
#include "grscene.h"
#include "grloadac.h"
@ -96,8 +96,6 @@ static ssgTransform *TheSun = NULL;
//static cGrCelestialBody *TheCelestBodies[NMaxCelestianBodies] = { NULL, NULL };
static cGrSky *TheSky = NULL;
static cGrSun *Sun = NULL;
static cGrMoon *Moon = NULL;
static sgdVec3 *AStarsData = NULL;
static sgdVec3 *APlanetsData = NULL;
@ -172,14 +170,14 @@ grInitBackground()
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
if (!TheSun && grTrack->local.rain == 0)
/*if (!TheSun && grTrack->local.rain == 0)
{
ssgaLensFlare *sun_obj = new ssgaLensFlare();
TheSun = new ssgTransform;
TheSun->setTransform(lightPosition);
TheSun->addKid(sun_obj);
SunAnchor->addKid(TheSun);
}
}*/
}
// If realistic sky dome is requested,
@ -214,30 +212,27 @@ grInitBackground()
APlanetsData = NULL;
int visibility = 0;
const double domeSizeRatio = grSkyDomeDistance / 80000.0;
GfLogInfo(" Planets : %d\n", NPlanets);
//Build the sky
TheSky = new cGrSky;
TheSky->build(grSkyDomeDistance, grSkyDomeDistance, NPlanets, APlanetsData, NStars, AStarsData );
TheSky->build(grSkyDomeDistance, grSkyDomeDistance, 2000 * domeSizeRatio, grSkyDomeDistance, 1500 * domeSizeRatio, grSkyDomeDistance,
NPlanets, APlanetsData, NStars, AStarsData );
//Add the Sun itself
const double domeSizeRatio = grSkyDomeDistance / 80000.0;
Sun = TheSky->addSun( "data/textures/halo.rgba", "data/textures/halo.rgba", "data/textures/outer_halo.rgba",
2500 * domeSizeRatio, grSkyDomeDistance, 0.5f, 10000.0 );
GLfloat sunAscension = grTrack->local.sunascension;
grSunDeclination = (float)(15 * (double)timeOfDay / 3600 - 90.0);
Sun->setDeclination ( DEG2RAD(grSunDeclination));
Sun->setRightAscension ( sunAscension );
TheSky->setSD( DEG2RAD(grSunDeclination));
TheSky->setSRA( sunAscension );
GfLogInfo(" Sun : time of day = %02d:%02d:%02d (declination = %.1f deg), "
"ascension = %.1f deg\n",
timeOfDay / 3600, (timeOfDay % 3600) / 60, timeOfDay % 60,
grSunDeclination, RAD2DEG(sunAscension));
// Add the Moon (TODO: Find a better solution than this random positioning !)
Moon = TheSky->addMoon( "data/textures/moon.rgba", 2000 * domeSizeRatio, grSkyDomeDistance );
if ( grSunDeclination > 180 )
grMoonDeclination = 3.0 + (rand() % 40);
else
@ -245,8 +240,8 @@ grInitBackground()
const float moonAscension = (float)(rand() % 360);
Moon->setmoonDeclination ( DEG2RAD(grMoonDeclination) );
Moon->setmoonRightAscension ( DEG2RAD(moonAscension) );
TheSky->setMD( DEG2RAD(grMoonDeclination) );
TheSky->setMRA( DEG2RAD(moonAscension) );
GfLogInfo(" Moon : declination = %.1f deg, ascension = %.1f deg\n",
grMoonDeclination, moonAscension);
@ -335,13 +330,13 @@ grInitBackground()
// Set up the light source to the Sun position.
sgCoord sunPosition;
Sun->getPosition(&sunPosition);
TheSky->getSunPos(&sunPosition);
light->setPosition(sunPosition.xyz);
// Initialize the whole sky dome.
sgVec3 viewPos;
sgSetVec3(viewPos,grWrldX/2, grWrldY/2, 0);
TheSky->repositionFlat(viewPos, 0, 0);
sgSetVec3(viewPos, grWrldX/2, grWrldY/2, 0);
TheSky->repositionFlat( viewPos, 0, 0);
//Setup visibility according to rain if any
// TODO: Does visibility really decrease when rain gets heavier ????
@ -378,7 +373,7 @@ grInitBackground()
const GLfloat fog_exp2_density = sqrt_m_log01 / visibility;
//Setup overall light level according to rain if any
const float sol_angle = (float)Sun->getAngle();
const float sol_angle = (float)TheSky->getSA();
const float sky_brightness = (float)(1.0 + cos(sol_angle)) / 2.0f;
float scene_brightness = (float)pow(sky_brightness, 0.5f);
@ -413,7 +408,7 @@ grInitBackground()
NPlanets, APlanetsData, NStars, AStarsData);
sgCoord solpos;
Sun->getPosition(&solpos);
TheSky->getSunPos(&solpos);
light->setPosition(solpos.xyz);
SceneAmbiant[0] = BaseAmbiant[0] * scene_brightness;
@ -1020,19 +1015,19 @@ grUpdateSky(double currentTime, double accelTime)
if (grSunDeclination >= 360.0f)
grSunDeclination -= 360.0f;
Sun->setDeclination ( DEG2RAD(grSunDeclination) );
TheSky->setSD( DEG2RAD(grSunDeclination) );
// 2) Update moon position
grMoonDeclination += deltaDecl;
if (grMoonDeclination >= 360.0f)
grMoonDeclination -= 360.0f;
Moon->setmoonDeclination ( DEG2RAD(grMoonDeclination) );
TheSky->setMD( DEG2RAD(grMoonDeclination) );
lastTimeLowSpeed = nextTimeLowSpeed;
}
// 3) Update scene color and light
const float sol_angle = (float)Sun->getAngle();
const float sol_angle = (float)TheSky->getSA();
const float sky_brightness = (float)(1.0 + cos(sol_angle)) / 2.0f;
float scene_brightness = (float)pow(sky_brightness, 0.5f);
@ -1070,7 +1065,7 @@ grUpdateSky(double currentTime, double accelTime)
// 3c) update the main light position (it's at the sun position !)
sgCoord solpos;
Sun-> getPosition(&solpos);
TheSky->getSunPos(&solpos);
ssgGetLight(0)-> setPosition(solpos.xyz);
// 3c) update scene colors.