From 886b897fe2698be836c37d5bca8b6f2a21b9a167 Mon Sep 17 00:00:00 2001 From: torcs-ng Date: Tue, 12 Jun 2012 18:51:55 +0000 Subject: [PATCH] - update Sky code git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@4744 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 01c532e990fd57843056c97222e5bff626225217 Former-commit-id: 6ae139010f3dfcc148805d04756ca5ddcbfbea81 --- src/modules/graphic/ssggraph/grMoon.cpp | 13 +- src/modules/graphic/ssggraph/grSky.cpp | 58 +++------ src/modules/graphic/ssggraph/grSky.h | 122 ++++-------------- src/modules/graphic/ssggraph/grSun.cpp | 2 + src/modules/graphic/ssggraph/grbackground.cpp | 11 +- 5 files changed, 58 insertions(+), 148 deletions(-) diff --git a/src/modules/graphic/ssggraph/grMoon.cpp b/src/modules/graphic/ssggraph/grMoon.cpp index 5657669e5..889b28de0 100644 --- a/src/modules/graphic/ssggraph/grMoon.cpp +++ b/src/modules/graphic/ssggraph/grMoon.cpp @@ -41,9 +41,10 @@ static int grMoonOrbPostDraw( ssgEntity *e ) } // Constructor -cGrMoon::cGrMoon( void ) : - prev_moon_angle(-1) +cGrMoon::cGrMoon( void ) { + moon_transform = 0; + prev_moon_angle= - 9999; } // Destructor @@ -114,7 +115,7 @@ bool cGrMoon::repaint( double moon_angle ) return true; } -bool cGrMoon::reposition( sgVec3 p, double angle, double rightAscension, double declination, 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; @@ -123,11 +124,11 @@ bool cGrMoon::reposition( sgVec3 p, double angle, double rightAscension, double sgMakeTransMat4( T1, p ); sgSetVec3( axis, 0.0, 0.0, -1.0 ); - sgMakeRotMat4( GST, (float)angle, axis ); + sgMakeRotMat4( GST, (float)moonangle, axis ); sgSetVec3( axis, 0.0, 0.0, 1.0 ); - sgMakeRotMat4( RA, ((float)rightAscension * SGD_RADIANS_TO_DEGREES) - 90.0, axis ); + sgMakeRotMat4( RA, ((float)moonrightAscension * SGD_RADIANS_TO_DEGREES) - 90.0, axis ); sgSetVec3( axis, 1.0, 0.0, 0.0 ); - sgMakeRotMat4( DEC, (float)declination * SGD_RADIANS_TO_DEGREES, axis ); + sgMakeRotMat4( DEC, (float)moondeclination * SGD_RADIANS_TO_DEGREES, axis ); sgSetVec3( v, 0.0, moon_dist, 0.0 ); sgMakeTransMat4( T2, v ); diff --git a/src/modules/graphic/ssggraph/grSky.cpp b/src/modules/graphic/ssggraph/grSky.cpp index 62c5a1bac..265b2aea9 100644 --- a/src/modules/graphic/ssggraph/grSky.cpp +++ b/src/modules/graphic/ssggraph/grSky.cpp @@ -63,10 +63,8 @@ cGrSky::~cGrSky( void ) void cGrSky::build( double h_radius, double v_radius, - const char *sun_path, const char *ihalo_path, const char *ohalo_path, - float sun_size, const char *moon_path, float moon_size, - int nplanets, sgdVec3 *planet_data, - int nstars, sgdVec3 *star_data, float humidity, float visibility ) + int nplanets, sgdVec3 *planet_data, + int nstars, sgdVec3 *star_data ) { delete dome; delete sun; @@ -94,12 +92,6 @@ 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_path, ihalo_path, ohalo_path, sun_size, humidity, visibility)); - - moon = new cGrMoon; - moon_transform -> addKid( moon->build( moon_path, moon_size )); - planets = new cGrStars; stars_transform -> addKid( planets->build( nplanets, planet_data, h_radius ) ); @@ -120,37 +112,25 @@ void cGrSky::build( double h_radius, double v_radius, post_root->addKid( post_selector ); } - -/*cGrCelestialBody* -cGrSky::addBody( const char *body_tex_path, const char *ihalo_tex_path, const char *ohalo_tex_path, double size, double dist, bool sol ) +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 ) { - cGrCelestialBody* body = new cGrCelestialBody; - bodies_transform->addKid( body->build( body_tex_path, ihalo_tex_path, ohalo_tex_path, size ) ); - bodies.add( body ); - - body -> setDist( dist ); - - if ( sol ) - sol_ref = body; - - return body; + 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; } - -cGrCelestialBody* -cGrSky::addBody( ssgSimpleState *orb_state, ssgSimpleState *ihalo_state, ssgSimpleState *ohalo_state, double size, double dist, bool sol ) +cGrMoon* +cGrSky::addMoon( const char *moon_path, double moon_size, double moon_dist ) { - cGrCelestialBody* body = new cGrCelestialBody; - bodies_transform->addKid( body->build( orb_state, ihalo_state, ohalo_state, size ) ); - bodies.add( body ); + cGrMoon* moon = new cGrMoon; + moon_transform->addKid( moon->build( moon_path, moon_size )); + moon->setmoonDist(moon_dist); - body -> setDist( dist ); - - if ( sol ) - sol_ref = body; - - return body; -}*/ + return moon; +} cGrCloudLayer* @@ -184,11 +164,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->getPosition ( &pos ); calc_celestial_angles( pos.xyz, view_pos, angle, rotation ); sun->setAngle( angle ); sun->setRotation( rotation ); + moon->getPosition(&pos); + calc_celestial_angles( pos.xyz, view_pos, angle, rotation ); + moon->setAngle( angle ); + moon->setRotation( rotation ); for ( i = 0; i < clouds.getNum (); i++ ) { diff --git a/src/modules/graphic/ssggraph/grSky.h b/src/modules/graphic/ssggraph/grSky.h index 5d2814e78..f20f5a1be 100644 --- a/src/modules/graphic/ssggraph/grSky.h +++ b/src/modules/graphic/ssggraph/grSky.h @@ -22,8 +22,6 @@ #include "plib/ssg.h" -//class cGrCelestialBody; -//class cGrCelestialBodyList; class cGrSun; class cGrMoon; class cGrCloudLayer; @@ -45,6 +43,7 @@ class cGrMoon double prev_moon_angle; double moon_angle; + double moon_rotation; double moon_size; double moon_dist; double moonAscension; @@ -82,11 +81,23 @@ public: 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 @@ -154,7 +165,7 @@ public: return reposition ( p, sun_angle, sun_right_ascension, sun_declination, sun_dist ); } - bool reposition( sgVec3 p, double sun_angle, double rightAscension, double declination, double dist ); + bool reposition( sgVec3 p, double sun_angle, double sun_right_ascension, double sun_declination, double sun_dist ); void getPosition (sgCoord* p) { @@ -200,11 +211,11 @@ public: return sun_declination; } - void setDist ( double dist ) + void setDistance ( double dist ) { sun_dist = dist; } - double getDist () + double getDistance () { return sun_dist; } @@ -214,95 +225,6 @@ public: double effective_visibility; }; -/*class cGrCelestialBody -{ -private: - - ssgTransform *transform; - ssgColourArray *cl; - ssgColourArray *ihalo_cl; - ssgColourArray *ohalo_cl; - - // used by repaint for rise/set effects - double body_angle; - double body_rotation; - - // used by reposition - double body_right_ascension; - double body_declination; - double body_dist; - -public: - - cGrCelestialBody( void ); - ~cGrCelestialBody( void ); - - ssgBranch *build( const char* body_tex_path, const char* ihalo_tex_path, const char* ohalo_tex, double body_size ); - ssgBranch *build( ssgSimpleState *orb_state, ssgSimpleState *ihalo_state, ssgSimpleState *ohalo_state, double body_size ); - - bool reposition( sgVec3 p, double angle ) - { - return reposition ( p, angle, body_right_ascension, body_declination, body_dist ); - } - bool reposition( sgVec3 p, double angle, double rightAscension, double declination, double dist ); - - bool repaint() { return repaint ( body_angle ); } - bool repaint( double angle ); - - void getPosition ( sgCoord* p ) - { - sgMat4 Xform; - transform->getTransform(Xform); - sgSetCoord(p, Xform); - } - - void setAngle ( double angle ) { body_angle = angle; } - double getAngle () { return body_angle; } - - void setRotation ( double rotation ) { body_rotation = rotation; } - double getRotation () { return body_rotation; } - - void setRightAscension ( double ra ) { body_right_ascension = ra; } - double getRightAscension () { return body_right_ascension; } - - void setDeclination ( double decl ) { body_declination = decl; } - double getDeclination () { return body_declination; } - - void setDist ( double dist ) { body_dist = dist; } - double getDist () { return body_dist; } - double effective_visibility; - - inline float *getColor() { return cl->get( 0 ); } -} ; - - -class cGrCelestialBodyList : private ssgSimpleList -{ -public: - - cGrCelestialBodyList ( int init = 3 ) - : ssgSimpleList ( sizeof(cGrCelestialBody*), init ) { } - - ~cGrCelestialBodyList () { removeAll(); } - - int getNum (void) { return total ; } - - cGrCelestialBody* get ( unsigned int n ) - { - assert(nbuild(grSkyDomeDistance, grSkyDomeDistance, "data/textures/halo.rgba", "data/textures/halo.rgba", "data/textures/outer_halo.rgba", - 2500 * domeSizeRatio, "data/textures/moon.rgba", 2000 * domeSizeRatio, NPlanets, APlanetsData, NStars, AStarsData, 0.5f, visibility); + TheSky->build(grSkyDomeDistance, grSkyDomeDistance, NPlanets, APlanetsData, NStars, AStarsData ); - //Add the Sun itself + //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); @@ -237,6 +237,7 @@ grInitBackground() 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