]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/main.cxx
Ssg tweaks.
[flightgear.git] / src / Main / main.cxx
index 75acc429ae4e4ad114b7cfffe9572719102b9646..19d796e1bf1c82784f9d92e6afe1648f675cb0aa 100644 (file)
@@ -130,6 +130,7 @@ slSample *s2;
 
 // ssg variables
 ssgRoot *scene = NULL;
+ssgBranch *terrain = NULL;
 ssgTransform *penguin = NULL;
 
 
@@ -181,8 +182,6 @@ static void fgInitVisuals( void ) {
 
     // xglFogi (GL_FOG_MODE, GL_LINEAR);
     xglFogi (GL_FOG_MODE, GL_EXP2);
-    // Fog density is now set when the weather system is initialized
-    // xglFogf (GL_FOG_DENSITY, w->fog_density);
     if ( (current_options.get_fog() == 1) || 
         (current_options.get_shading() == 0) ) {
        // if fastest fog requested, or if flat shading force fastest
@@ -353,11 +352,12 @@ static void fgRenderFrame( void ) {
        xglEnable( GL_DEPTH_TEST );
        if ( current_options.get_fog() > 0 ) {
            xglEnable( GL_FOG );
-           xglFogfv (GL_FOG_COLOR, l->adj_fog_color);
+           xglFogi( GL_FOG_MODE, GL_EXP2 );
+           xglFogfv( GL_FOG_COLOR, l->adj_fog_color );
        }
        // set lighting parameters
-       xglLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_ambient );
-       xglLightfv(GL_LIGHT0, GL_DIFFUSE, l->scene_diffuse );
+       xglLightfv( GL_LIGHT0, GL_AMBIENT, l->scene_ambient );
+       xglLightfv( GL_LIGHT0, GL_DIFFUSE, l->scene_diffuse );
        // xglLightfv(GL_LIGHT0, GL_SPECULAR, white );
        
        if ( current_options.get_textures() ) {
@@ -378,7 +378,56 @@ static void fgRenderFrame( void ) {
            // xglMaterialfv (GL_FRONT, GL_DIFFUSE, white);
        }
 
-       global_tile_mgr.render();
+       // global_tile_mgr.render();
+
+       // ssg test
+
+       xglMatrixMode( GL_PROJECTION );
+       xglLoadIdentity();
+       ssgSetFOV( current_options.get_fov(), 0.0f );
+
+       double agl = current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER
+           - scenery.cur_elev;
+
+       // FG_LOG( FG_ALL, FG_INFO, "visibility is " 
+       //         << current_weather.get_visibility() );
+           
+       if ( agl > 10.0 ) {
+           // ssgSetNearFar( 10.0f, current_weather.get_visibility() );
+           ssgSetNearFar( 10.0f, 100000.0f );
+       } else {
+           // ssgSetNearFar( 0.5f, current_weather.get_visibility() );
+           ssgSetNearFar( 0.5f, 100000.0f );
+       }
+
+       sgMat4 sgTRANS;
+       sgMakeTransMat4( sgTRANS, 
+                        current_view.view_pos.x() 
+                        + current_view.view_forward[0] * 20,
+                        current_view.view_pos.y() 
+                        + current_view.view_forward[1] * 20,
+                        current_view.view_pos.z() 
+                        + current_view.view_forward[2] * 20 );
+
+       sgMat4 sgTMP;
+       sgMat4 sgTUX;
+       sgMultMat4( sgTMP, current_view.sgUP, sgTRANS );
+       sgMultMat4( sgTUX, current_view.sgLARC_TO_SSG, sgTMP );
+       
+       sgCoord tuxpos;
+       sgSetCoord( &tuxpos, sgTUX );
+       penguin->setTransform( &tuxpos );
+
+       sgMakeTransMat4( sgTRANS, 
+                        current_view.view_pos.x(),
+                        current_view.view_pos.y(),
+                        current_view.view_pos.z() );
+       sgMat4 sgVIEW;
+       sgMultMat4( sgVIEW, current_view.sgVIEW, sgTRANS );
+       ssgSetCamera( sgVIEW );
+
+       global_tile_mgr.prep_ssg_nodes();
+       ssgCullAndDraw( scene );
 
        xglDisable( GL_TEXTURE_2D );
        xglDisable( GL_FOG );
@@ -394,33 +443,6 @@ static void fgRenderFrame( void ) {
        xglDisable   ( GL_BLEND ) ;
        xglEnable( GL_FOG );
 
-       // ssg test
-       cout << "trying to draw ssg scene" << endl;
-
-       xglMatrixMode(GL_PROJECTION);
-       xglLoadIdentity();
-       ssgSetFOV(60.0f, 0.0f);
-       ssgSetNearFar(1.0f, 700.0f);
-       sgCoord tuxpos;
-       sgSetCoord( &tuxpos, 
-                   current_view.view_pos.x() + current_view.view_forward[0] 
-                   * 20, 
-                   current_view.view_pos.y() + current_view.view_forward[1]
-                   * 20,
-                   current_view.view_pos.z() + current_view.view_forward[2]
-                   * 20, 
-                   0.0, 0.0, 0.0 );
-       penguin->setTransform( &tuxpos );
-
-       sgCoord campos;
-       sgSetCoord( &campos, 
-                   current_view.view_pos.x(), 
-                   current_view.view_pos.y(),
-                   current_view.view_pos.z(), 
-                   0, 0, 0 );
-       ssgSetCamera( &campos );
-       ssgCullAndDraw( scene );
-
     }
 
     xglutSwapBuffers();
@@ -1060,8 +1082,12 @@ int main( int argc, char **argv ) {
 
     ssgModelPath( "/stage/pinky01/src/Libs/plib-1.0.12/examples/ssg/tux/data/" );
     ssgTexturePath( "/stage/pinky01/src/Libs/plib-1.0.12/examples/ssg/tux/data/" );
+    // ssgModelPath( "/h/curt/src/Libs/plib-1.0.12/examples/ssg/tux/data/" );
+    // ssgTexturePath( "/h/curt/src/Libs/plib-1.0.12/examples/ssg/tux/data/" );
 
     scene = new ssgRoot;
+    terrain = new ssgBranch;
+    terrain->setName( "Terrain" );
     penguin = new ssgTransform;
 
     ssgEntity *tux_obj = ssgLoadAC( "tuxedo.ac" );
@@ -1069,6 +1095,7 @@ int main( int argc, char **argv ) {
     ssgFlatten( tux_obj );
     ssgStripify( penguin );
 
+    scene->addKid( terrain );
     scene->addKid( penguin );
 
     // pass control off to the master GLUT event handler