]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/renderer.cxx
Fix a typo and an unitialized variable
[flightgear.git] / src / Main / renderer.cxx
index fe79a0425995790e44e904a1e362f10b5832f0be..0e25a71692b87ff8dbc98f349c8403d6137e3a59 100644 (file)
@@ -57,6 +57,7 @@
 #include <Time/light.hxx>
 #include <Time/light.hxx>
 #include <Aircraft/aircraft.hxx>
+// #include <Aircraft/replay.hxx>
 #include <Cockpit/panel.hxx>
 #include <Cockpit/cockpit.hxx>
 #include <Cockpit/hud.hxx>
@@ -66,7 +67,6 @@
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
 #include <ATC/ATCdisplay.hxx>
-#include <Replay/replay.hxx>
 #include <GUI/new_gui.hxx>
 
 #include "splash.hxx"
@@ -244,7 +244,13 @@ FGRenderer::update( bool refresh_camera_settings ) {
         SGAnimation::set_sim_time_sec( 0.0 );
         return;
     }
+//    return; 
 
+       // TODO:TEST only, don't commit that !!
+//     sgFXperFrameInit();
+
+    extern void sgShaderFrameInit(double delta_time_sec);
+    sgShaderFrameInit(delta_time_sec);
 
     bool draw_otw = fgGetBool("/sim/rendering/draw-otw");
     bool skyblend = fgGetBool("/sim/rendering/skyblend");
@@ -314,7 +320,8 @@ FGRenderer::update( bool refresh_camera_settings ) {
     // calculate our current position in cartesian space
     Point3D cntr = globals->get_scenery()->get_next_center();
     globals->get_scenery()->set_center(cntr);
-    current__view->set_scenery_center(cntr);
+    // Force update of center dependent values ...
+    current__view->set_dirty();
 
     if ( refresh_camera_settings ) {
         // update view port
@@ -383,7 +390,7 @@ FGRenderer::update( bool refresh_camera_settings ) {
         */
 
         static SGSkyColor scolor;
-        FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
+//        FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
 
         scolor.sky_color   = l->sky_color();
         scolor.fog_color   = l->adj_fog_color();
@@ -465,7 +472,8 @@ FGRenderer::update( bool refresh_camera_settings ) {
         glEnable( GL_FOG );
         glFogi( GL_FOG_MODE, GL_EXP2 );
         glFogfv( GL_FOG_COLOR, l->adj_fog_color() );
-    }
+    } else
+        glDisable( GL_FOG ); 
 
     // set sun/lighting parameters
     ssgGetLight( 0 ) -> setPosition( l->sun_vec() );
@@ -487,11 +495,10 @@ FGRenderer::update( bool refresh_camera_settings ) {
     glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
     glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
 
-    double agl =
-        current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
-        - globals->get_scenery()->get_cur_elev();
+    double agl = current__view->getAltitudeASL_ft()*SG_FEET_TO_METER
+      - current__view->getSGLocation()->get_cur_elev_m();
 
-    if ( agl > 50.0 ) {
+    if ( agl > 10.0 ) {
         scene_nearplane = 10.0f;
         scene_farplane = 120000.0f;
     } else {
@@ -711,17 +718,7 @@ FGRenderer::update( bool refresh_camera_settings ) {
         globals->get_aircraft_model()->select( true );
         globals->get_model_mgr()->draw();
         globals->get_aircraft_model()->draw();
-        // If the view is internal, the previous line draw the 
-        //  cockpit with modified near/far clip planes and deselect
-        //  the aircraft in the global scenegraph
-        // Otherwise, it just enables the aircraft: The scenegraph
-        //  must be drawn again to see the plane.
-        ssgBranch *branch = globals->get_scenery()->get_aircraft_branch();
-        // in external view the shadows are drawn before the transparent parts of the ac
-        if( ! is_internal )
-            branch->setTravCallback( SSG_CALLBACK_POSTTRAV, SGShadowVolume::ACpostTravCB);
-        ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
-        branch->setTravCallback( SSG_CALLBACK_POSTTRAV, 0);
+
         FGTileMgr::set_tile_filter( true );
         sgSetModelFilter( true );
         globals->get_aircraft_model()->select( true );
@@ -923,5 +920,50 @@ void FGRenderer::setNearFar( float n, float f ) {
     fgHackFrustum();
 }
 
+bool FGRenderer::getPickInfo( sgdVec3 pt, sgdVec3 dir, unsigned x, unsigned y )
+{
+  // Get the matrices involved in the transform from global to screen
+  // coordinates.
+  sgMat4 pm;
+  ssgGetProjectionMatrix(pm);
+  sgMat4 mv;
+  ssgGetModelviewMatrix(mv);
+  
+  // Compose ...
+  sgMat4 m;
+  sgMultMat4(m, pm, mv);
+  // ... and invert
+  sgInvertMat4(m);
+  
+  // Get the width and height of the display to be able to normalize the
+  // mouse coordinate
+  float width = fgGetInt("/sim/startup/xsize");
+  float height = fgGetInt("/sim/startup/ysize");
+  
+  // Compute some coordinates of in the line from the eyepoint to the
+  // mouse click coodinates.
+  // First build the normalized projection coordinates
+  sgVec4 normPt;
+  sgSetVec4(normPt, (2*x - width)/width, -(2*y - height)/height, 1, 1);
+  // Transform them into the real world
+  sgVec4 worldPt;
+  sgXformPnt4(worldPt, normPt, m);
+  if (worldPt[3] == 0)
+    return false;
+  sgScaleVec3(worldPt, 1/worldPt[3]);
+
+  // Now build a direction from the point
+  FGViewer* view = globals->get_current_view();
+  sgVec4 fDir;
+  sgSubVec3(fDir, worldPt, view->get_view_pos());
+  sgdSetVec3(dir, fDir);
+  sgdNormalizeVec3(dir);
+
+  // Copy the start point
+  sgdCopyVec3(pt, view->get_absolute_view_pos());
+
+  return true;
+}
 
 // end of renderer.cxx
+