From f14de5671212317e93cf9b47946d6499c291f393 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 28 Feb 2000 23:04:07 +0000 Subject: [PATCH] Further work on ssg-ifying the sky dome. (not tested) but I can build the structures and update the colors. I still need to set up the transforms properly and connect it into the scene graph. --- simgear/ephemeris/sky.cxx | 213 ++++++++++++++++++++++++++++++++------ simgear/ephemeris/sky.hxx | 21 ++-- 2 files changed, 195 insertions(+), 39 deletions(-) diff --git a/simgear/ephemeris/sky.cxx b/simgear/ephemeris/sky.cxx index 5d7c39f1..f1df2381 100644 --- a/simgear/ephemeris/sky.cxx +++ b/simgear/ephemeris/sky.cxx @@ -97,69 +97,122 @@ bool FGSky::initialize() { int i; // initialize arrays - upper_ring_vl = new ssgVertexArray( 12 ); - upper_ring_cl = new ssgColourArray( 12 ); + center_disk_vl = new ssgVertexArray( 14 ); + center_disk_cl = new ssgColourArray( 14 ); + + upper_ring_vl = new ssgVertexArray( 26 ); + upper_ring_cl = new ssgColourArray( 26 ); - middle_ring_vl = new ssgVertexArray( 12 ); - middle_ring_cl = new ssgColourArray( 12 ); + middle_ring_vl = new ssgVertexArray( 26 ); + middle_ring_cl = new ssgColourArray( 26 ); - lower_ring_vl = new ssgVertexArray( 12 ); - lower_ring_cl = new ssgColourArray( 12 ); + lower_ring_vl = new ssgVertexArray( 26 ); + lower_ring_cl = new ssgColourArray( 26 ); - bottom_ring_vl = new ssgVertexArray( 12 ); - bottom_ring_cl = new ssgColourArray( 12 ); + // initially seed to all blue + sgSetVec3( color, 0.0, 0.0, 1.0 ); - // generate the sky dome vertices + // generate the raw vertex data + sgVec3 center_vertex; + sgVec3 upper_vertex[12]; + sgVec3 middle_vertex[12]; + sgVec3 lower_vertex[12]; + sgVec3 bottom_vertex[12]; - sgSetVec3( color, 0.0, 0.0, 1.0 ); // seed to all blue + sgSetVec3( center_vertex, 0.0, 0.0, CENTER_ELEV ); for ( i = 0; i < 12; i++ ) { theta = (i * 30.0) * DEG_TO_RAD; - sgSetVec3( vertex, + sgSetVec3( upper_vertex[i], cos(theta) * UPPER_RADIUS, sin(theta) * UPPER_RADIUS, UPPER_ELEV ); - upper_ring_vl->add( vertex ); - upper_ring_cl->add( color ); - sgSetVec3( vertex, + sgSetVec3( middle_vertex[i], cos((double)theta) * MIDDLE_RADIUS, sin((double)theta) * MIDDLE_RADIUS, MIDDLE_ELEV ); - middle_ring_vl->add( vertex ); - middle_ring_cl->add( color ); - sgSetVec3( vertex, + sgSetVec3( lower_vertex[i], cos((double)theta) * LOWER_RADIUS, sin((double)theta) * LOWER_RADIUS, LOWER_ELEV ); - lower_ring_vl->add( vertex ); - lower_ring_cl->add( color ); - sgSetVec3( vertex, + sgSetVec3( bottom_vertex[i], cos((double)theta) * BOTTOM_RADIUS, sin((double)theta) * BOTTOM_RADIUS, BOTTOM_ELEV ); - bottom_ring_vl->add( vertex ); - bottom_ring_cl->add( color ); } - // force a rebuild of the colors - rebuild(); + // generate the center disk vertex/color arrays + center_disk_vl->add( center_vertex ); + center_disk_cl->add( color ); + for ( i = 11; i >= 0; i-- ) { + center_disk_vl->add( upper_vertex[i] ); + center_disk_cl->add( color ); + } + center_disk_vl->add( upper_vertex[11] ); + center_disk_cl->add( color ); + + // generate the upper ring + for ( i = 0; i < 12; i++ ) { + upper_ring_vl->add( middle_vertex[i] ); + upper_ring_cl->add( color ); + + upper_ring_vl->add( upper_vertex[i] ); + upper_ring_cl->add( color ); + } + upper_ring_vl->add( middle_vertex[0] ); + upper_ring_cl->add( color ); + + upper_ring_vl->add( upper_vertex[0] ); + upper_ring_cl->add( color ); + + // generate middle ring + for ( i = 0; i < 12; i++ ) { + middle_ring_vl->add( lower_vertex[i] ); + middle_ring_cl->add( color ); + + middle_ring_vl->add( middle_vertex[i] ); + middle_ring_cl->add( color ); + } + middle_ring_vl->add( lower_vertex[0] ); + middle_ring_cl->add( color ); + + middle_ring_vl->add( middle_vertex[0] ); + middle_ring_cl->add( color ); + + // generate lower ring + for ( i = 0; i < 12; i++ ) { + lower_ring_vl->add( bottom_vertex[i] ); + lower_ring_cl->add( color ); + + lower_ring_vl->add( lower_vertex[i] ); + lower_ring_cl->add( color ); + } + lower_ring_vl->add( bottom_vertex[0] ); + lower_ring_cl->add( color ); + + lower_ring_vl->add( lower_vertex[0] ); + lower_ring_cl->add( color ); + + // force a repaint of the colors + repaint(); return true; } -// rebuild the sky colors based on current value of sun_angle, sky, +// repaint the sky colors based on current value of sun_angle, sky, // and fog colors. This updates the color arrays for ssgVtxTable. -bool FGSky::rebuild() { +bool FGSky::repaint() { double diff; sgVec3 outer_param, outer_amt, outer_diff; sgVec3 middle_param, middle_amt, middle_diff; int i, j; + // Check for sunrise/sunset condition if ( (sun_angle > 80.0) && (sun_angle < 100.0) ) { // 0.0 - 0.4 sgSetVec3( outer_param, @@ -189,10 +242,17 @@ bool FGSky::rebuild() { sgCopyVec3( outer_amt, outer_param ); sgCopyVec3( middle_amt, middle_param ); - // float *upper_color, *middle_color, *lower_color; + // + // First, recalulate the basic colors + // + + sgVec3 center_color; + sgVec3 upper_color[12]; + sgVec3 middle_color[12]; + sgVec3 lower_color[12]; + sgVec3 bottom_color[12]; for ( i = 0; i < 6; i++ ) { - // inner_color = for ( j = 0; j < 3; j++ ) { diff = sky_color[j] - fog_color[j]; @@ -212,8 +272,8 @@ bool FGSky::rebuild() { if ( lower_color[i][j] > 255 ) { lower_color[i][j] = 255; } if ( lower_color[i][j] < 25 ) { lower_color[i][j] = 25; } } - upper_color[i][3] = middle_color[i][3] = lower_color[i][3] = - (GLubyte)(sky_color[3] * 255); + // upper_color[i][3] = middle_color[i][3] = lower_color[i][3] = + // (GLubyte)(sky_color[3] * 255); for ( j = 0; j < 3; j++ ) { outer_amt[j] -= outer_diff[j]; @@ -255,8 +315,8 @@ bool FGSky::rebuild() { if ( lower_color[i][j] > 255 ) { lower_color[i][j] = 255; } if ( lower_color[i][j] < 35 ) { lower_color[i][j] = 35; } } - upper_color[i][3] = middle_color[i][3] = lower_color[i][3] = - (GLubyte)(sky_color[3] * 255); + // upper_color[i][3] = middle_color[i][3] = lower_color[i][3] = + // (GLubyte)(sky_color[3] * 255); for ( j = 0; j < 3; j++ ) { outer_amt[j] += outer_diff[j]; @@ -275,10 +335,99 @@ bool FGSky::rebuild() { */ } + for ( i = 0; i < 12; i++ ) { + sgCopyVec3( bottom_color[i], fog_color ); + } + + // + // Second, assign the basic colors to the object color arrays + // + + float *slot; + int counter; + + // update the center disk color arrays + counter = 0; + slot = center_disk_cl->get( counter++ ); + sgCopyVec3( slot, center_color ); + for ( i = 11; i >= 0; i-- ) { + slot = center_disk_cl->get( counter++ ); + sgCopyVec3( slot, upper_color[i] ); + } + slot = center_disk_cl->get( counter++ ); + sgCopyVec3( slot, upper_color[11] ); + + // generate the upper ring + counter = 0; + for ( i = 0; i < 12; i++ ) { + slot = upper_ring_cl->get( counter++ ); + sgCopyVec3( slot, middle_color[i] ); + + slot = upper_ring_cl->get( counter++ ); + sgCopyVec3( slot, upper_color[i] ); + } + slot = upper_ring_cl->get( counter++ ); + sgCopyVec3( slot, middle_color[0] ); + + slot = upper_ring_cl->get( counter++ ); + sgCopyVec3( slot, upper_color[0] ); + + // generate middle ring + counter = 0; + for ( i = 0; i < 12; i++ ) { + slot = middle_ring_cl->get( counter++ ); + sgCopyVec3( slot, lower_color[i] ); + + slot = middle_ring_cl->get( counter++ ); + sgCopyVec3( slot, middle_color[i] ); + } + slot = middle_ring_cl->get( counter++ ); + sgCopyVec3( slot, lower_color[0] ); + + slot = middle_ring_cl->get( counter++ ); + sgCopyVec3( slot, middle_color[0] ); + + // generate lower ring + counter = 0; + for ( i = 0; i < 12; i++ ) { + slot = lower_ring_cl->get( counter++ ); + sgCopyVec3( slot, bottom_color[i] ); + + slot = lower_ring_cl->get( counter++ ); + sgCopyVec3( slot, lower_color[i] ); + } + slot = lower_ring_cl->get( counter++ ); + sgCopyVec3( slot, bottom_color[0] ); + + slot = lower_ring_cl->get( counter++ ); + sgCopyVec3( slot, lower_color[0] ); + return true; } +// build the ssg scene graph sub tree for the sky and connected into +// the provide scene graph root +bool FGSky::build( ssgBranch *branch ) { + sky_selector = new ssgSelector; + sky_transform = new ssgTransform; + + ssgVtxTable *center_disk, *upper_ring, *middle_ring, *lower_ring; + + center_disk = new ssgVtxTable( GL_TRIANGLE_FAN, + center_disk_vl, NULL, NULL, center_disk_cl ); + + upper_ring = new ssgVtxTable( GL_TRIANGLE_STRIP, + upper_ring_vl, NULL, NULL, upper_ring_cl ); + + middle_ring = new ssgVtxTable( GL_TRIANGLE_STRIP, + middle_ring_vl, NULL, NULL, middle_ring_cl ); + + lower_ring = new ssgVtxTable( GL_TRIANGLE_STRIP, + lower_ring_vl, NULL, NULL, lower_ring_cl ); +} + + // Calculate the sky structure vertices void fgSkyVerticesInit() { float theta; diff --git a/simgear/ephemeris/sky.hxx b/simgear/ephemeris/sky.hxx index dfc2a3d2..a4edd851 100644 --- a/simgear/ephemeris/sky.hxx +++ b/simgear/ephemeris/sky.hxx @@ -50,6 +50,12 @@ class FGSky { // sky) + ssgSelector *sky_selector; + ssgTransform *sky_transform; + + ssgVertexArray *center_disk_vl; + ssgColourArray *center_disk_cl; + ssgVertexArray *upper_ring_vl; ssgColourArray *upper_ring_cl; @@ -59,9 +65,6 @@ class FGSky { ssgVertexArray *lower_ring_vl; ssgColourArray *lower_ring_cl; - ssgVertexArray *bottom_ring_vl; - ssgColourArray *bottom_ring_cl; - public: // Constructor @@ -73,18 +76,22 @@ public: // initialize the sky object and connect it into the scene graph bool initialize(); - // rebuild the sky colors based on current value of sun_angle, + // repaint the sky colors based on current value of sun_angle, // sky, and fog colors. This updates the color arrays for // ssgVtxTable. - bool rebuild(); + bool repaint(); + + // build the ssg scene graph sub tree for the sky and connected + // into the provide scene graph branch + bool build( ssgBranch *branch ); // enable the sky in the scene graph (default) - bool enable(); + bool enable() { sky_selector->select( 1 ); } // disable the sky in the scene graph. The leaf node is still // there, how ever it won't be traversed on the cullandrender // phase. - bool disable(); + bool disable() { sky_selector->select( 0 ); } inline void set_sun_angle( double a ) { sun_angle = a; } inline void set_sky_color( sgVec3 color ) { -- 2.39.5