From 9f9f487e2a5cf6fcfff121cc35da789a41df5b43 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 30 Jun 1999 14:35:01 +0000 Subject: [PATCH] Added some early support for a cheezy external view of TuX. 'v' toggles internal vs. external view modes. Add the distance of the bouding radius into the tile's range selector. --- src/Main/keyboard.cxx | 5 ++++- src/Main/main.cxx | 28 ++++++++++++++++++---------- src/Main/views.cxx | 21 ++++++++++++++++++++- src/Main/views.hxx | 34 +++++++++++++++++++++++++++++++++- src/Scenery/tilemgr.cxx | 5 +++-- 5 files changed, 78 insertions(+), 15 deletions(-) diff --git a/src/Main/keyboard.cxx b/src/Main/keyboard.cxx index d4e4e8b6c..b5c7d2d5a 100644 --- a/src/Main/keyboard.cxx +++ b/src/Main/keyboard.cxx @@ -277,7 +277,10 @@ void GLUTkey(unsigned char k, int x, int y) { t->adjust_warp_delta (+30); local_update_sky_and_lighting_params(); return; - case 120: // X key + case 118: // v key + v->cycle_view_mode(); + return; + case 120: // x key fov = current_options.get_fov(); fov /= 1.05; if ( fov < FG_FOV_MIN ) { diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 19d796e1b..f141f3bf4 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -402,17 +402,15 @@ static void fgRenderFrame( void ) { 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 ); + current_view.view_pos.x(), + current_view.view_pos.y(), + current_view.view_pos.z() ); - sgMat4 sgTMP; + // sgMat4 sgTMP; sgMat4 sgTUX; - sgMultMat4( sgTMP, current_view.sgUP, sgTRANS ); - sgMultMat4( sgTUX, current_view.sgLARC_TO_SSG, sgTMP ); + // sgMultMat4( sgTMP, current_view.sgUP, sgTRANS ); + // sgMultMat4( sgTUX, current_view.sgLARC_TO_SSG, sgTMP ); + sgMultMat4( sgTUX, current_view.sgVIEW_ROT, sgTRANS ); sgCoord tuxpos; sgSetCoord( &tuxpos, sgTUX ); @@ -423,7 +421,17 @@ static void fgRenderFrame( void ) { current_view.view_pos.y(), current_view.view_pos.z() ); sgMat4 sgVIEW; - sgMultMat4( sgVIEW, current_view.sgVIEW, sgTRANS ); + + if ( current_view.view_mode == FGView::FG_VIEW_FIRST_PERSON ) { + sgCopyMat4( sgVIEW, current_view.sgVIEW ); + } else if ( current_view.view_mode == FGView::FG_VIEW_FOLLOW ) { + FGMat4Wrapper tmp = current_view.follow.front(); + sgCopyMat4( sgVIEW, tmp.m ); + } + if ( current_view.follow.size() > 15 ) { + current_view.follow.pop_front(); + } + ssgSetCamera( sgVIEW ); global_tile_mgr.prep_ssg_nodes(); diff --git a/src/Main/views.cxx b/src/Main/views.cxx index c6f6eba4f..23945180b 100644 --- a/src/Main/views.cxx +++ b/src/Main/views.cxx @@ -76,6 +76,7 @@ FGView::FGView( void ) { void FGView::Init( void ) { FG_LOG( FG_VIEW, FG_INFO, "Initializing View parameters" ); + view_mode = FG_VIEW_FIRST_PERSON; view_offset = 0.0; goal_view_offset = 0.0; @@ -131,6 +132,16 @@ void FGView::UpdateFOV( const fgOPTIONS& o ) { } +// Cycle view mode +void FGView::cycle_view_mode() { + if ( view_mode == FG_VIEW_FIRST_PERSON ) { + view_mode = FG_VIEW_FOLLOW; + } else if ( view_mode == FG_VIEW_FOLLOW ) { + view_mode = FG_VIEW_FIRST_PERSON; + } +} + + // Basically, this is a modified version of the Mesa gluLookAt() // function that's been modified slightly so we can capture the // result before sending it off to OpenGL land. @@ -742,7 +753,15 @@ void FGView::UpdateViewMath( FGInterface *f ) { sgMat4 sgTMP; sgMultMat4( sgTMP, sgLOCAL, sgUP ); - sgMultMat4( sgVIEW, sgLARC_TO_SSG, sgTMP ); + sgMultMat4( sgVIEW_ROT, sgLARC_TO_SSG, sgTMP ); + + sgMakeTransMat4( sgTRANS, view_pos.x(), view_pos.y(), view_pos.z() ); + + sgMultMat4( sgVIEW, sgVIEW_ROT, sgTRANS ); + + FGMat4Wrapper tmp; + sgCopyMat4( tmp.m, sgVIEW ); + follow.push_back( tmp ); /* cout << "FG derived VIEW matrix using sg routines" << endl; diff --git a/src/Main/views.hxx b/src/Main/views.hxx index 378bf5876..b15a47d9f 100644 --- a/src/Main/views.hxx +++ b/src/Main/views.hxx @@ -29,6 +29,10 @@ # error This library requires C++ #endif +#include + +#include + #include // plib include #include @@ -39,6 +43,18 @@ #include "options.hxx" +FG_USING_STD(list); + + +class FGMat4Wrapper { +public: + sgMat4 m; +}; + +typedef list < FGMat4Wrapper > sgMat4_list; +typedef sgMat4_list::iterator sgMat4_list_iterator; +typedef sgMat4_list::const_iterator const_sgMat4_list_iterator; + // used in views.cxx and tilemgr.cxx #define USE_FAST_FOV_CLIP @@ -49,6 +65,12 @@ class FGView { public: + enum fgViewMode + { + FG_VIEW_FIRST_PERSON = 0, + FG_VIEW_FOLLOW = 1 + }; + // the current offset from forward for viewing double view_offset; @@ -153,7 +175,14 @@ public: // Current model view matrix; GLfloat MODEL_VIEW[16]; - sgMat4 sgLOCAL, sgUP, sgVIEW, sgLARC_TO_SSG; + // view mode + fgViewMode view_mode; + + // sg versions of our friendly matrices + sgMat4 sgLOCAL, sgUP, sgVIEW_ROT, sgTRANS, sgVIEW, sgLARC_TO_SSG; + + // queue of view matrices so we can have a follow view + sgMat4_list follow; public: @@ -190,6 +219,9 @@ public: // Update the field of view coefficients void UpdateFOV( const fgOPTIONS& o ); + // Cycle view mode + void cycle_view_mode(); + // accessor functions inline double get_view_offset() const { return view_offset; } inline void set_view_offset( double a ) { view_offset = a; } diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index f303f8218..e296d0a28 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -744,7 +744,6 @@ void FGTileMgr::prep_ssg_nodes( void ) { float ranges[2]; ranges[0] = 0.0f; - ranges[1] = current_weather.get_visibility(); // traverse the potentially viewable tile list and update range // selector and transform @@ -753,7 +752,9 @@ void FGTileMgr::prep_ssg_nodes( void ) { t = global_tile_cache.get_tile(index); if ( t->is_loaded() ) { - // set range selector (LOD trick) + // set range selector (LOD trick) to be distance to center + // of tile + bounding radius + ranges[1] = current_weather.get_visibility() + t->bounding_radius; t->range_ptr->setRanges( ranges, 2 ); // calculate tile offset