1 // controls.hxx -- defines a standard interface to all flight sim controls
3 // Written by Curtis Olson, started May 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <Main/options.hxx>
30 # error This library requires C++
34 // Define a structure containing the control parameters
58 double throttle[MAX_ENGINES];
59 double brake[MAX_WHEELS];
61 inline void CLAMP(double *x, double min, double max ) {
62 if ( *x < min ) { *x = min; }
63 if ( *x > max ) { *x = max; }
75 inline double get_aileron() const { return aileron; }
76 inline double get_elevator() const { return elevator; }
77 inline double get_elevator_trim() const { return elevator_trim; }
78 inline double get_rudder() const { return rudder; }
79 inline double get_throttle(int engine) const { return throttle[engine]; }
80 inline double get_brake(int wheel) const { return brake[wheel]; }
83 inline void set_aileron( double pos ) {
85 CLAMP( &aileron, -1.0, 1.0 );
87 // check for autocoordination
88 if ( current_options.get_auto_coordination() ==
89 fgOPTIONS::FG_AUTO_COORD_ENABLED )
91 set_rudder( aileron / 2.0 );
94 inline void move_aileron( double amt ) {
96 CLAMP( &aileron, -1.0, 1.0 );
98 // check for autocoordination
99 if ( current_options.get_auto_coordination() ==
100 fgOPTIONS::FG_AUTO_COORD_ENABLED )
102 set_rudder( aileron / 2.0 );
105 inline void set_elevator( double pos ) {
107 CLAMP( &elevator, -1.0, 1.0 );
109 inline void move_elevator( double amt ) {
111 CLAMP( &elevator, -1.0, 1.0 );
113 inline void set_elevator_trim( double pos ) {
115 CLAMP( &elevator_trim, -1.0, 1.0 );
117 inline void move_elevator_trim( double amt ) {
118 elevator_trim += amt;
119 CLAMP( &elevator_trim, -1.0, 1.0 );
121 inline void set_rudder( double pos ) {
123 CLAMP( &rudder, -1.0, 1.0 );
125 inline void move_rudder( double amt ) {
127 CLAMP( &rudder, -1.0, 1.0 );
129 inline void set_throttle( int engine, double pos ) {
130 if ( engine == ALL_ENGINES ) {
131 for ( int i = 0; i < MAX_ENGINES; i++ ) {
133 CLAMP( &throttle[i], 0.0, 1.0 );
136 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
137 throttle[engine] = pos;
138 CLAMP( &throttle[engine], 0.0, 1.0 );
142 inline void move_throttle( int engine, double amt ) {
143 if ( engine == ALL_ENGINES ) {
144 for ( int i = 0; i < MAX_ENGINES; i++ ) {
146 CLAMP( &throttle[i], 0.0, 1.0 );
149 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
150 throttle[engine] += amt;
151 CLAMP( &throttle[engine], 0.0, 1.0 );
155 inline void set_brake( int wheel, double pos ) {
156 if ( wheel == ALL_WHEELS ) {
157 for ( int i = 0; i < MAX_WHEELS; i++ ) {
159 CLAMP( &brake[i], 0.0, 1.0 );
162 if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
164 CLAMP( &brake[wheel], 0.0, 1.0 );
168 inline void move_brake( int wheel, double amt ) {
169 if ( wheel == ALL_WHEELS ) {
170 for ( int i = 0; i < MAX_WHEELS; i++ ) {
172 CLAMP( &brake[i], 0.0, 1.0 );
175 if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
177 CLAMP( &brake[wheel], 0.0, 1.0 );
184 extern FGControls controls;
187 #endif // _CONTROLS_HXX