From 2eda8480e98dfe8b2a8dbde097d86ca6fe8bbe7e Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 18 Oct 2000 21:19:30 +0000 Subject: [PATCH] Some changes contributed by David Megginson to allow for more interesting external views. --- src/Cockpit/hud_ladr.cxx | 3 +- src/Cockpit/panel.cxx | 13 ++++++- src/Cockpit/panel.hxx | 8 ++++ src/Main/bfi.cxx | 5 ++- src/Main/fg_init.cxx | 9 +++++ src/Main/keyboard.cxx | 79 +++++++++++++++++++++++++++++++++++++++- src/Main/main.cxx | 36 ++++++++++++++---- src/Main/views.cxx | 2 +- 8 files changed, 141 insertions(+), 14 deletions(-) diff --git a/src/Cockpit/hud_ladr.cxx b/src/Cockpit/hud_ladr.cxx index 08cf1980e..2a62b4d50 100644 --- a/src/Cockpit/hud_ladr.cxx +++ b/src/Cockpit/hud_ladr.cxx @@ -1,5 +1,6 @@ #include "hud.hxx" +#include "panel.hxx" #define DO_PANEL_HACK @@ -219,7 +220,7 @@ void HudLadder :: draw( void ) glEnable(GL_LINE_STIPPLE); #ifdef DO_PANEL_HACK - glLineStipple( 1, current_options.get_panel_status() ? 0x0F0F : 0x00FF ); + glLineStipple( 1, fgPanelVisible() ? 0x0F0F : 0x00FF ); #else glLineStipple( 1, 0x00FF ); #endif diff --git a/src/Cockpit/panel.cxx b/src/Cockpit/panel.cxx index 16168f8c8..7de4b43ea 100644 --- a/src/Cockpit/panel.cxx +++ b/src/Cockpit/panel.cxx @@ -41,6 +41,15 @@ #include "panel.hxx" +bool +fgPanelVisible () +{ + return ((current_options.get_panel_status()) && + (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_PILOT) && + (current_view.get_view_offset() == 0.0)); +} + + //////////////////////////////////////////////////////////////////////// // Implementation of FGTextureManager. @@ -125,7 +134,7 @@ FGPanel::FGPanel (int window_x, int window_y, int window_w, int window_h) _width(_winw), _height(int(_winh * 0.5768 + 1)), _x_offset(0), _y_offset(0), _view_height(int(_winh * 0.4232)) { - setVisibility(current_options.get_panel_status()); + setVisibility(fgPanelVisible()); } @@ -160,7 +169,7 @@ void FGPanel::update () const { // Do nothing if the panel isn't visible. - if (!_visibility) + if (!fgPanelVisible()) return; // If the mouse is down, do something diff --git a/src/Cockpit/panel.hxx b/src/Cockpit/panel.hxx index 25c0037ac..c8e8c606c 100644 --- a/src/Cockpit/panel.hxx +++ b/src/Cockpit/panel.hxx @@ -567,6 +567,14 @@ private: }; + +//////////////////////////////////////////////////////////////////////// +// Functions. +//////////////////////////////////////////////////////////////////////// + +bool fgPanelVisible (); + + //////////////////////////////////////////////////////////////////////// // The current panel, if any. diff --git a/src/Main/bfi.cxx b/src/Main/bfi.cxx index 886d7d3a8..89c2b952d 100644 --- a/src/Main/bfi.cxx +++ b/src/Main/bfi.cxx @@ -111,7 +111,8 @@ FGBFI::init () current_properties.tieDouble("/position/longitude", getLongitude, setLongitude); current_properties.tieDouble("/position/altitude", - getAltitude, setAltitude); + // getAltitude, setAltitude); + getAltitude, setAltitude, false); current_properties.tieDouble("/position/altitude-agl", getAGL, 0); @@ -234,6 +235,8 @@ FGBFI::init () current_properties.tieDouble("/environment/visibility", getVisibility, setVisibility); + _needReinit = false; + FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init"); } diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index c89aafab8..1027381cc 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -346,6 +346,15 @@ bool fgInitPosition( void ) { fgFDMSetGroundElevation( current_options.get_flight_model(), f->get_Altitude() * FEET_TO_METER ); +#if 0 + current_properties.setDoubleValue("/position/longitude", + f->get_Longitude() * RAD_TO_DEG); + current_properties.setDoubleValue("/position/latitude", + f->get_Latitude() * RAD_TO_DEG); + current_properties.setDoubleValue("/position/altitude", + f->get_Altitude() * RAD_TO_DEG); +#endif + FG_LOG( FG_GENERAL, FG_INFO, "Initial position is: (" << (f->get_Longitude() * RAD_TO_DEG) << ", " diff --git a/src/Main/keyboard.cxx b/src/Main/keyboard.cxx index 624a087b9..8606a2864 100644 --- a/src/Main/keyboard.cxx +++ b/src/Main/keyboard.cxx @@ -158,27 +158,59 @@ void GLUTkey(unsigned char k, int x, int y) { return; case 49: // numeric keypad 1 v->set_goal_view_offset( FG_PI * 0.75 ); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + pilot_view.set_pilot_offset(-25.0, 25.0, 1.0); + v->set_view_offset( FG_PI * 0.75 ); + } return; case 50: // numeric keypad 2 v->set_goal_view_offset( FG_PI ); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + pilot_view.set_pilot_offset(-25.0, 0.0, 1.0); + v->set_view_offset( FG_PI ); + } return; case 51: // numeric keypad 3 v->set_goal_view_offset( FG_PI * 1.25 ); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + pilot_view.set_pilot_offset(-25.0, -25.0, 1.0); + v->set_view_offset( FG_PI * 1.25 ); + } return; case 52: // numeric keypad 4 v->set_goal_view_offset( FG_PI * 0.50 ); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + pilot_view.set_pilot_offset(0.0, 25.0, 1.0); + v->set_view_offset( FG_PI * 0.50 ); + } return; case 54: // numeric keypad 6 v->set_goal_view_offset( FG_PI * 1.50 ); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + pilot_view.set_pilot_offset(0.0, -25.0, 1.0); + v->set_view_offset( FG_PI * 1.50 ); + } return; case 55: // numeric keypad 7 v->set_goal_view_offset( FG_PI * 0.25 ); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + pilot_view.set_pilot_offset(25.0, 25.0, 1.0); + v->set_view_offset( FG_PI * 0.25 ); + } return; case 56: // numeric keypad 8 v->set_goal_view_offset( 0.00 ); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + pilot_view.set_pilot_offset(25.0, 0.0, 1.0); + v->set_view_offset( 0.00 ); + } return; case 57: // numeric keypad 9 v->set_goal_view_offset( FG_PI * 1.75 ); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + pilot_view.set_pilot_offset(25.0, -25.0, 1.0); + v->set_view_offset( FG_PI * 1.75 ); + } return; case 65: // A key speed = current_options.get_speed_up(); @@ -375,7 +407,20 @@ void GLUTkey(unsigned char k, int x, int y) { fgUpdateSkyAndLightingParams(); return; case 118: // v key - current_options.cycle_view_mode(); +// current_options.cycle_view_mode(); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + current_options.set_view_mode(fgOPTIONS::FG_VIEW_PILOT); + v->set_goal_view_offset( 0.0 ); + v->set_view_offset( 0.0 ); + } else if (current_options.get_view_mode() == + fgOPTIONS::FG_VIEW_PILOT) { + current_options.set_view_mode(fgOPTIONS::FG_VIEW_FOLLOW); + v->set_goal_view_offset( FG_PI * 1.75 ); + v->set_view_offset( FG_PI * 1.75 ); + pilot_view.set_pilot_offset(25.0, -25.0, 1.0); + } + fgReshape( current_view.get_winWidth(), + current_view.get_winHeight() ); return; case 120: // x key fov = current_options.get_fov(); @@ -496,27 +541,59 @@ void GLUTspecialkey(int k, int x, int y) { } case GLUT_KEY_END: // numeric keypad 1 v->set_goal_view_offset( FG_PI * 0.75 ); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + pilot_view.set_pilot_offset(-25.0, 25.0, 1.0); + v->set_view_offset( FG_PI * 0.75 ); + } return; case GLUT_KEY_DOWN: // numeric keypad 2 v->set_goal_view_offset( FG_PI ); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + pilot_view.set_pilot_offset(-25.0, 0.0, 1.0); + v->set_view_offset( FG_PI ); + } return; case GLUT_KEY_PAGE_DOWN: // numeric keypad 3 v->set_goal_view_offset( FG_PI * 1.25 ); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + pilot_view.set_pilot_offset(-25.0, -25.0, 1.0); + v->set_view_offset( FG_PI * 1.25 ); + } return; case GLUT_KEY_LEFT: // numeric keypad 4 v->set_goal_view_offset( FG_PI * 0.50 ); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + pilot_view.set_pilot_offset(0.0, 25.0, 1.0); + v->set_view_offset( FG_PI * 0.50 ); + } return; case GLUT_KEY_RIGHT: // numeric keypad 6 v->set_goal_view_offset( FG_PI * 1.50 ); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + pilot_view.set_pilot_offset(0.0, -25.0, 1.0); + v->set_view_offset( FG_PI * 1.50 ); + } return; case GLUT_KEY_HOME: // numeric keypad 7 v->set_goal_view_offset( FG_PI * 0.25 ); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + pilot_view.set_pilot_offset(25.0, 25.0, 1.0); + v->set_view_offset( FG_PI * 0.25 ); + } return; case GLUT_KEY_UP: // numeric keypad 8 v->set_goal_view_offset( 0.00 ); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + pilot_view.set_pilot_offset(25.0, 0.0, 1.0); + v->set_view_offset( 0.00 ); + } return; case GLUT_KEY_PAGE_UP: // numeric keypad 9 v->set_goal_view_offset( FG_PI * 1.75 ); + if (current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW) { + pilot_view.set_pilot_offset(25.0, -25.0, 1.0); + v->set_view_offset( FG_PI * 1.75 ); + } return; } } else { diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 67e4aa02c..b672be5b8 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -308,6 +308,12 @@ void fgRenderFrame( void ) { // update view volume parameters // cout << "before pilot_view update" << endl; + if ( current_options.get_view_mode() == fgOPTIONS::FG_VIEW_FOLLOW ) { + float * offset = pilot_view.get_pilot_offset(); + current_view.set_pilot_offset(offset[0], offset[1], offset[2]); + } else { + current_view.set_pilot_offset(0.0, 0.0, 0.0); + } pilot_view.UpdateViewParams(*cur_fdm_state); // cout << "after pilot_view update" << endl; current_view.UpdateViewParams(cur_view_fdm); @@ -1106,7 +1112,7 @@ static void fgIdleFunction ( void ) { // options.cxx needs to see this for toggle_panel() // Handle new window size or exposure void fgReshape( int width, int height ) { - if ( ! current_options.get_panel_status() || idle_state != 1000 ) { + if ( ! fgPanelVisible() || idle_state != 1000 ) { current_view.set_win_ratio( (float)height / (float)width ); glViewport(0, 0 , (GLint)(width), (GLint)(height) ); } else { @@ -1410,8 +1416,8 @@ int main( int argc, char **argv ) { // FGPath modelpath( current_options.get_fg_root() ); - modelpath.append( "Models" ); - modelpath.append( "Geometry" ); + // modelpath.append( "Models" ); + // modelpath.append( "Geometry" ); FGPath texturepath( current_options.get_fg_root() ); texturepath.append( "Models" ); @@ -1466,11 +1472,25 @@ int main( int argc, char **argv ) { // temporary visible aircraft "own ship" penguin_sel = new ssgSelector; penguin_pos = new ssgTransform; - // ssgBranch *tux_obj = ssgMakeSphere( 10.0, 10, 10 ); - ssgEntity *tux_obj = ssgLoadAC( "glider.ac" ); - // ssgEntity *tux_obj = ssgLoadAC( "Tower1x.ac" ); - - penguin_pos->addKid( tux_obj ); + string tux_path = + current_properties.getStringValue("/sim/model/path", + "Models/Geometry/glider.ac"); + ssgEntity *tux_obj = ssgLoad((char *)(tux_path.c_str())); + + // align the model properly for FGFS + ssgTransform *tux_align = new ssgTransform; + tux_align->addKid(tux_obj); + sgMat4 tux_matrix; + float h_rot = + current_properties.getFloatValue("/sim/model/h-rotation", 0.0); + float p_rot = + current_properties.getFloatValue("/sim/model/p-rotation", 0.0); + float r_rot = + current_properties.getFloatValue("/sim/model/r-rotation", 0.0); + sgMakeRotMat4(tux_matrix, h_rot, h_rot, r_rot); + tux_align->setTransform(tux_matrix); + + penguin_pos->addKid( tux_align ); penguin_sel->addKid( penguin_pos ); ssgFlatten( tux_obj ); ssgStripify( penguin_sel ); diff --git a/src/Main/views.cxx b/src/Main/views.cxx index 240aefc6e..91118cf8e 100644 --- a/src/Main/views.cxx +++ b/src/Main/views.cxx @@ -166,7 +166,7 @@ inline static void fgMakeLOCAL( sgMat4 dst, const double Theta, void FGView::UpdateViewParams( const FGInterface& f ) { UpdateViewMath(f); - if ( ! current_options.get_panel_status() ) { + if ( ! fgPanelVisible() ) { xglViewport(0, 0 , (GLint)(winWidth), (GLint)(winHeight) ); } else { int view_h = -- 2.39.5