void IceFloe::tessVertex( void *data ) { sgVec3 *p = (sgVec3*)data; printf("tess vtx %p\n", data ); //printf("tess vtx %3.2f %3.2f %3.2f\n", (*p)[0], (*p)[1],(*p)[2] ); #if 0 if (tessMode==GL_TRIANGLES) { if ((stripA) && (stripB)) { TessTri *tri = new TessTri(); sgCopyVec3( tri->a, *stripA ); sgCopyVec3( tri->b, *stripB ); sgCopyVec3( tri->c, *p ); floeToTess->tess.push_back( tri ); stripA = NULL; stripB = NULL; } else if (stripA) { stripB = p; } else { stripA = p; } } else if (tessMode==GL_TRIANGLE_FAN) { if ((fanCenter) && (stripA)) { TessTri *tri = new TessTri(); sgCopyVec3( tri->a, *fanCenter ); sgCopyVec3( tri->b, *stripA ); sgCopyVec3( tri->c, *p ); stripA = p; floeToTess->tess.push_back( tri ); } else if ((fanCenter)&&(!stripA)) { stripA = p; } else if (!fanCenter) { fanCenter = p; } } else if (tessMode==GL_TRIANGLE_STRIP) { if ((stripA) && (stripB)) { TessTri *tri = new TessTri(); sgCopyVec3( tri->a, *stripA ); sgCopyVec3( tri->a, *stripB ); sgCopyVec3( tri->c, *p ); floeToTess->tess.push_back( tri ); stripA = stripB; stripB = p; } else if (stripA) { stripB = p; } else { stripA = p; } } #endif }
bool cGrCloudLayer::repaint( sgVec3 fog_color ) { float *color; for ( int i = 0; i < 4; i++ ) for ( int j = 0; j < 10; ++j ) { color = cl[i]->get( j ); sgCopyVec3( color, fog_color ); } return true; }
void TransIcelandicExpress::mouseMotion( int xrel, int yrel ) { // rotate the camera sgVec3 axis, oldCamPos; sgMat4 m; float rot_factor = 0.5; // change heading sgSetVec3( axis, 0.0, 1.0, 0.0 ); sgMakeRotMat4( m, (float)xrel * rot_factor, axis ) ; sgXformVec3( cameraPos, m ) ; // change pitch sgSetVec3( axis, 1.0, 0.0, 0.0 ); sgMakeRotMat4( m, (float)yrel * rot_factor, axis ) ; sgCopyVec3( oldCamPos, cameraPos ); sgXformVec3( cameraPos, m ) ; // don't let the camera go below player if (cameraPos[1] < 0.0 ) { sgCopyVec3( cameraPos, oldCamPos ); } }
/** * \brief Tile the terrain * * This function recursively walks the scene graph and sorts all * triangles into a grid of smaller graphs. This reduces the * calculation effort: If the position of the plane and therefore * the grid below it is known, only a small fraction of all * triangles has to be tested. * * During the recursive walk down the tree, the function tracks * all transformations. If a leaf node is encountered, the contained * triangles are transformed by the tracked transformations to * get the absolute position of each triangle. Then all triangles * are sorted into the grid by their absolute position. * * \param e Pointer to the currently processed entity * \param xform Reference to the current transformation */ void HD_TilingTerrain::tiling_terrain(ssgEntity * e, sgMat4 xform) { // only continue if HOT traversal is enabled for this entity if ( e->getTraversalMask() & SSGTRAV_HOT ) { if ( e->isAKindOf(ssgTypeBranch()) ) { ssgBranch *br = (ssgBranch *) e ; if ( e -> isA ( ssgTypeTransform() ) ) { sgMat4 xform1; ((ssgTransform *)e)->getTransform ( xform1 ) ; sgPreMultMat4 ( xform, xform1 ) ;//Pre or Post ??? /* std::cout << "------tranform " << br<< std::endl; std::cout << "-------------- " << xform[0][0]<<" "<< xform[0][1]<<" "<< xform[0][2]<<" "<< xform[0][3]<< std::endl; std::cout << "-------------- " << xform[1][0]<<" "<< xform[1][1]<<" "<< xform[1][2]<<" "<< xform[1][3]<< std::endl; std::cout << "-------------- " << xform[2][0]<<" "<< xform[2][1]<<" "<< xform[2][2]<<" "<< xform[2][3]<< std::endl; std::cout << "-------------- " << xform[3][0]<<" "<< xform[3][1]<<" "<< xform[3][2]<<" "<< xform[3][3]<< std::endl; */ } //else std::cout << "------branch " << br<< std::endl; // Bug #16552: "xform" is actually passed by reference and // not by value. Therefore we have to store it locally and // restore it before recursing to the next child. Else all // children receive an xform matrix that was modified by // the previous child. sgMat4 local_xform; sgCopyMat4(local_xform, xform); for ( int i = 0 ; i < br -> getNumKids () ; i++ ) { tiling_terrain ( br -> getKid ( i ), xform); // restore transformation matrix sgCopyMat4(xform, local_xform); } } else if ( e -> isAKindOf ( ssgTypeLeaf() ) ) { //std::cout << "------leaf " << e<< std::endl; ssgLeaf *leaf = (ssgLeaf *) e ; int nt = leaf->getNumTriangles(); //std::cout << "------n triangles " << nt<< std::endl; for ( int i = 0 ; i < nt ; i++ )//pour chaque triangle { short iv1,iv2,iv3;/*float *v1, *v2, *v3;*/ sgVec3 v1,v2,v3; leaf->getTriangle ( i, &iv1, &iv2, &iv3 ); sgCopyVec3 (v1 , leaf->getVertex(iv1)); sgXformPnt3( v1, xform); sgCopyVec3 (v2 , leaf->getVertex(iv2)); sgXformPnt3( v2, xform); sgCopyVec3 (v3 , leaf->getVertex(iv3)); sgXformPnt3( v3, xform); /* std::cout << "------triangle " << std::endl; std::cout << "-------------- " << v1[0]<<" "<< v1[1]<<" "<< v1[2]<<" "<< std::endl; std::cout << "-------------- " << v2[0]<<" "<< v2[1]<<" "<< v2[2]<<" "<< std::endl; std::cout << "-------------- " << v3[0]<<" "<< v3[1]<<" "<< v3[2]<<" "<< std::endl; */ //calcule cube englobant sgBox box; box.empty(); box.extend(v1); box.extend(v2); box.extend(v3); //std::cout << "Min " << box.min[0]<<", "<<box.min[1]<<", "<<box.min[2]<<" Max"<<box.max[0]<<", "<<box.max[1]<<", "<<box.max[2]<< std::endl; //ajoute dans cellules recouvertes int save = 1; int i1 = (int)(-0.1+box.min[0]/SIZE_CELL_GRID_PLANES) + SIZE_GRID_PLANES/2; int i2 = (int)(0.1+box.max[0]/SIZE_CELL_GRID_PLANES) + SIZE_GRID_PLANES/2; int j1 = (int)(-0.1+box.min[2]/SIZE_CELL_GRID_PLANES) + SIZE_GRID_PLANES/2; int j2 = (int)(0.1+box.max[2]/SIZE_CELL_GRID_PLANES) + SIZE_GRID_PLANES/2; if (((i1<0) && (i2<0)) ||((i1>SIZE_GRID_PLANES) && (i2>SIZE_GRID_PLANES)) ) { save = 0; } if (((j1<0) && (j2<0)) ||((j1>SIZE_GRID_PLANES) && (j2>SIZE_GRID_PLANES)) ) { save = 0; } if (i1<0) i1=0; if (i1>SIZE_GRID_PLANES) i1 = SIZE_GRID_PLANES; if (i2<0) i2=0; if (i2>SIZE_GRID_PLANES) i2 = SIZE_GRID_PLANES; if (j1<0) j1=0; if (j1>SIZE_GRID_PLANES) j1 = SIZE_GRID_PLANES; if (j2<0) j2=0; if (j2>SIZE_GRID_PLANES) j2 = SIZE_GRID_PLANES; //std::cout << "cellules i, j " << i1 <<", "<<i2<<", "<<j1<<","<<j2<< std::endl; if (save) { for ( int i = i1 ; i <= i2; i++ ) { for ( int j = j1 ; j <= j2; j++ ) { //std::cout << "met dans cellule " << i <<", "<<j<< std::endl; tile_table[i][j]->add(v1); tile_table[i][j]->add(v2); tile_table[i][j]->add(v3); } } } } } } }
/** * Create a CRRCControlSurfaceAnimation object * * Initialize the animation from an * <animation type="ControlSurface"> tag */ CRRCControlSurfaceAnimation::CRRCControlSurfaceAnimation(SimpleXMLTransfer *xml) : CRRCAnimation(new ssgTransform()), fallback_data(0.0f), eventAdapter(this, &CRRCControlSurfaceAnimation::axisValueCallback, Event::Input), aileron(0.0f), elevator(0.0f), rudder(0.0f), throttle(0.0f), spoiler(0.0f), flap(0.0f), retract(0.0f), pitch(0.0f) { bool failed = false; // evaluate <object> tag SimpleXMLTransfer *map = xml->getChild("object", true); symbolic_name = map->getString("name", "no_name_set"); max_angle = (float)(map->getDouble("max_angle", 0.0) * SG_RADIANS_TO_DEGREES); abs_max_angle = (float)fabs((double)max_angle); // find hinges and evaluate all <control> tags int num_controls = 0; int num_hinges = 0; for (int i = 0; i < xml->getChildCount(); i++) { SimpleXMLTransfer *child = xml->getChildAt(i); if (child->getName() == "hinge") { // found a <hinge> child sgVec3 pos; pos[SG_X] = (float)(-1 * child->getDouble("y", 0.0)); pos[SG_Y] = (float)(-1 * child->getDouble("x", 0.0)); pos[SG_Z] = (float)(-1 * child->getDouble("z", 0.0)); if (num_hinges == 0) { sgCopyVec3(hinge_1, pos); } else if (num_hinges == 1) { sgCopyVec3(hinge_2, pos); } num_hinges++; } else if (child->getName() == "control") { // found a <control> child // The "*2" factor for each gain value scales the control input // values from -0.5...+0.5 to -1.0...+1.0. This saves one // float multiplication per mapping in the runtime update() routine. std::string mapping = child->getString("mapping", "NOTHING"); float gain = (float)child->getDouble("gain", 1.0); if (mapping == "ELEVATOR") { datasource.push_back(&elevator); source_gain.push_back(gain * 2); num_controls++; } else if (mapping == "AILERON") { datasource.push_back(&aileron); source_gain.push_back(gain * 2); num_controls++; } else if (mapping == "THROTTLE") { datasource.push_back(&throttle); source_gain.push_back(gain * 2); num_controls++; } else if (mapping == "RUDDER") { datasource.push_back(&rudder); source_gain.push_back(gain * 2); num_controls++; } else if (mapping == "FLAP") { datasource.push_back(&flap); source_gain.push_back(gain * 2); num_controls++; } else if (mapping == "SPOILER") { datasource.push_back(&spoiler); source_gain.push_back(gain * 2); num_controls++; } else if (mapping == "RETRACT") { datasource.push_back(&retract); source_gain.push_back(gain * 2); num_controls++; } else if (mapping == "PITCH") { datasource.push_back(&pitch); source_gain.push_back(gain * 2); num_controls++; } else { std::cerr << "ControlSurfaceAnimation: ignoring <control> tag without mapping." << std::endl; } } } if (num_controls < 1) { std::cerr << "ControlSurfaceAnimation: found animation without proper <control> tag. Animation disabled." << std::endl; failed = true; } if (num_hinges < 2) { std::cerr << "ControlSurfaceAnimation: Must specify exactly two hinges!" << std::endl; failed = true; } else { if (num_hinges > 2) { std::cerr << "ControlSurfaceAnimation: Must specify exactly two hinges!" << std::endl; std::cerr << "ControlSurfaceAnimation: Ignoring excessive hinge tag(s)." << std::endl; } sgSubVec3(axis, hinge_2, hinge_1); if (sgLengthVec3(axis) < 0.001) { std::cerr << "ControlSurfaceAnimation: Insufficient spacing between hinges!" << std::endl; failed = true; } } if (failed) { std::cerr << "ControlSurfaceAnimation: Animation setup failed." << std::endl; // set to some non-critical defaults datasource.resize(1); datasource[0] = &fallback_data; source_gain.resize(1); source_gain[0] = 1.0; sgSetVec3(hinge_1, 0.0f, 0.0f, 0.0f); sgSetVec3(hinge_2, 1.0f, 0.0f, 0.0f); sgSubVec3(axis, hinge_2, hinge_1); } sgMakeIdentMat4(move_to_origin); move_to_origin[3][0] = -hinge_1[0]; move_to_origin[3][1] = -hinge_1[1]; move_to_origin[3][2] = -hinge_1[2]; sgMakeTransMat4(move_back, hinge_1); realInit(); }
bool cGrCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat, double alt, double dt ) { sgMat4 T1, LON, LAT; sgVec3 axis; // combine p and asl (meters) to get translation offset sgVec3 asl_offset; sgCopyVec3( asl_offset, up ); sgNormalizeVec3( asl_offset ); if ( alt <= layer_asl ) { sgScaleVec3( asl_offset, layer_asl ); } else { sgScaleVec3( asl_offset, layer_asl + layer_thickness ); } sgAddVec3( asl_offset, p ); // Translate to zero elevation sgMakeTransMat4( T1, asl_offset ); // Rotate to proper orientation sgSetVec3( axis, 0.0, 0.0, 1.0 ); sgMakeRotMat4( LON, (float)(lon * SGD_RADIANS_TO_DEGREES), axis ); sgSetVec3( axis, 0.0, 1.0, 0.0 ); sgMakeRotMat4( LAT, (float)(90.0 - lat * SGD_RADIANS_TO_DEGREES), axis ); sgMat4 TRANSFORM; sgCopyMat4( TRANSFORM, T1 ); sgPreMultMat4( TRANSFORM, LON ); sgPreMultMat4( TRANSFORM, LAT ); sgCoord layerpos; sgSetCoord( &layerpos, TRANSFORM ); layer_transform->setTransform( &layerpos ); // now calculate update texture coordinates if ( last_lon < -900 ) { last_lon = lon; last_lat = lat; } double sp_dist = speed*dt; if ( lon != last_lon || lat != last_lat || sp_dist != 0 ) { double course = 0.0, dist = 0.0; if ( lon != last_lon || lat != last_lat ) { sgVec2 start, dest; sgSetVec2(start, (float)last_lon, (float)last_lat); sgSetVec2(dest, (float)lon, (float)lat); calc_gc_course_dist( dest, start, &course, &dist ); } // calculate cloud movement double ax = 0.0, ay = 0.0, bx = 0.0, by = 0.0; if (dist > 0.0) { ax = cos(course) * dist; ay = sin(course) * dist; } if (sp_dist > 0) { bx = cos(-direction * SGD_DEGREES_TO_RADIANS) * sp_dist; by = sin(-direction * SGD_DEGREES_TO_RADIANS) * sp_dist; } float xoff = (float)((ax + bx) / (2 * scale)); float yoff = (float)((ay + by) / (2 * scale)); const float layer_scale = layer_span / scale; float *base, *tc; base = tl[0]->get( 0 ); base[0] += xoff; if ( base[0] > -10.0 && base[0] < 10.0 ) { base[0] -= (int)base[0]; } else { base[0] = 0.0; ulSetError(UL_WARNING, "Warning: base1\n"); } base[1] += yoff; if ( base[1] > -10.0 && base[1] < 10.0 ) { base[1] -= (int)base[1]; } else { base[1] = 0.0; ulSetError(UL_WARNING, "Warning: base2\n"); } for (int i = 0; i < 4; i++) { tc = tl[i]->get( 0 ); sgSetVec2( tc, base[0] + layer_scale * i/4, base[1] ); for (int j = 0; j < 4; j++) { tc = tl[i]->get( j*2+1 ); sgSetVec2( tc, base[0] + layer_scale * (i+1)/4, base[1] + layer_scale * j/4 ); tc = tl[i]->get( (j+1)*2 ); sgSetVec2( tc, base[0] + layer_scale * i/4, base[1] + layer_scale * (j+1)/4 ); } tc = tl[i]->get( 9 ); sgSetVec2( tc, base[0] + layer_scale * (i+1)/4, base[1] + layer_scale ); } last_lon = lon; last_lat = lat; } return true; }
int grInitScene(void) { void *hndl = grTrackHandle; ssgLight * light = ssgGetLight(0); GLfloat mat_specular[] = {0.3, 0.3, 0.3, 1.0}; GLfloat mat_shininess[] = {50.0}; GLfloat light_position[] = {0, 0, 200, 0.0}; GLfloat lmodel_ambient[] = {0.2, 0.2, 0.2, 1.0}; GLfloat lmodel_diffuse[] = {0.8, 0.8, 0.8, 1.0}; GLfloat fog_clr[] = {1.0, 1.0, 1.0, 0.5}; if (grHandle==NULL) { sprintf(buf, "%s%s", GetLocalDir(), GR_PARAM_FILE); grHandle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT); } mat_specular[0] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_SPEC_R, NULL, mat_specular[0]); mat_specular[1] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_SPEC_G, NULL, mat_specular[1]); mat_specular[2] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_SPEC_B, NULL, mat_specular[2]); lmodel_ambient[0] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_AMBIENT_R, NULL, lmodel_ambient[0]); lmodel_ambient[1] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_AMBIENT_G, NULL, lmodel_ambient[1]); lmodel_ambient[2] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_AMBIENT_B, NULL, lmodel_ambient[2]); lmodel_diffuse[0] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_DIFFUSE_R, NULL, lmodel_diffuse[0]); lmodel_diffuse[1] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_DIFFUSE_G, NULL, lmodel_diffuse[1]); lmodel_diffuse[2] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_DIFFUSE_B, NULL, lmodel_diffuse[2]); mat_shininess[0] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_SHIN, NULL, mat_shininess[0]); light_position[0] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_LIPOS_X, NULL, light_position[0]); light_position[1] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_LIPOS_Y, NULL, light_position[1]); light_position[2] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_LIPOS_Z, NULL, light_position[2]); glShadeModel(GL_SMOOTH); light->setPosition(light_position[0],light_position[1],light_position[2]); light->setColour(GL_AMBIENT,lmodel_ambient); light->setColour(GL_DIFFUSE,lmodel_diffuse); light->setColour(GL_SPECULAR,mat_specular); light->setSpotAttenuation(0.0, 0.0, 0.0); sgCopyVec3 (fog_clr, grTrack->graphic.bgColor); sgScaleVec3 (fog_clr, 0.8); glFogi(GL_FOG_MODE, GL_LINEAR); glFogfv(GL_FOG_COLOR, fog_clr); glFogf(GL_FOG_DENSITY, 0.05); glHint(GL_FOG_HINT, GL_DONT_CARE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); if (!sun) { ssgaLensFlare *sun_obj = NULL ; sun_obj = new ssgaLensFlare () ; sun = new ssgTransform ; sun -> setTransform ( light_position ) ; sun -> addKid ( sun_obj ) ; SunAnchor-> addKid(sun) ; } /* GUIONS GL_TRUE */ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_FALSE); #ifdef GL_SEPARATE_SPECULAR_COLOR glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR); #else #ifdef GL_SEPARATE_SPECULAR_COLOR_EXT glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT,GL_SEPARATE_SPECULAR_COLOR_EXT); #endif #endif return 0; }
void MyShape::getColor(sgVec3 retVec) { sgCopyVec3(retVec, color); }
void MyShape::setColor(sgVec3 newColor) { sgCopyVec3(color, newColor); }
void TransIcelandicExpress::simulate() { sgVec3 fwd, right, up, frict, v; sgVec3 playerForce; float cf_accel = 1.0, // m/s^2 maxVel = 0.5, // m/2 cf_friction_land = 8.0, cf_friction_ice = 5.0; float pv, ff; // friction fudge... more friction for slow objects float timestep = 0.01f; static float timeleft = 0.0f; timeleft += deltaT; sgSetVec3( up, 0.0, 1.0, 0.0 ); sgSetVec3( playerForce, 0.0, 0.0, 0.0 ); while (timeleft > timestep) { sgCopyVec3( fwd, cameraPos ); sgNegateVec3( fwd ); fwd[1] = 0.0; sgNormalizeVec3( fwd ); sgVectorProductVec3( right, fwd, up ); // todo: if on the ground sgScaleVec3( fwd, cf_moveForward ); sgAddVec3( playerForce, fwd ); sgScaleVec3( right, cf_moveSideways ); sgAddVec3( playerForce, right ); sgScaleVec3( playerForce, cf_accel * timestep ); sgAddVec3( player->vel, playerForce ); pv = sgLengthVec3( player->vel ) ; ff = (1.0 - ((pv / maxVel)* 0.8)); ff = ff*ff; sgCopyVec3( frict, player->vel ); sgNegateVec3( frict ); sgScaleVec3( frict, ff * cf_friction_ice * timestep ); sgAddVec3( player->vel, frict ); dbgVel.push_back( pv ); if (dbgVel.size() > 100 ) { dbgVel.pop_front(); } if ( pv > maxVel ) { //printf("maxvel!\n" ); sgNormalizeVec3( player->vel ); sgScaleVec3( player->vel, maxVel ); } sgCopyVec3( v, player->vel ); sgScaleVec3( v, timestep ); sgAddVec3( player->pos, v ); // advance timeleft -= timestep; } player->pos[1] = getHeight( player->pos ); }
bool cGrSkyDome::repaint( sgVec4 sky_color, sgVec4 fog_color, double sol_angle, double vis ) { double diff, prev_sun_angle = 999.0; sgVec3 outer_param, outer_amt, outer_diff; sgVec3 middle_param, middle_amt, middle_diff; int i, j; if (prev_sun_angle == sol_angle) return true; prev_sun_angle = sol_angle; //sol_angle *= SGD_RADIANS_TO_DEGREES; // Check for sunrise/sunset condition if ((sol_angle > 80.0)) { sgSetVec3( outer_param, (float)((10.0 - fabs(90.0 - sol_angle)) / 20.0), (float)((10.0 - fabs(90.0 - sol_angle)) / 40.0), (float)(-(10.0 - fabs(90.0 - sol_angle)) / 30.0)); sgSetVec3( middle_param, (float)((10.0 - fabs(90.0 - sol_angle)) / 40.0), (float)((10.0 - fabs(90.0 - sol_angle)) / 80.0), 0.0 ); sgScaleVec3( outer_diff, outer_param, 1.0f / 6.0f ); sgScaleVec3( middle_diff, middle_param, 1.0f / 6.0f ); } else { sgSetVec3( outer_param, 0.0, 0.0, 0.0 ); sgSetVec3( middle_param, 0.0, 0.0, 0.0 ); sgSetVec3( outer_diff, 0.0, 0.0, 0.0 ); sgSetVec3( middle_diff, 0.0, 0.0, 0.0 ); } // calculate transition colors between sky and fog sgCopyVec3( outer_amt, outer_param ); sgCopyVec3( middle_amt, middle_param ); // // First, recalulate the basic colors // sgVec4 center_color; sgVec4 upper_color[12]; sgVec4 middle_color[12]; sgVec4 lower_color[12]; sgVec4 bottom_color[12]; double vis_factor, cvf = vis; if (cvf > 45000) cvf = 45000; vis_factor = (vis - 1000.0) / 2000.0; if ( vis_factor < 0.0 ) { vis_factor = 0.0; } else if ( vis_factor > 1.0) { vis_factor = 1.0; } for ( j = 0; j < 3; j++ ) { diff = sky_color[j] - fog_color[j]; center_color[j] = sky_color[j]; // - (float)(diff * ( 1.0 - vis_factor )); } for ( i = 0; i < 6; i++ ) { for ( j = 0; j < 3; j++ ) { double saif = sol_angle/SG_PI; diff = sky_color[j] - fog_color[j] * (0.8 + j * 0.2) * (0.8 + saif - ((6-i)/10)); upper_color[i][j] = sky_color[j] - (float)(diff * ( 1.0 - vis_factor * (0.7 + 0.3 * cvf/45000))); middle_color[i][j] = sky_color[j] - (float)(diff * ( 1.0 - vis_factor * (0.1 + 0.85 * cvf/45000))) + middle_amt[j]; lower_color[i][j] = fog_color[j] + outer_amt[j]; if ( upper_color[i][j] > 1.0 ) { upper_color[i][j] = 1.0; } if ( upper_color[i][j] < 0.0 ) { upper_color[i][j] = 0.0; } if ( middle_color[i][j] > 1.0 ) { middle_color[i][j] = 1.0; } if ( middle_color[i][j] < 0.0 ) { middle_color[i][j] = 0.0; } if ( lower_color[i][j] > 1.0 ) { lower_color[i][j] = 1.0; } if ( lower_color[i][j] < 0.0 ) { lower_color[i][j] = 0.0; } } upper_color[i][3] = middle_color[i][3] = lower_color[i][3] = 1.0; for ( j = 0; j < 3; j++ ) { outer_amt[j] -= outer_diff[j]; middle_amt[j] -= middle_diff[j]; } } sgSetVec3( outer_amt, 0.0, 0.0, 0.0 ); sgSetVec3( middle_amt, 0.0, 0.0, 0.0 ); for ( i = 6; i < 12; i++ ) { for ( j = 0; j < 3; j++ ) { double saif = sol_angle/SG_PI; diff = (sky_color[j] - fog_color[j]) * (0.8 + j * 0.2) * (0.8 + saif - ((-i+12)/10)); upper_color[i][j] = sky_color[j] - (float)(diff * ( 1.0 - vis_factor * (0.7 + 0.3 * cvf/45000))); middle_color[i][j] = sky_color[j] - (float)(diff * ( 1.0 - vis_factor * (0.1 + 0.85 * cvf/45000))) + middle_amt[j]; lower_color[i][j] = fog_color[j] + outer_amt[j]; if ( upper_color[i][j] > 1.0 ) { upper_color[i][j] = 1.0; } if ( upper_color[i][j] < 0.0 ) { upper_color[i][j] = 0.0; } if ( middle_color[i][j] > 1.0 ) { middle_color[i][j] = 1.0; } if ( middle_color[i][j] < 0.0 ) { middle_color[i][j] = 0.0; } if ( lower_color[i][j] > 1.0 ) { lower_color[i][j] = 1.0; } if ( lower_color[i][j] < 0.0 ) { lower_color[i][j] = 0.0; } } upper_color[i][3] = middle_color[i][3] = lower_color[i][3] = 1.0; for ( j = 0; j < 3; j++ ) { outer_amt[j] += outer_diff[j]; middle_amt[j] += middle_diff[j]; } } fade_to_black( (sgVec4 *) center_color, asl * center_elev, 1); fade_to_black( upper_color, (asl+0.05f) * upper_elev, 12); fade_to_black( middle_color, (asl+0.05f) * middle_elev, 12); fade_to_black( lower_color, (asl+0.05f) * lower_elev, 12); for ( i = 0; i < 12; i++ ) { sgCopyVec4( 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++ ); // sgVec4 red; // sgSetVec4( red, 1.0, 0.0, 0.0, 1.0 ); sgCopyVec4( slot, center_color ); for ( i = 11; i >= 0; i-- ) { slot = center_disk_cl->get( counter++ ); sgCopyVec4( slot, upper_color[i] ); } slot = center_disk_cl->get( counter++ ); sgCopyVec4( slot, upper_color[11] ); // generate the upper ring counter = 0; for ( i = 0; i < 12; i++ ) { slot = upper_ring_cl->get( counter++ ); sgCopyVec4( slot, middle_color[i] ); slot = upper_ring_cl->get( counter++ ); sgCopyVec4( slot, upper_color[i] ); } slot = upper_ring_cl->get( counter++ ); sgCopyVec4( slot, middle_color[0] ); slot = upper_ring_cl->get( counter++ ); sgCopyVec4( slot, upper_color[0] ); // generate middle ring counter = 0; for ( i = 0; i < 12; i++ ) { slot = middle_ring_cl->get( counter++ ); sgCopyVec4( slot, lower_color[i] ); slot = middle_ring_cl->get( counter++ ); sgCopyVec4( slot, middle_color[i] ); } slot = middle_ring_cl->get( counter++ ); sgCopyVec4( slot, lower_color[0] ); slot = middle_ring_cl->get( counter++ ); sgCopyVec4( slot, middle_color[0] ); // generate lower ring counter = 0; for ( i = 0; i < 12; i++ ) { slot = lower_ring_cl->get( counter++ ); sgCopyVec4( slot, bottom_color[i] ); slot = lower_ring_cl->get( counter++ ); sgCopyVec4( slot, lower_color[i] ); } slot = lower_ring_cl->get( counter++ ); sgCopyVec4( slot, bottom_color[0] ); slot = lower_ring_cl->get( counter++ ); sgCopyVec4( slot, lower_color[0] ); return true; }