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/fgfs.hxx>
28 #include <Main/globals.hxx>
31 # error This library requires C++
35 // Define a structure containing the control parameters
37 class FGControls : public FGSubsystem
61 double throttle[MAX_ENGINES];
62 double mixture[MAX_ENGINES];
63 double prop_advance[MAX_ENGINES];
64 double brake[MAX_WHEELS];
67 inline void CLAMP(double *x, double min, double max ) {
68 if ( *x < min ) { *x = min; }
69 if ( *x > max ) { *x = max; }
77 // Implementation of FGSubsystem.
87 inline double get_aileron() const { return aileron; }
88 inline double get_elevator() const { return elevator; }
89 inline double get_elevator_trim() const { return elevator_trim; }
90 inline double get_rudder() const { return rudder; }
91 inline double get_flaps() const { return flaps; }
92 inline double get_throttle(int engine) const { return throttle[engine]; }
93 inline double get_mixture(int engine) const { return mixture[engine]; }
94 inline double get_prop_advance(int engine) const {
95 return prop_advance[engine];
97 inline double get_brake(int wheel) const { return brake[wheel]; }
100 inline void set_aileron( double pos ) {
102 CLAMP( &aileron, -1.0, 1.0 );
104 // check for autocoordination
105 if ( globals->get_options()->get_auto_coordination() ==
106 FGOptions::FG_AUTO_COORD_ENABLED )
108 set_rudder( aileron / 2.0 );
111 inline void move_aileron( double amt ) {
113 CLAMP( &aileron, -1.0, 1.0 );
115 // check for autocoordination
116 if ( globals->get_options()->get_auto_coordination() ==
117 FGOptions::FG_AUTO_COORD_ENABLED )
119 set_rudder( aileron / 2.0 );
122 inline void set_elevator( double pos ) {
124 CLAMP( &elevator, -1.0, 1.0 );
126 inline void move_elevator( double amt ) {
128 CLAMP( &elevator, -1.0, 1.0 );
130 inline void set_elevator_trim( double pos ) {
132 CLAMP( &elevator_trim, -1.0, 1.0 );
134 inline void move_elevator_trim( double amt ) {
135 elevator_trim += amt;
136 CLAMP( &elevator_trim, -1.0, 1.0 );
138 inline void set_rudder( double pos ) {
140 CLAMP( &rudder, -1.0, 1.0 );
142 inline void move_rudder( double amt ) {
144 CLAMP( &rudder, -1.0, 1.0 );
146 inline void set_flaps( double pos ) {
148 CLAMP( &flaps, 0.0, 1.0 );
150 inline void move_flaps( double amt ) {
152 CLAMP( &flaps, 0.0, 1.0 );
154 inline void set_throttle( int engine, double pos ) {
155 if ( engine == ALL_ENGINES ) {
156 for ( int i = 0; i < MAX_ENGINES; i++ ) {
158 CLAMP( &throttle[i], 0.0, 1.0 );
161 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
162 throttle[engine] = pos;
163 CLAMP( &throttle[engine], 0.0, 1.0 );
167 inline void move_throttle( int engine, double amt ) {
168 if ( engine == ALL_ENGINES ) {
169 for ( int i = 0; i < MAX_ENGINES; i++ ) {
171 CLAMP( &throttle[i], 0.0, 1.0 );
174 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
175 throttle[engine] += amt;
176 CLAMP( &throttle[engine], 0.0, 1.0 );
180 inline void set_mixture( int engine, double pos ) {
181 if ( engine == ALL_ENGINES ) {
182 for ( int i = 0; i < MAX_ENGINES; i++ ) {
184 CLAMP( &mixture[i], 0.0, 1.0 );
187 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
188 mixture[engine] = pos;
189 CLAMP( &mixture[engine], 0.0, 1.0 );
193 inline void move_mixture( int engine, double amt ) {
194 if ( engine == ALL_ENGINES ) {
195 for ( int i = 0; i < MAX_ENGINES; i++ ) {
197 CLAMP( &mixture[i], 0.0, 1.0 );
200 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
201 mixture[engine] += amt;
202 CLAMP( &mixture[engine], 0.0, 1.0 );
206 inline void set_prop_advance( int engine, double pos ) {
207 if ( engine == ALL_ENGINES ) {
208 for ( int i = 0; i < MAX_ENGINES; i++ ) {
209 prop_advance[i] = pos;
210 CLAMP( &prop_advance[i], 0.0, 1.0 );
213 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
214 prop_advance[engine] = pos;
215 CLAMP( &prop_advance[engine], 0.0, 1.0 );
219 inline void move_prop_advance( int engine, double amt ) {
220 if ( engine == ALL_ENGINES ) {
221 for ( int i = 0; i < MAX_ENGINES; i++ ) {
222 prop_advance[i] += amt;
223 CLAMP( &prop_advance[i], 0.0, 1.0 );
226 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
227 prop_advance[engine] += amt;
228 CLAMP( &prop_advance[engine], 0.0, 1.0 );
232 inline void set_brake( int wheel, double pos ) {
233 if ( wheel == ALL_WHEELS ) {
234 for ( int i = 0; i < MAX_WHEELS; i++ ) {
236 CLAMP( &brake[i], 0.0, 1.0 );
239 if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
241 CLAMP( &brake[wheel], 0.0, 1.0 );
245 inline void move_brake( int wheel, double amt ) {
246 if ( wheel == ALL_WHEELS ) {
247 for ( int i = 0; i < MAX_WHEELS; i++ ) {
249 CLAMP( &brake[i], 0.0, 1.0 );
252 if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
254 CLAMP( &brake[wheel], 0.0, 1.0 );
261 extern FGControls controls;
264 #endif // _CONTROLS_HXX