// $Id$
+#include <iostream>
+
#include <plib/ssg.h>
#include <simgear/constants.h>
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 );
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 );
// 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 );
// 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;
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;
}
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 );