From cf6022e43937bc19dc97885fb8248e67e69b6ad8 Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 26 Oct 2000 21:51:09 +0000 Subject: [PATCH] Added a viewmgr system and made corresponding changes to support it. --- src/GUI/gui.cxx | 1 - src/Main/Makefile.am | 3 +- src/Main/fg_init.cxx | 68 +++---- src/Main/globals.hxx | 16 +- src/Main/keyboard.cxx | 10 +- src/Main/main.cxx | 61 ++---- src/Main/options.cxx | 4 + src/Main/viewer.cxx | 7 - src/Main/viewer.hxx | 3 - src/Main/viewer_lookat.cxx | 51 ----- src/Main/viewer_lookat.hxx | 3 - src/Main/viewer_rph.cxx | 61 ++---- src/Main/viewmgr.cxx | 34 ++++ src/Main/viewmgr.hxx | 96 +++++++++ src/Main/views.cxx | 404 ------------------------------------- src/Main/views.hxx | 205 ------------------- src/Time/moonpos.cxx | 2 +- src/Time/sunpos.cxx | 2 +- 18 files changed, 222 insertions(+), 809 deletions(-) create mode 100644 src/Main/viewmgr.cxx create mode 100644 src/Main/viewmgr.hxx delete mode 100644 src/Main/views.cxx delete mode 100644 src/Main/views.hxx diff --git a/src/GUI/gui.cxx b/src/GUI/gui.cxx index b9542d887..617973b0c 100644 --- a/src/GUI/gui.cxx +++ b/src/GUI/gui.cxx @@ -904,7 +904,6 @@ GLubyte *hiResScreenCapture( int multiplier ) b1->copyBitmap( &b2, cur_width*x, cur_height*y ); } } - globals->get_current_view()->UpdateViewParams(cur_view_fdm); globals->get_options()->set_fov(oldfov); return b1->getBitmap(); } diff --git a/src/Main/Makefile.am b/src/Main/Makefile.am index 0baa34931..5a6fb2967 100644 --- a/src/Main/Makefile.am +++ b/src/Main/Makefile.am @@ -45,7 +45,8 @@ fgfs_SOURCES = \ splash.cxx splash.hxx \ viewer.cxx viewer.hxx \ viewer_lookat.cxx viewer_lookat.hxx \ - viewer_rph.cxx viewer_rph.hxx + viewer_rph.cxx viewer_rph.hxx \ + viewmgr.cxx viewmgr.hxx fgfs_LDADD = \ $(top_builddir)/src/Aircraft/libAircraft.a \ diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index db2c4b5d6..408baf805 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -564,24 +564,24 @@ bool fgInitSubsystems( void ) { &fgEVENT_MGR::PrintStats), fgEVENT::FG_EVENT_READY, 60000 ); - // Initialize view parameters - FG_LOG( FG_GENERAL, FG_DEBUG, "Before current_view.init()"); - globals->get_current_view()->init(); - // globals->get_pilot_view()->Init(); - FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()"); - - globals->get_current_view()-> - set_geod_view_pos( cur_fdm_state->get_Longitude(), - cur_fdm_state->get_Lat_geocentric(), - cur_fdm_state->get_Altitude() * - FEET_TO_METER ); - globals->get_current_view()-> - set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() * - FEET_TO_METER ); - globals->get_current_view()-> - set_rph( cur_fdm_state->get_Phi(), - cur_fdm_state->get_Theta(), - cur_fdm_state->get_Psi() ); + // Initialize win ratio parameters + globals->get_options()->set_win_ratio( globals->get_options()->get_xsize() / + globals->get_options()->get_ysize() + ); + + // Initialize pilot view + FGViewerRPH *pilot_view = + (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 ); + + pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(), + cur_fdm_state->get_Lat_geocentric(), + cur_fdm_state->get_Altitude() * + FEET_TO_METER ); + pilot_view->set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() * + FEET_TO_METER ); + pilot_view->set_rph( cur_fdm_state->get_Phi(), + cur_fdm_state->get_Theta(), + cur_fdm_state->get_Psi() ); FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << globals->get_current_view()->get_abs_view_pos()); @@ -799,23 +799,21 @@ void fgReInitSubsystems( void ) globals->get_options()->get_heading() * DEG_TO_RAD ); // Initialize view parameters - globals->get_current_view()->set_view_offset( 0.0 ); - globals->get_current_view()->set_goal_view_offset( 0.0 ); - - FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()"); - - globals->get_current_view()-> - set_geod_view_pos( cur_fdm_state->get_Longitude(), - cur_fdm_state->get_Lat_geocentric(), - cur_fdm_state->get_Altitude() * - FEET_TO_METER ); - globals->get_current_view()-> - set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() * - FEET_TO_METER ); - globals->get_current_view()-> - set_rph( cur_fdm_state->get_Phi(), - cur_fdm_state->get_Theta(), - cur_fdm_state->get_Psi() ); + FGViewerRPH *pilot_view = + (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 ); + + pilot_view->set_view_offset( 0.0 ); + pilot_view->set_goal_view_offset( 0.0 ); + + pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(), + cur_fdm_state->get_Lat_geocentric(), + cur_fdm_state->get_Altitude() * + FEET_TO_METER ); + pilot_view->set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() * + FEET_TO_METER ); + pilot_view->set_rph( cur_fdm_state->get_Phi(), + cur_fdm_state->get_Theta(), + cur_fdm_state->get_Psi() ); FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << globals->get_current_view()->get_abs_view_pos()); diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index 6e698204d..fdf7275a0 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -31,7 +31,7 @@ #include #include "options.hxx" -#include "viewer_rph.hxx" +#include "viewmgr.hxx" class FGGlobals { @@ -64,8 +64,9 @@ private: // options FGOptions *options; - // viewers - FGViewerRPH *current_view; + // viewer maneger + FGViewMgr *viewmgr; + FGViewer *current_view; public: @@ -98,11 +99,10 @@ public: inline FGOptions *get_options() const { return options; } inline void set_options( FGOptions *o ) { options = o; } - // inline FGViewer *get_pilot_view() const { return pilot_view; } - // inline void set_pilot_view( FGViewer *v ) { pilot_view = v; } - - inline FGViewerRPH *get_current_view() const { return current_view; } - inline void set_current_view( FGViewerRPH *v ) { current_view = v; } + inline FGViewMgr *get_viewmgr() const { return viewmgr; } + inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; } + inline FGViewer *get_current_view() const { return current_view; } + inline void set_current_view( FGViewer *v ) { current_view = v; } }; diff --git a/src/Main/keyboard.cxx b/src/Main/keyboard.cxx index 5ee3a5ffa..e28854cc8 100644 --- a/src/Main/keyboard.cxx +++ b/src/Main/keyboard.cxx @@ -78,14 +78,12 @@ extern void fgReshape( int width, int height ); // Handle keyboard events void GLUTkey(unsigned char k, int x, int y) { - FGInterface *f; - FGViewerRPH *v; float fov, tmp; static bool winding_ccw = true; int speed; - f = current_aircraft.fdm_state; - v = globals->get_current_view(); + FGInterface *f = current_aircraft.fdm_state; + FGViewerRPH *v = (FGViewerRPH *)globals->get_current_view(); FG_LOG( FG_INPUT, FG_DEBUG, "Key hit = " << k ); if ( puKeyboard(k, PU_DOWN) ) { @@ -473,9 +471,7 @@ void GLUTkey(unsigned char k, int x, int y) { // Handle "special" keyboard events void GLUTspecialkey(int k, int x, int y) { - FGViewerRPH *v; - - v = globals->get_current_view(); + FGViewerRPH *v = (FGViewerRPH *)globals->get_current_view(); FG_LOG( FG_INPUT, FG_DEBUG, "Special key hit = " << k ); diff --git a/src/Main/main.cxx b/src/Main/main.cxx index b7b666a77..658ee8f74 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -118,10 +118,6 @@ ssgTransform *ship_pos = NULL; #include "keyboard.hxx" #include "splash.hxx" -// temporary? -#include "viewer_lookat.hxx" -FGViewerLookAt *tv; - // -dw- use custom sioux settings so I can see output window #ifdef macintosh # ifndef FG_NDEBUG @@ -326,18 +322,19 @@ void fgRenderFrame( void ) { // printf("scenery center = %.2f %.2f %.2f\n", scenery.center.x(), // scenery.center.y(), scenery.center.z()); - globals->get_current_view()-> - set_geod_view_pos( cur_fdm_state->get_Longitude(), - cur_fdm_state->get_Lat_geocentric(), - cur_fdm_state->get_Altitude() * - FEET_TO_METER ); - globals->get_current_view()-> - set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() * - FEET_TO_METER ); - globals->get_current_view()-> - set_rph( cur_fdm_state->get_Phi(), - cur_fdm_state->get_Theta(), - cur_fdm_state->get_Psi() ); + FGViewerRPH *pilot_view = + (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 ); + + pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(), + cur_fdm_state->get_Lat_geocentric(), + cur_fdm_state->get_Altitude() * + FEET_TO_METER ); + pilot_view->set_sea_level_radius( cur_fdm_state-> + get_Sea_level_radius() * + FEET_TO_METER ); + pilot_view->set_rph( cur_fdm_state->get_Phi(), + cur_fdm_state->get_Theta(), + cur_fdm_state->get_Psi() ); #if 0 // this is a test, we are trying to match RPH and LookAt @@ -432,14 +429,6 @@ void fgRenderFrame( void ) { glLoadIdentity(); ssgSetCamera( (sgMat4)globals->get_current_view()->get_VIEW() ); - /* - sgMat4 vm_tmp, view_mat; - sgTransposeNegateMat4 ( vm_tmp, current_view.VIEW ) ; - sgCopyMat4( view_mat, copy_of_ssgOpenGLAxisSwapMatrix ) ; - sgPreMultMat4( view_mat, vm_tmp ) ; - glLoadMatrixf( (float *)view_mat ); - */ - // set the opengl state to known default values default_state->force(); @@ -583,10 +572,6 @@ void fgRenderFrame( void ) { } else if ( globals->get_options()->get_view_mode() == FGOptions::FG_VIEW_FOLLOW ) { - // select view matrix from front of view matrix queue - // FGMat4Wrapper tmp = current_view.follow.front(); - // sgCopyMat4( sgVIEW, tmp.m ); - // enable TuX and set up his position and orientation penguin_sel->select(1); @@ -641,21 +626,9 @@ void fgRenderFrame( void ) { } # endif - // ssgSetCamera( current_view.VIEW ); - // position tile nodes and update range selectors global_tile_mgr.prep_ssg_nodes(); - // force the default state so ssg can get back on track if - // we've changed things elsewhere (this is now handled - // differently) - // - // FGMaterialSlot m_slot; - // FGMaterialSlot *m_ptr = &m_slot; - // if ( material_mgr.find( "Default", m_ptr ) ) { - // m_ptr->get_state()->force(); - // } - // draw the sky backdrop thesky->preDraw(); @@ -1369,11 +1342,13 @@ int main( int argc, char **argv ) { FGOptions *options = new FGOptions; globals->set_options( options ); + FGViewMgr *viewmgr = new FGViewMgr; + globals->set_viewmgr( viewmgr ); + FGViewerRPH *pv = new FGViewerRPH; + globals->get_viewmgr()->add_view( pv ); globals->set_current_view( pv ); - tv = new FGViewerLookAt; - tv->init(); - + // Scan the config file(s) and command line options to see if // fg_root was specified (ignore all other options for now) fgInitFGRoot(argc, argv); diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 2f1f01691..01996cf6c 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -936,6 +936,10 @@ int FGOptions::parse_option( const string& arg ) { } else { default_view_offset = atof( woffset.c_str() ) * DEG_TO_RAD; } + FGViewerRPH *pilot_view = + (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 ); + pilot_view->set_view_offset( default_view_offset ); + pilot_view->set_goal_view_offset( default_view_offset ); // $$$ end - added VS Renganathan, 14 Oct 2K } else if ( arg.find( "--wp=" ) != string::npos ) { parse_wp( arg.substr( 5 ) ); diff --git a/src/Main/viewer.cxx b/src/Main/viewer.cxx index 33a286823..4b70193e1 100644 --- a/src/Main/viewer.cxx +++ b/src/Main/viewer.cxx @@ -39,13 +39,6 @@ FGViewer::FGViewer( void ) } -// Initialize a view structure -void FGViewer::init( void ) { - FG_LOG( FG_VIEW, FG_ALERT, "Shouldn't ever see this" ); - exit(-1); -} - - // Update the view parameters void FGViewer::update() { FG_LOG( FG_VIEW, FG_ALERT, "Shouldn't ever see this" ); diff --git a/src/Main/viewer.hxx b/src/Main/viewer.hxx index b9ba984cf..0253dc459 100644 --- a/src/Main/viewer.hxx +++ b/src/Main/viewer.hxx @@ -116,9 +116,6 @@ public: // Destructor virtual ~FGViewer( void ); - // Initialize a view class - virtual void init( void ); - ////////////////////////////////////////////////////////////////////// // setter functions ////////////////////////////////////////////////////////////////////// diff --git a/src/Main/viewer_lookat.cxx b/src/Main/viewer_lookat.cxx index efb002c6d..21e2a5ad0 100644 --- a/src/Main/viewer_lookat.cxx +++ b/src/Main/viewer_lookat.cxx @@ -108,57 +108,6 @@ static void fgLookAt( sgVec3 eye, sgVec3 center, sgVec3 up, sgMat4 &m ) { } -// Initialize a view structure -void FGViewerLookAt::init( void ) { - set_dirty(); - - FG_LOG( FG_VIEW, FG_INFO, "Initializing View parameters" ); - - view_offset = goal_view_offset = - globals->get_options()->get_default_view_offset(); - sgSetVec3( pilot_offset, 0.0, 0.0, 0.0 ); - - globals->get_options()->set_win_ratio( globals->get_options()->get_xsize() / - globals->get_options()->get_ysize() - ); -} - - -#define USE_FAST_LOCAL -#ifdef USE_FAST_LOCAL -inline static void fgMakeLOCAL( sgMat4 dst, const double Theta, - const double Phi, const double Psi) -{ - SGfloat cosTheta = (SGfloat) cos(Theta); - SGfloat sinTheta = (SGfloat) sin(Theta); - SGfloat cosPhi = (SGfloat) cos(Phi); - SGfloat sinPhi = (SGfloat) sin(Phi); - SGfloat sinPsi = (SGfloat) sin(Psi) ; - SGfloat cosPsi = (SGfloat) cos(Psi) ; - - dst[0][0] = cosPhi * cosTheta; - dst[0][1] = sinPhi * cosPsi + cosPhi * -sinTheta * -sinPsi; - dst[0][2] = sinPhi * sinPsi + cosPhi * -sinTheta * cosPsi; - dst[0][3] = SG_ZERO; - - dst[1][0] = -sinPhi * cosTheta; - dst[1][1] = cosPhi * cosPsi + -sinPhi * -sinTheta * -sinPsi; - dst[1][2] = cosPhi * sinPsi + -sinPhi * -sinTheta * cosPsi; - dst[1][3] = SG_ZERO ; - - dst[2][0] = sinTheta; - dst[2][1] = cosTheta * -sinPsi; - dst[2][2] = cosTheta * cosPsi; - dst[2][3] = SG_ZERO; - - dst[3][0] = SG_ZERO; - dst[3][1] = SG_ZERO; - dst[3][2] = SG_ZERO; - dst[3][3] = SG_ONE ; -} -#endif - - // convert sgMat4 to MAT3 and print static void print_sgMat4( sgMat4 &in) { int i, j; diff --git a/src/Main/viewer_lookat.hxx b/src/Main/viewer_lookat.hxx index 19b2941e9..3920fbcef 100644 --- a/src/Main/viewer_lookat.hxx +++ b/src/Main/viewer_lookat.hxx @@ -64,9 +64,6 @@ public: // Destructor ~FGViewerLookAt( void ); - // Initialize a view class - void init( void ); - ////////////////////////////////////////////////////////////////////// // setter functions ////////////////////////////////////////////////////////////////////// diff --git a/src/Main/viewer_rph.cxx b/src/Main/viewer_rph.cxx index f900abfe4..503c2de46 100644 --- a/src/Main/viewer_rph.cxx +++ b/src/Main/viewer_rph.cxx @@ -46,6 +46,28 @@ // Constructor FGViewerRPH::FGViewerRPH( void ) { +#ifndef USE_FAST_VIEWROT + // This never changes -- NHV + LARC_TO_SSG[0][0] = 0.0; + LARC_TO_SSG[0][1] = 1.0; + LARC_TO_SSG[0][2] = -0.0; + LARC_TO_SSG[0][3] = 0.0; + + LARC_TO_SSG[1][0] = 0.0; + LARC_TO_SSG[1][1] = 0.0; + LARC_TO_SSG[1][2] = 1.0; + LARC_TO_SSG[1][3] = 0.0; + + LARC_TO_SSG[2][0] = 1.0; + LARC_TO_SSG[2][1] = -0.0; + LARC_TO_SSG[2][2] = 0.0; + LARC_TO_SSG[2][3] = 0.0; + + LARC_TO_SSG[3][0] = 0.0; + LARC_TO_SSG[3][1] = 0.0; + LARC_TO_SSG[3][2] = 0.0; + LARC_TO_SSG[3][3] = 1.0; +#endif // USE_FAST_VIEWROT } @@ -81,45 +103,6 @@ inline static void fgMakeViewRot( sgMat4 dst, const sgMat4 m1, const sgMat4 m2 ) #endif -// Initialize a view structure -void FGViewerRPH::init( void ) { - set_dirty(); - - FG_LOG( FG_VIEW, FG_INFO, "Initializing View parameters" ); - - view_offset = goal_view_offset = - globals->get_options()->get_default_view_offset(); - sgSetVec3( pilot_offset, 0.0, 0.0, 0.0 ); - - globals->get_options()->set_win_ratio( globals->get_options()->get_xsize() / - globals->get_options()->get_ysize() - ); - -#ifndef USE_FAST_VIEWROT - // This never changes -- NHV - LARC_TO_SSG[0][0] = 0.0; - LARC_TO_SSG[0][1] = 1.0; - LARC_TO_SSG[0][2] = -0.0; - LARC_TO_SSG[0][3] = 0.0; - - LARC_TO_SSG[1][0] = 0.0; - LARC_TO_SSG[1][1] = 0.0; - LARC_TO_SSG[1][2] = 1.0; - LARC_TO_SSG[1][3] = 0.0; - - LARC_TO_SSG[2][0] = 1.0; - LARC_TO_SSG[2][1] = -0.0; - LARC_TO_SSG[2][2] = 0.0; - LARC_TO_SSG[2][3] = 0.0; - - LARC_TO_SSG[3][0] = 0.0; - LARC_TO_SSG[3][1] = 0.0; - LARC_TO_SSG[3][2] = 0.0; - LARC_TO_SSG[3][3] = 1.0; -#endif // USE_FAST_VIEWROT -} - - #define USE_FAST_LOCAL #ifdef USE_FAST_LOCAL inline static void fgMakeLOCAL( sgMat4 dst, const double Theta, diff --git a/src/Main/viewmgr.cxx b/src/Main/viewmgr.cxx new file mode 100644 index 000000000..e9170f0fa --- /dev/null +++ b/src/Main/viewmgr.cxx @@ -0,0 +1,34 @@ +// viewmgr.cxx -- class for managing all the views in the flightgear world. +// +// Written by Curtis Olson, started October 2000. +// +// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ + + +#include "viewmgr.hxx" + + +// Constructor +FGViewMgr::FGViewMgr( void ) { +} + + +// Destructor +FGViewMgr::~FGViewMgr( void ) { +} diff --git a/src/Main/viewmgr.hxx b/src/Main/viewmgr.hxx new file mode 100644 index 000000000..08be5aebf --- /dev/null +++ b/src/Main/viewmgr.hxx @@ -0,0 +1,96 @@ +// viewmgr.hxx -- class for managing all the views in the flightgear world. +// +// Written by Curtis Olson, started October 2000. +// +// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ + + +#ifndef _VIEWMGR_HXX +#define _VIEWMGR_HXX + + +#ifndef __cplusplus +# error This library requires C++ +#endif + + +#include + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "viewer_lookat.hxx" +#include "viewer_rph.hxx" + +FG_USING_STD(vector); + + +// Define a structure containing view information +class FGViewMgr { + +private: + + typedef vector < FGViewer * > viewer_list; + viewer_list views; + + int current; + +public: + + // Constructor + FGViewMgr( void ); + + // Destructor + ~FGViewMgr( void ); + + // getters + inline int size() const { return views.size(); } + inline FGViewer *get_view( int i ) { + if ( i < 0 ) { i = 0; } + if ( i >= (int)views.size() ) { i = views.size() - 1; } + return views[i]; + } + inline FGViewer *next_view() { + ++current; + if ( current >= (int)views.size() ) { + current = 0; + } + return views[current]; + } + inline FGViewer *prev_view() { + --current; + if ( current < 0 ) { + current = views.size() - 1; + } + return views[current]; + } + + // setters + inline void clear() { views.clear(); } + inline void add_view( FGViewer * v ) { + views.push_back(v); + current = views.size() - 1; + } +}; + + +#endif // _VIEWMGR_HXX diff --git a/src/Main/views.cxx b/src/Main/views.cxx deleted file mode 100644 index b9e235304..000000000 --- a/src/Main/views.cxx +++ /dev/null @@ -1,404 +0,0 @@ -// views.cxx -- data structures and routines for managing and view -// parameters. -// -// Written by Curtis Olson, started August 1997. -// -// Copyright (C) 1997 Curtis L. Olson - curt@flightgear.org -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// -// $Id$ - -#error do not compile me - -#include - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include // plib include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "globals.hxx" -#include "views.hxx" - - -// This is a record containing current view parameters for the current -// aircraft position -FGView pilot_view; - -// This is a record containing current view parameters for the current -// view position -FGView current_view; - - -// Constructor -FGView::FGView( void ) { -} - -#define USE_FAST_VIEWROT -#ifdef USE_FAST_VIEWROT -// VIEW_ROT = LARC_TO_SSG * ( VIEWo * VIEW_OFFSET ) -// This takes advantage of the fact that VIEWo and VIEW_OFFSET -// only have entries in the upper 3x3 block -// and that LARC_TO_SSG is just a shift of rows NHV -inline static void fgMakeViewRot( sgMat4 dst, const sgMat4 m1, const sgMat4 m2 ) -{ - for ( int j = 0 ; j < 3 ; j++ ) { - dst[2][j] = m2[0][0] * m1[0][j] + - m2[0][1] * m1[1][j] + - m2[0][2] * m1[2][j]; - - dst[0][j] = m2[1][0] * m1[0][j] + - m2[1][1] * m1[1][j] + - m2[1][2] * m1[2][j]; - - dst[1][j] = m2[2][0] * m1[0][j] + - m2[2][1] * m1[1][j] + - m2[2][2] * m1[2][j]; - } - dst[0][3] = - dst[1][3] = - dst[2][3] = - dst[3][0] = - dst[3][1] = - dst[3][2] = SG_ZERO; - dst[3][3] = SG_ONE; -} -#endif - -// Initialize a view structure -void FGView::Init( void ) { - FG_LOG( FG_VIEW, FG_INFO, "Initializing View parameters" ); - - view_offset = 0.0; - goal_view_offset = 0.0; - sgSetVec3( pilot_offset, 0.0, 0.0, 0.0 ); - - winWidth = current_options.get_xsize(); - winHeight = current_options.get_ysize(); - - set_win_ratio( winHeight / winWidth ); - -#ifndef USE_FAST_VIEWROT - // This never changes -- NHV - LARC_TO_SSG[0][0] = 0.0; - LARC_TO_SSG[0][1] = 1.0; - LARC_TO_SSG[0][2] = -0.0; - LARC_TO_SSG[0][3] = 0.0; - - LARC_TO_SSG[1][0] = 0.0; - LARC_TO_SSG[1][1] = 0.0; - LARC_TO_SSG[1][2] = 1.0; - LARC_TO_SSG[1][3] = 0.0; - - LARC_TO_SSG[2][0] = 1.0; - LARC_TO_SSG[2][1] = -0.0; - LARC_TO_SSG[2][2] = 0.0; - LARC_TO_SSG[2][3] = 0.0; - - LARC_TO_SSG[3][0] = 0.0; - LARC_TO_SSG[3][1] = 0.0; - LARC_TO_SSG[3][2] = 0.0; - LARC_TO_SSG[3][3] = 1.0; -#endif // USE_FAST_VIEWROT - - force_update_fov_math(); -} - - -#define USE_FAST_LOCAL -#ifdef USE_FAST_LOCAL -inline static void fgMakeLOCAL( sgMat4 dst, const double Theta, - const double Phi, const double Psi) -{ - SGfloat cosTheta = (SGfloat) cos(Theta); - SGfloat sinTheta = (SGfloat) sin(Theta); - SGfloat cosPhi = (SGfloat) cos(Phi); - SGfloat sinPhi = (SGfloat) sin(Phi); - SGfloat sinPsi = (SGfloat) sin(Psi) ; - SGfloat cosPsi = (SGfloat) cos(Psi) ; - - dst[0][0] = cosPhi * cosTheta; - dst[0][1] = sinPhi * cosPsi + cosPhi * -sinTheta * -sinPsi; - dst[0][2] = sinPhi * sinPsi + cosPhi * -sinTheta * cosPsi; - dst[0][3] = SG_ZERO; - - dst[1][0] = -sinPhi * cosTheta; - dst[1][1] = cosPhi * cosPsi + -sinPhi * -sinTheta * -sinPsi; - dst[1][2] = cosPhi * sinPsi + -sinPhi * -sinTheta * cosPsi; - dst[1][3] = SG_ZERO ; - - dst[2][0] = sinTheta; - dst[2][1] = cosTheta * -sinPsi; - dst[2][2] = cosTheta * cosPsi; - dst[2][3] = SG_ZERO; - - dst[3][0] = SG_ZERO; - dst[3][1] = SG_ZERO; - dst[3][2] = SG_ZERO; - dst[3][3] = SG_ONE ; -} -#endif - - -// Update the view volume, position, and orientation -void FGView::UpdateViewParams( const FGInterface& f ) { - UpdateViewMath(f); - - if ( ! fgPanelVisible() ) { - xglViewport(0, 0 , (GLint)(winWidth), (GLint)(winHeight) ); - } else { - int view_h = - int((current_panel->getViewHeight() - current_panel->getYOffset()) - * (winHeight / 768.0)); - glViewport(0, (GLint)(winHeight - view_h), - (GLint)(winWidth), (GLint)(view_h) ); - } -} - - -// convert sgMat4 to MAT3 and print -static void print_sgMat4( sgMat4 &in) { - int i, j; - for ( i = 0; i < 4; i++ ) { - for ( j = 0; j < 4; j++ ) { - printf("%10.4f ", in[i][j]); - } - cout << endl; - } -} - - -// Update the view parameters -void FGView::UpdateViewMath( const FGInterface& f ) { - - Point3D p; - sgVec3 v0, minus_z, sgvec, forward; - sgMat4 VIEWo, TMP; - - if ( update_fov ) { - ssgSetFOV( current_options.get_fov(), - current_options.get_fov() * win_ratio ); - update_fov = false; - } - - scenery.center = scenery.next_center; - - // printf("scenery center = %.2f %.2f %.2f\n", scenery.center.x, - // scenery.center.y, scenery.center.z); - - // calculate the cartesion coords of the current lat/lon/0 elev - p = Point3D( f.get_Longitude(), - f.get_Lat_geocentric(), - f.get_Sea_level_radius() * FEET_TO_METER ); - - cur_zero_elev = sgPolarToCart3d(p) - scenery.center; - - // calculate view position in current FG view coordinate system - // p.lon & p.lat are already defined earlier, p.radius was set to - // the sea level radius, so now we add in our altitude. - if ( f.get_Altitude() * FEET_TO_METER > - (scenery.cur_elev + 0.5 * METER_TO_FEET) ) { - p.setz( p.radius() + f.get_Altitude() * FEET_TO_METER ); - } else { - p.setz( p.radius() + scenery.cur_elev + 0.5 * METER_TO_FEET ); - } - - abs_view_pos = sgPolarToCart3d(p); - - view_pos = abs_view_pos - scenery.center; - - FG_LOG( FG_VIEW, FG_DEBUG, "Polar view pos = " << p ); - FG_LOG( FG_VIEW, FG_DEBUG, "Absolute view pos = " << abs_view_pos ); - FG_LOG( FG_VIEW, FG_DEBUG, "Relative view pos = " << view_pos ); - - // code to calculate LOCAL matrix calculated from Phi, Theta, and - // Psi (roll, pitch, yaw) in case we aren't running LaRCsim as our - // flight model - -#ifdef USE_FAST_LOCAL - - fgMakeLOCAL( LOCAL, f.get_Theta(), f.get_Phi(), -f.get_Psi() ); - -#else // USE_TEXT_BOOK_METHOD - - sgVec3 rollvec; - sgSetVec3( rollvec, 0.0, 0.0, 1.0 ); - sgMat4 PHI; // roll - sgMakeRotMat4( PHI, f.get_Phi() * RAD_TO_DEG, rollvec ); - - sgVec3 pitchvec; - sgSetVec3( pitchvec, 0.0, 1.0, 0.0 ); - sgMat4 THETA; // pitch - sgMakeRotMat4( THETA, f.get_Theta() * RAD_TO_DEG, pitchvec ); - - // ROT = PHI * THETA - sgMat4 ROT; - // sgMultMat4( ROT, PHI, THETA ); - sgCopyMat4( ROT, PHI ); - sgPostMultMat4( ROT, THETA ); - - sgVec3 yawvec; - sgSetVec3( yawvec, 1.0, 0.0, 0.0 ); - sgMat4 PSI; // pitch - sgMakeRotMat4( PSI, -f.get_Psi() * RAD_TO_DEG, yawvec ); - - // LOCAL = ROT * PSI - // sgMultMat4( LOCAL, ROT, PSI ); - sgCopyMat4( LOCAL, ROT ); - sgPostMultMat4( LOCAL, PSI ); - -#endif // YIKES - - // cout << "LOCAL matrix" << endl; - // print_sgMat4( LOCAL ); - - sgMakeRotMat4( UP, - f.get_Longitude() * RAD_TO_DEG, - 0.0, - -f.get_Latitude() * RAD_TO_DEG ); - - sgSetVec3( local_up, UP[0][0], UP[0][1], UP[0][2] ); - // sgXformVec3( local_up, UP ); - // cout << "Local Up = " << local_up[0] << "," << local_up[1] << "," - // << local_up[2] << endl; - - // Alternative method to Derive local up vector based on - // *geodetic* coordinates - // alt_up = sgPolarToCart(FG_Longitude, FG_Latitude, 1.0); - // printf( " Alt Up = (%.4f, %.4f, %.4f)\n", - // alt_up.x, alt_up.y, alt_up.z); - - // VIEWo = LOCAL * UP - // sgMultMat4( VIEWo, LOCAL, UP ); - sgCopyMat4( VIEWo, LOCAL ); - sgPostMultMat4( VIEWo, UP ); - // cout << "VIEWo matrix" << endl; - // print_sgMat4( VIEWo ); - - // generate the sg view up and forward vectors - sgSetVec3( view_up, VIEWo[0][0], VIEWo[0][1], VIEWo[0][2] ); - // cout << "view = " << view[0] << "," - // << view[1] << "," << view[2] << endl; - sgSetVec3( forward, VIEWo[2][0], VIEWo[2][1], VIEWo[2][2] ); - // cout << "forward = " << forward[0] << "," - // << forward[1] << "," << forward[2] << endl; - - // generate the pilot offset vector in world coordinates - sgVec3 pilot_offset_world; - sgSetVec3( pilot_offset_world, - pilot_offset[2], pilot_offset[1], -pilot_offset[0] ); - sgXformVec3( pilot_offset_world, pilot_offset_world, VIEWo ); - - // generate the view offset matrix - sgMakeRotMat4( VIEW_OFFSET, view_offset * RAD_TO_DEG, view_up ); - // cout << "VIEW_OFFSET matrix" << endl; - // print_sgMat4( VIEW_OFFSET ); - sgXformVec3( view_forward, forward, VIEW_OFFSET ); - // cout << "view_forward = " << view_forward[0] << "," - // << view_forward[1] << "," << view_forward[2] << endl; - - // VIEW_ROT = LARC_TO_SSG * ( VIEWo * VIEW_OFFSET ) -#ifdef USE_FAST_VIEWROT - fgMakeViewRot( VIEW_ROT, VIEW_OFFSET, VIEWo ); -#else - // sgMultMat4( VIEW_ROT, VIEW_OFFSET, VIEWo ); - // sgPreMultMat4( VIEW_ROT, LARC_TO_SSG ); - sgCopyMat4( VIEW_ROT, VIEWo ); - sgPostMultMat4( VIEW_ROT, VIEW_OFFSET ); - sgPreMultMat4( VIEW_ROT, LARC_TO_SSG ); -#endif - // cout << "VIEW_ROT matrix" << endl; - // print_sgMat4( VIEW_ROT ); - - sgVec3 trans_vec; - sgSetVec3( trans_vec, - view_pos.x() + pilot_offset_world[0], - view_pos.y() + pilot_offset_world[1], - view_pos.z() + pilot_offset_world[2] ); - - // VIEW = VIEW_ROT * TRANS - sgCopyMat4( VIEW, VIEW_ROT ); - sgPostMultMat4ByTransMat4( VIEW, trans_vec ); - - //!!!!!!!!!!!!!!!!!!! - // THIS IS THE EXPERIMENTAL VIEWING ANGLE SHIFTER - // THE MAJORITY OF THE WORK IS DONE IN GUI.CXX - // this in gui.cxx for now just testing - extern float quat_mat[4][4]; - sgPreMultMat4( VIEW, quat_mat); - // !!!!!!!!!! testing - - // make a vector to the current view position - sgSetVec3( v0, view_pos.x(), view_pos.y(), view_pos.z() ); - - // Given a vector pointing straight down (-Z), map into onto the - // local plane representing "horizontal". This should give us the - // local direction for moving "south". - sgSetVec3( minus_z, 0.0, 0.0, -1.0 ); - - sgmap_vec_onto_cur_surface_plane(local_up, v0, minus_z, surface_south); - sgNormalizeVec3(surface_south); - // cout << "Surface direction directly south " << surface_south[0] << "," - // << surface_south[1] << "," << surface_south[2] << endl; - - // now calculate the surface east vector -#define USE_FAST_SURFACE_EAST -#ifdef USE_FAST_SURFACE_EAST - sgVec3 local_down; - sgNegateVec3(local_down, local_up); - sgVectorProductVec3(surface_east, surface_south, local_down); -#else -#define USE_LOCAL_UP -#ifdef USE_LOCAL_UP - sgMakeRotMat4( TMP, FG_PI_2 * RAD_TO_DEG, local_up ); -#else - sgMakeRotMat4( TMP, FG_PI_2 * RAD_TO_DEG, view_up ); -#endif // USE_LOCAL_UP - // cout << "sgMat4 TMP" << endl; - // print_sgMat4( TMP ); - sgXformVec3(surface_east, surface_south, TMP); -#endif // USE_FAST_SURFACE_EAST - // cout << "Surface direction directly east " << surface_east[0] << "," - // << surface_east[1] << "," << surface_east[2] << endl; - // cout << "Should be close to zero = " - // << sgScalarProductVec3(surface_south, surface_east) << endl; -} - - -void FGView::CurrentNormalInLocalPlane(sgVec3 dst, sgVec3 src) { - sgVec3 tmp; - sgSetVec3(tmp, src[0], src[1], src[2] ); - sgMat4 TMP; - sgTransposeNegateMat4 ( TMP, UP ) ; - sgXformVec3(tmp, tmp, TMP); - sgSetVec3(dst, tmp[2], tmp[1], tmp[0] ); -} - - -// Destructor -FGView::~FGView( void ) { -} diff --git a/src/Main/views.hxx b/src/Main/views.hxx deleted file mode 100644 index 15fb85c08..000000000 --- a/src/Main/views.hxx +++ /dev/null @@ -1,205 +0,0 @@ -// views.hxx -- data structures and routines for managing and view parameters. -// -// Written by Curtis Olson, started August 1997. -// -// Copyright (C) 1997 Curtis L. Olson - curt@flightgear.org -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// -// $Id$ - - -#ifndef _VIEWS_HXX -#define _VIEWS_HXX - -#error do not include me! - -#ifndef __cplusplus -# error This library requires C++ -#endif - -#include -#include -#include - -#include - -#include // plib include - -#include -#include