From: curt Date: Thu, 2 Mar 2000 18:20:52 +0000 (+0000) Subject: Sun now correctly placed in sky and correctly colored. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5fbe532ec5e85c0152fe8b7752e48dd626b66144;p=simgear.git Sun now correctly placed in sky and correctly colored. --- diff --git a/simgear/ephemeris/ephemeris.cxx b/simgear/ephemeris/ephemeris.cxx index a3787155..1469c28f 100644 --- a/simgear/ephemeris/ephemeris.cxx +++ b/simgear/ephemeris/ephemeris.cxx @@ -27,17 +27,19 @@ // Constructor FGEphemeris::FGEphemeris( void ) { + our_sun = new Star; } // Destructor FGEphemeris::~FGEphemeris( void ) { + delete our_sun; } // Update (recalculate) the positions of all objects for the specified // time void FGEphemeris::update( FGTime *t ) { - our_sun.updatePosition( t ); + our_sun->updatePosition( t ); } diff --git a/simgear/ephemeris/ephemeris.hxx b/simgear/ephemeris/ephemeris.hxx index adae3023..c681fcc1 100644 --- a/simgear/ephemeris/ephemeris.hxx +++ b/simgear/ephemeris/ephemeris.hxx @@ -33,7 +33,7 @@ class FGEphemeris { - Star our_sun; + Star *our_sun; public: @@ -49,10 +49,10 @@ public: // sun position inline double getSunRightAscension() { - return our_sun.getRightAscension(); + return our_sun->getRightAscension(); } inline double getSunDeclination() { - return our_sun.getDeclination(); + return our_sun->getDeclination(); } }; diff --git a/simgear/sky/skysun.cxx b/simgear/sky/skysun.cxx index 2fd98352..a0a0f8cf 100644 --- a/simgear/sky/skysun.cxx +++ b/simgear/sky/skysun.cxx @@ -24,6 +24,8 @@ // $Id$ +#include + #include #include @@ -56,10 +58,12 @@ bool FGSkySun::initialize() { orb_state->disable( GL_DEPTH_TEST ); orb_state->disable( GL_CULL_FACE ); orb_state->disable( GL_TEXTURE_2D ); - orb_state->disable( GL_COLOR_MATERIAL ); - orb_state->setMaterial( GL_AMBIENT_AND_DIFFUSE, 1.0, 1.0, 1.0, 1.0 ); + orb_state->enable( GL_COLOR_MATERIAL ); + orb_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE ); + + cl = new ssgColourArray( 1 ); - ssgBranch *orb = ssgMakeSphere( orb_state, 550.0, 10, 10 ); + ssgBranch *orb = ssgMakeSphere( orb_state, cl, 550.0, 10, 10 ); // force a repaint of the sun colors with arbitrary defaults repaint( 0.0 ); @@ -110,20 +114,33 @@ bool FGSkySun::repaint( double sun_angle ) { if (color[1] > 1.0) color[1] = 1.0; if (color[2] > 1.0) color[2] = 1.0; - orb_state->setMaterial( GL_AMBIENT_AND_DIFFUSE, - color[0], color[1], color[2], 1.0 ); + cout << "color = " << color[0] << " " << color[1] << " " << color[2] << endl; + + float *ptr; + ptr = cl->get( 0 ); + sgCopyVec3( ptr, color ); } return true; } -// reposition the sun at the specified right ascension and declination -bool FGSkySun::reposition( double rightAscension, double declination ) { - sgMat4 T, RA, DEC; +// 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 FGSkySun::reposition( sgVec3 p, double angle, + double rightAscension, double declination ) +{ + sgMat4 T1, T2, GST, RA, DEC; sgVec3 axis; sgVec3 v; + sgMakeTransMat4( T1, p ); + + sgSetVec3( axis, 0.0, 0.0, -1.0 ); + sgMakeRotMat4( GST, angle, axis ); + // xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0); sgSetVec3( axis, 0.0, 0.0, 1.0 ); sgMakeRotMat4( RA, (rightAscension * RAD_TO_DEG) - 90.0, axis ); @@ -134,12 +151,14 @@ bool FGSkySun::reposition( double rightAscension, double declination ) { // xglTranslatef(0,60000,0); sgSetVec3( v, 0.0, 60000.0, 0.0 ); - sgMakeTransMat4( T, v ); + sgMakeTransMat4( T2, v ); sgMat4 TRANSFORM; - sgCopyMat4( TRANSFORM, RA ); + sgCopyMat4( TRANSFORM, T1 ); + sgPreMultMat4( TRANSFORM, GST ); + sgPreMultMat4( TRANSFORM, RA ); sgPreMultMat4( TRANSFORM, DEC ); - sgPreMultMat4( TRANSFORM, T ); + sgPreMultMat4( TRANSFORM, T2 ); sgCoord skypos; sgSetCoord( &skypos, TRANSFORM ); diff --git a/simgear/sky/skysun.hxx b/simgear/sky/skysun.hxx index 59fa1c50..77e5d2a9 100644 --- a/simgear/sky/skysun.hxx +++ b/simgear/sky/skysun.hxx @@ -41,6 +41,8 @@ class FGSkySun { ssgSimpleState *orb_state; ssgSimpleState *halo_state; + ssgColourArray *cl; + public: // Constructor @@ -61,8 +63,11 @@ public: bool repaint( double sun_angle ); // reposition the sun at the specified right ascension and - // declination - bool reposition( double rightAscension, double declination ); + // 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 ); // Draw the sun bool draw(); diff --git a/simgear/sky/sphere.cxx b/simgear/sky/sphere.cxx index c7eabd0f..c4f1d7af 100644 --- a/simgear/sky/sphere.cxx +++ b/simgear/sky/sphere.cxx @@ -26,8 +26,9 @@ // return a sphere object as an ssgBranch -ssgBranch *ssgMakeSphere( ssgSimpleState *state, double radius, int slices, - int stacks ) { +ssgBranch *ssgMakeSphere( ssgSimpleState *state, ssgColourArray *cl, + double radius, int slices, int stacks ) +{ float rho, drho, theta, dtheta; float x, y, z; float s, t, ds, dt; @@ -37,6 +38,24 @@ ssgBranch *ssgMakeSphere( ssgSimpleState *state, double radius, int slices, sgVec2 vec2; sgVec3 vec3; + // handle cl whether it is preinitialized or not + if ( cl == NULL ) { + // create a new array if needed + cl = new ssgColourArray( 1 ); + } + + sgVec3 color; + sgSetVec3( color, 1.0, 1.0, 1.0 ); + + if ( cl->getNum() > 1 ) { + cl->removeAll(); + cl->add( color ); + } else if ( cl->getNum() == 0 ) { + cl->add( color ); + } else { + // accept value as given to us in + } + drho = M_PI / (float) stacks; dtheta = 2.0 * M_PI / (float) slices; @@ -96,7 +115,7 @@ ssgBranch *ssgMakeSphere( ssgSimpleState *state, double radius, int slices, } ssgLeaf *slice = - new ssgVtxTable ( GL_TRIANGLE_STRIP, vl, nl, tl, NULL ); + new ssgVtxTable ( GL_TRIANGLE_STRIP, vl, nl, tl, cl ); slice->setState( state ); sphere->addKid( slice ); diff --git a/simgear/sky/sphere.hxx b/simgear/sky/sphere.hxx index 5d64b101..566fe1c0 100644 --- a/simgear/sky/sphere.hxx +++ b/simgear/sky/sphere.hxx @@ -27,7 +27,7 @@ // return a sphere object as an ssgBranch (and connect in the // specified ssgSimpleState -ssgBranch *ssgMakeSphere( ssgSimpleState *state, double radius, int slices, - int stacks ); +ssgBranch *ssgMakeSphere( ssgSimpleState *state, ssgColourArray *cl, + double radius, int slices, int stacks );