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();
}
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 \
&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());
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());
#include <simgear/timing/sg_time.hxx>
#include "options.hxx"
-#include "viewer_rph.hxx"
+#include "viewmgr.hxx"
class FGGlobals {
// options
FGOptions *options;
- // viewers
- FGViewerRPH *current_view;
+ // viewer maneger
+ FGViewMgr *viewmgr;
+ FGViewer *current_view;
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; }
};
// 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) ) {
// 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 );
#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
// 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
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();
} 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);
}
# 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();
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);
} 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 ) );
}
-// 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" );
// Destructor
virtual ~FGViewer( void );
- // Initialize a view class
- virtual void init( void );
-
//////////////////////////////////////////////////////////////////////
// setter functions
//////////////////////////////////////////////////////////////////////
}
-// 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;
// Destructor
~FGViewerLookAt( void );
- // Initialize a view class
- void init( void );
-
//////////////////////////////////////////////////////////////////////
// setter functions
//////////////////////////////////////////////////////////////////////
// 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
}
#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,
--- /dev/null
+// 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 ) {
+}
--- /dev/null
+// 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 <simgear/compiler.h>
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <vector>
+
+#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
+++ /dev/null
-// 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 <simgear/compiler.h>
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <plib/ssg.h> // plib include
-
-#include <simgear/constants.h>
-#include <simgear/debug/logstream.hxx>
-#include <simgear/math/point3d.hxx>
-#include <simgear/math/polar3d.hxx>
-#include <simgear/math/vector.hxx>
-
-#include <Aircraft/aircraft.hxx>
-#include <Cockpit/panel.hxx>
-#include <Scenery/scenery.hxx>
-
-#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 ) {
-}
+++ /dev/null
-// 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 <simgear/compiler.h>
-#include <simgear/math/point3d.hxx>
-#include <simgear/timing/sg_time.hxx>
-
-#include <list>
-
-#include <plib/sg.h> // plib include
-
-#include <FDM/flight.hxx>
-#include <Time/light.hxx>
-
-FG_USING_STD(list);
-
-
-#define FG_FOV_MIN 0.1
-#define FG_FOV_MAX 179.9
-
-
-// Define a structure containing view information
-class FGView {
-
-public:
-
- // the current offset from forward for viewing
- double view_offset;
-
- // the goal view offset for viewing (used for smooth view changes)
- double goal_view_offset;
-
- // flag forcing update of fov related stuff
- bool update_fov;
-
- // fov of view is specified in the y direction, win_ratio is used to
- // calculate the fov in the X direction = width / height
- double win_ratio;
-
- // width & height of window
- int winWidth, winHeight;
-
- // absolute view position in earth coordinates
- Point3D abs_view_pos;
-
- // view position in opengl world coordinates (this is the
- // abs_view_pos translated to scenery.center)
- Point3D view_pos;
-
- // pilot offset from center of gravity. The X axis is positive
- // out the tail, Y is out the right wing, and Z is positive up.
- // Distances in meters of course.
- sgVec3 pilot_offset;
-
- // cartesion coordinates of current lon/lat if at sea level
- // translated to scenery.center
- Point3D cur_zero_elev;
-
- // vector in cartesian coordinates from current position to the
- // postion on the earth's surface the sun is directly over
- sgVec3 to_sun;
-
- // surface direction to go to head towards sun
- sgVec3 surface_to_sun;
-
- // vector in cartesian coordinates from current position to the
- // postion on the earth's surface the moon is directly over
- sgVec3 to_moon;
-
- // surface direction to go to head towards moon
- sgVec3 surface_to_moon;
-
- // surface vector heading south
- sgVec3 surface_south;
-
- // surface vector heading east (used to unambiguously align sky
- // with sun)
- sgVec3 surface_east;
-
- // local up vector (normal to the plane tangent to the earth's
- // surface at the spot we are directly above
- sgVec3 local_up;
-
- // up vector for the view (usually point straight up through the
- // top of the aircraft
- sgVec3 view_up;
-
- // the vector pointing straight out the nose of the aircraft
- sgVec3 view_forward;
-
- // Transformation matrix for eye coordinates to aircraft coordinates
- // sgMat4 AIRCRAFT;
-
- // Transformation matrix for the view direction offset relative to
- // the AIRCRAFT matrix
- sgMat4 VIEW_OFFSET;
-
- // sg versions of our friendly matrices
- sgMat4 LOCAL, UP, VIEW_ROT, TRANS, VIEW, LARC_TO_SSG;
-
-public:
-
- // Constructor
- FGView( void );
-
- // Destructor
- ~FGView( void );
-
- // Initialize a view class
- void Init( void );
-
- // Update the view volume, position, and orientation
- void UpdateViewParams( const FGInterface& f );
-
- // Flag to request that UpdateFOV() be called next time
- // UpdateViewMath() is run.
- inline void force_update_fov_math() { update_fov = true; }
-
- // Update the view parameters
- void UpdateViewMath( const FGInterface& f );
-
- // Update the field of view coefficients
- void UpdateFOV( const fgOPTIONS& o );
-
- // Transform a vector from world coordinates to the local plane
- void CurrentNormalInLocalPlane(sgVec3 dst, sgVec3 src);
-
- // accessor functions
- inline double get_view_offset() const { return view_offset; }
- inline void set_view_offset( double a ) { view_offset = a; }
- inline void inc_view_offset( double amt ) { view_offset += amt; }
- inline double get_goal_view_offset() const { return goal_view_offset; }
- inline void set_goal_view_offset( double a) { goal_view_offset = a; }
- inline double get_win_ratio() const { return win_ratio; }
- inline void set_win_ratio( double r ) { win_ratio = r; }
- inline int get_winWidth() const { return winWidth; }
- inline void set_winWidth( int w ) { winWidth = w; }
- inline int get_winHeight() const { return winHeight; }
- inline void set_winHeight( int h ) { winHeight = h; }
- inline Point3D get_abs_view_pos() const { return abs_view_pos; }
- inline Point3D get_view_pos() const { return view_pos; }
- inline float *get_pilot_offset() { return pilot_offset; }
- inline void set_pilot_offset( float x, float y, float z ) {
- sgSetVec3( pilot_offset, x, y, z );
- }
- inline Point3D get_cur_zero_elev() const { return cur_zero_elev; }
- inline float *get_to_sun() { return to_sun; }
- inline void set_to_sun( float x, float y, float z ) {
- sgSetVec3( to_sun, x, y, z );
- }
- inline float *get_surface_to_sun() { return surface_to_sun; }
- inline void set_surface_to_sun( float x, float y, float z) {
- sgSetVec3( surface_to_sun, x, y, z );
- }
- inline float *get_to_moon() { return to_moon; }
- inline void set_to_moon( float x, float y, float z) {
- sgSetVec3( to_moon, x, y, z );
- }
- inline float *get_surface_to_moon() { return surface_to_moon; }
- inline void set_surface_to_moon( float x, float y, float z) {
- sgSetVec3( surface_to_moon, x, y, z );
- }
- inline float *get_surface_south() { return surface_south; }
- inline float *get_surface_east() { return surface_east; }
- inline float *get_local_up() { return local_up; }
- inline float *get_view_forward() { return view_forward; }
-};
-
-
-extern FGView pilot_view;
-extern FGView current_view;
-
-
-#endif // _VIEWS_HXX
-
-
l = &cur_light_params;
SGTime *t = globals->get_time_params();
- v = globals->get_current_view();
+ v = (FGViewerRPH *)globals->get_current_view();
FG_LOG( FG_EVENT, FG_INFO, " Updating Moon position" );
l = &cur_light_params;
SGTime *t = globals->get_time_params();
- v = globals->get_current_view();
+ v = (FGViewerRPH *)globals->get_current_view();
FG_LOG( FG_EVENT, FG_INFO, " Updating Sun position" );
FG_LOG( FG_EVENT, FG_INFO, " Gst = " << t->getGst() );