Sun now correctly placed in sky and correctly colored.
This commit is contained in:
parent
5f3de889d7
commit
5fbe532ec5
@ -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 );
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -24,6 +24,8 @@
|
||||
// $Id$
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <plib/ssg.h>
|
||||
|
||||
#include <simgear/constants.h>
|
||||
@ -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 );
|
||||
|
||||
ssgBranch *orb = ssgMakeSphere( orb_state, 550.0, 10, 10 );
|
||||
cl = new ssgColourArray( 1 );
|
||||
|
||||
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 );
|
||||
|
@ -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();
|
||||
|
@ -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 );
|
||||
|
@ -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 );
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user