From 5f5905f6e8f6e0679fef044de58d3377fed4ea32 Mon Sep 17 00:00:00 2001 From: curt Date: Sat, 9 Oct 1999 13:09:16 +0000 Subject: [PATCH] Updates by norman vine to controls.hxx. Joystick auto-coordination tweaks. Additional debuging output when pausing and resuming the sim. Window resizing tweaks by David Megginson (and Norman Vine). --- src/Controls/controls.hxx | 57 ++++++++++++++++----------------------- src/FDM/LaRCsim.cxx | 4 +-- src/FDM/flight.hxx | 8 +++--- src/Joystick/joystick.cxx | 12 +++++++-- src/Main/keyboard.cxx | 31 ++++++++++++++------- src/Main/main.cxx | 3 +++ 6 files changed, 64 insertions(+), 51 deletions(-) diff --git a/src/Controls/controls.hxx b/src/Controls/controls.hxx index 690e9b11c..3aff6ba2a 100644 --- a/src/Controls/controls.hxx +++ b/src/Controls/controls.hxx @@ -58,6 +58,11 @@ private: double throttle[MAX_ENGINES]; double brake[MAX_WHEELS]; + inline void CLAMP(double *x, double min, double max ) { + if ( *x < min ) { *x = min; } + if ( *x > max ) { *x = max; } + } + public: FGControls(); @@ -77,9 +82,8 @@ public: // Update functions inline void set_aileron( double pos ) { aileron = pos; - if ( aileron < -1.0 ) aileron = -1.0; - if ( aileron > 1.0 ) aileron = 1.0; - + CLAMP( &aileron, -1.0, 1.0 ); + // check for autocoordination if ( current_options.get_auto_coordination() == fgOPTIONS::FG_AUTO_COORD_ENABLED ) @@ -89,9 +93,8 @@ public: } inline void move_aileron( double amt ) { aileron += amt; - if ( aileron < -1.0 ) aileron = -1.0; - if ( aileron > 1.0 ) aileron = 1.0; - + CLAMP( &aileron, -1.0, 1.0 ); + // check for autocoordination if ( current_options.get_auto_coordination() == fgOPTIONS::FG_AUTO_COORD_ENABLED ) @@ -101,46 +104,38 @@ public: } inline void set_elevator( double pos ) { elevator = pos; - if ( elevator < -1.0 ) elevator = -1.0; - if ( elevator > 1.0 ) elevator = 1.0; + CLAMP( &elevator, -1.0, 1.0 ); } inline void move_elevator( double amt ) { elevator += amt; - if ( elevator < -1.0 ) elevator = -1.0; - if ( elevator > 1.0 ) elevator = 1.0; + CLAMP( &elevator, -1.0, 1.0 ); } inline void set_elevator_trim( double pos ) { elevator_trim = pos; - if ( elevator_trim < -1.0 ) elevator_trim = -1.0; - if ( elevator_trim > 1.0 ) elevator_trim = 1.0; + CLAMP( &elevator_trim, -1.0, 1.0 ); } inline void move_elevator_trim( double amt ) { elevator_trim += amt; - if ( elevator_trim < -1.0 ) elevator_trim = -1.0; - if ( elevator_trim > 1.0 ) elevator_trim = 1.0; + CLAMP( &elevator_trim, -1.0, 1.0 ); } inline void set_rudder( double pos ) { rudder = pos; - if ( rudder < -1.0 ) rudder = -1.0; - if ( rudder > 1.0 ) rudder = 1.0; + CLAMP( &rudder, -1.0, 1.0 ); } inline void move_rudder( double amt ) { rudder += amt; - if ( rudder < -1.0 ) rudder = -1.0; - if ( rudder > 1.0 ) rudder = 1.0; + CLAMP( &rudder, -1.0, 1.0 ); } inline void set_throttle( int engine, double pos ) { if ( engine == ALL_ENGINES ) { for ( int i = 0; i < MAX_ENGINES; i++ ) { throttle[i] = pos; - if ( throttle[i] < 0.0 ) throttle[i] = 0.0; - if ( throttle[i] > 1.0 ) throttle[i] = 1.0; + CLAMP( &throttle[i], 0.0, 1.0 ); } } else { if ( (engine >= 0) && (engine < MAX_ENGINES) ) { throttle[engine] = pos; - if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0; - if ( throttle[engine] > 1.0 ) throttle[engine] = 1.0; + CLAMP( &throttle[engine], 0.0, 1.0 ); } } } @@ -148,14 +143,12 @@ public: if ( engine == ALL_ENGINES ) { for ( int i = 0; i < MAX_ENGINES; i++ ) { throttle[i] += amt; - if ( throttle[i] < 0.0 ) throttle[i] = 0.0; - if ( throttle[i] > 1.0 ) throttle[i] = 1.0; + CLAMP( &throttle[i], 0.0, 1.0 ); } } else { if ( (engine >= 0) && (engine < MAX_ENGINES) ) { throttle[engine] += amt; - if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0; - if ( throttle[engine] > 1.0 ) throttle[engine] = 1.0; + CLAMP( &throttle[engine], 0.0, 1.0 ); } } } @@ -163,14 +156,12 @@ public: if ( wheel == ALL_WHEELS ) { for ( int i = 0; i < MAX_WHEELS; i++ ) { brake[i] = pos; - if ( brake[i] < 0.0 ) brake[i] = 0.0; - if ( brake[i] > 1.0 ) brake[i] = 1.0; + CLAMP( &brake[i], 0.0, 1.0 ); } } else { if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) { brake[wheel] = pos; - if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0; - if ( brake[wheel] > 1.0 ) brake[wheel] = 1.0; + CLAMP( &brake[wheel], 0.0, 1.0 ); } } } @@ -178,14 +169,12 @@ public: if ( wheel == ALL_WHEELS ) { for ( int i = 0; i < MAX_WHEELS; i++ ) { brake[i] += amt; - if ( brake[i] < 0.0 ) brake[i] = 0.0; - if ( brake[i] > 1.0 ) brake[i] = 1.0; + CLAMP( &brake[i], 0.0, 1.0 ); } } else { if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) { brake[wheel] += amt; - if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0; - if ( brake[wheel] > 1.0 ) brake[wheel] = 1.0; + CLAMP( &brake[wheel], 0.0, 1.0 ); } } } diff --git a/src/FDM/LaRCsim.cxx b/src/FDM/LaRCsim.cxx index 66b8a9cbb..7602bb5d8 100644 --- a/src/FDM/LaRCsim.cxx +++ b/src/FDM/LaRCsim.cxx @@ -360,9 +360,9 @@ int fgLaRCsim_2_FGInterface (FGInterface& f) { // f.set_Cos_beta( Cos_beta ); // f.set_Sin_beta( Sin_beta ); - // f.set_Cos_phi( Cos_phi ); + f.set_Cos_phi( Cos_phi ); // f.set_Sin_phi( Sin_phi ); - // f.set_Cos_theta( Cos_theta ); + f.set_Cos_theta( Cos_theta ); // f.set_Sin_theta( Sin_theta ); // f.set_Cos_psi( Cos_psi ); // f.set_Sin_psi( Sin_psi ); diff --git a/src/FDM/flight.hxx b/src/FDM/flight.hxx index 2e3d79394..529a320ca 100644 --- a/src/FDM/flight.hxx +++ b/src/FDM/flight.hxx @@ -665,12 +665,12 @@ public: // inline void set_Sin_beta( double sb ) { sin_beta = sb; } double cos_phi, sin_phi, cos_theta, sin_theta, cos_psi, sin_psi; - // inline double get_Cos_phi() const { return cos_phi; } - // inline void set_Cos_phi( double cp ) { cos_phi = cp; } + inline double get_Cos_phi() const { return cos_phi; } + inline void set_Cos_phi( double cp ) { cos_phi = cp; } // inline double get_Sin_phi() const { return sin_phi; } // inline void set_Sin_phi( double sp ) { sin_phi = sp; } - // inline double get_Cos_theta() const { return cos_theta; } - // inline void set_Cos_theta( double ct ) { cos_theta = ct; } + inline double get_Cos_theta() const { return cos_theta; } + inline void set_Cos_theta( double ct ) { cos_theta = ct; } // inline double get_Sin_theta() const { return sin_theta; } // inline void set_Sin_theta( double st ) { sin_theta = st; } // inline double get_Cos_psi() const { return cos_psi; } diff --git a/src/Joystick/joystick.cxx b/src/Joystick/joystick.cxx index 1f766e363..35cd5951e 100644 --- a/src/Joystick/joystick.cxx +++ b/src/Joystick/joystick.cxx @@ -208,7 +208,11 @@ int fgJoystickRead( void ) { ((-js_ax0[2] + 1) / 2) ); } if ( js0->getNumAxes() > 3 ) { - controls.set_rudder( js_ax0[3] ); + if ( current_options.get_auto_coordination() != + fgOPTIONS::FG_AUTO_COORD_ENABLED ) + { + controls.set_rudder( js_ax0[3] ); + } } // End of William's code @@ -216,7 +220,11 @@ int fgJoystickRead( void ) { if ( ! js1->notWorking() ) { js1->read( &b, js_ax1 ) ; - controls.set_rudder( js_ax1[0] ); + if ( current_options.get_auto_coordination() != + fgOPTIONS::FG_AUTO_COORD_ENABLED ) + { + controls.set_rudder( js_ax1[0] ); + } controls.set_throttle( FGControls::ALL_ENGINES, -js_ax1[1] * 1.05 ); } diff --git a/src/Main/keyboard.cxx b/src/Main/keyboard.cxx index 5063874d0..67296cab5 100644 --- a/src/Main/keyboard.cxx +++ b/src/Main/keyboard.cxx @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include