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/globals.hxx>
30 # error This library requires C++
34 // Define a structure containing the control parameters
59 double throttle[MAX_ENGINES];
60 double mixture[MAX_ENGINES];
61 double prop_advance[MAX_ENGINES];
62 double brake[MAX_WHEELS];
65 inline void CLAMP(double *x, double min, double max ) {
66 if ( *x < min ) { *x = min; }
67 if ( *x > max ) { *x = max; }
79 inline double get_aileron() const { return aileron; }
80 inline double get_elevator() const { return elevator; }
81 inline double get_elevator_trim() const { return elevator_trim; }
82 inline double get_rudder() const { return rudder; }
83 inline double get_flaps() const { return flaps; }
84 inline double get_throttle(int engine) const { return throttle[engine]; }
85 inline double get_mixture(int engine) const { return mixture[engine]; }
86 inline double get_prop_advance(int engine) const {
87 return prop_advance[engine];
89 inline double get_brake(int wheel) const { return brake[wheel]; }
92 inline void set_aileron( double pos ) {
94 CLAMP( &aileron, -1.0, 1.0 );
96 // check for autocoordination
97 if ( globals->get_options()->get_auto_coordination() ==
98 FGOptions::FG_AUTO_COORD_ENABLED )
100 set_rudder( aileron / 2.0 );
103 inline void move_aileron( double amt ) {
105 CLAMP( &aileron, -1.0, 1.0 );
107 // check for autocoordination
108 if ( globals->get_options()->get_auto_coordination() ==
109 FGOptions::FG_AUTO_COORD_ENABLED )
111 set_rudder( aileron / 2.0 );
114 inline void set_elevator( double pos ) {
116 CLAMP( &elevator, -1.0, 1.0 );
118 inline void move_elevator( double amt ) {
120 CLAMP( &elevator, -1.0, 1.0 );
122 inline void set_elevator_trim( double pos ) {
124 CLAMP( &elevator_trim, -1.0, 1.0 );
126 inline void move_elevator_trim( double amt ) {
127 elevator_trim += amt;
128 CLAMP( &elevator_trim, -1.0, 1.0 );
130 inline void set_rudder( double pos ) {
132 CLAMP( &rudder, -1.0, 1.0 );
134 inline void move_rudder( double amt ) {
136 CLAMP( &rudder, -1.0, 1.0 );
138 inline void set_flaps( double pos ) {
140 CLAMP( &flaps, 0.0, 1.0 );
142 inline void move_flaps( double amt ) {
144 CLAMP( &flaps, 0.0, 1.0 );
146 inline void set_throttle( int engine, double pos ) {
147 if ( engine == ALL_ENGINES ) {
148 for ( int i = 0; i < MAX_ENGINES; i++ ) {
150 CLAMP( &throttle[i], 0.0, 1.0 );
153 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
154 throttle[engine] = pos;
155 CLAMP( &throttle[engine], 0.0, 1.0 );
159 inline void move_throttle( int engine, double amt ) {
160 if ( engine == ALL_ENGINES ) {
161 for ( int i = 0; i < MAX_ENGINES; i++ ) {
163 CLAMP( &throttle[i], 0.0, 1.0 );
166 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
167 throttle[engine] += amt;
168 CLAMP( &throttle[engine], 0.0, 1.0 );
172 inline void set_mixture( int engine, double pos ) {
173 if ( engine == ALL_ENGINES ) {
174 for ( int i = 0; i < MAX_ENGINES; i++ ) {
176 CLAMP( &mixture[i], 0.0, 1.0 );
179 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
180 mixture[engine] = pos;
181 CLAMP( &mixture[engine], 0.0, 1.0 );
185 inline void move_mixture( int engine, double amt ) {
186 if ( engine == ALL_ENGINES ) {
187 for ( int i = 0; i < MAX_ENGINES; i++ ) {
189 CLAMP( &mixture[i], 0.0, 1.0 );
192 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
193 mixture[engine] += amt;
194 CLAMP( &mixture[engine], 0.0, 1.0 );
198 inline void set_prop_advance( int engine, double pos ) {
199 if ( engine == ALL_ENGINES ) {
200 for ( int i = 0; i < MAX_ENGINES; i++ ) {
201 prop_advance[i] = pos;
202 CLAMP( &prop_advance[i], 0.0, 1.0 );
205 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
206 prop_advance[engine] = pos;
207 CLAMP( &prop_advance[engine], 0.0, 1.0 );
211 inline void move_prop_advance( int engine, double amt ) {
212 if ( engine == ALL_ENGINES ) {
213 for ( int i = 0; i < MAX_ENGINES; i++ ) {
214 prop_advance[i] += amt;
215 CLAMP( &prop_advance[i], 0.0, 1.0 );
218 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
219 prop_advance[engine] += amt;
220 CLAMP( &prop_advance[engine], 0.0, 1.0 );
224 inline void set_brake( int wheel, double pos ) {
225 if ( wheel == ALL_WHEELS ) {
226 for ( int i = 0; i < MAX_WHEELS; i++ ) {
228 CLAMP( &brake[i], 0.0, 1.0 );
231 if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
233 CLAMP( &brake[wheel], 0.0, 1.0 );
237 inline void move_brake( int wheel, double amt ) {
238 if ( wheel == ALL_WHEELS ) {
239 for ( int i = 0; i < MAX_WHEELS; i++ ) {
241 CLAMP( &brake[i], 0.0, 1.0 );
244 if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
246 CLAMP( &brake[wheel], 0.0, 1.0 );
253 extern FGControls controls;
256 #endif // _CONTROLS_HXX