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 <simgear/misc/props.hxx>
29 #include <Main/fgfs.hxx>
30 #include <Main/globals.hxx>
33 # error This library requires C++
37 // Define a structure containing the control parameters
39 class FGControls : public FGSubsystem
63 double throttle[MAX_ENGINES];
64 double mixture[MAX_ENGINES];
65 double prop_advance[MAX_ENGINES];
66 double brake[MAX_WHEELS];
69 SGValue * auto_coordination;
71 inline void CLAMP(double *x, double min, double max ) {
72 if ( *x < min ) { *x = min; }
73 if ( *x > max ) { *x = max; }
81 // Implementation of FGSubsystem.
91 inline double get_aileron() const { return aileron; }
92 inline double get_elevator() const { return elevator; }
93 inline double get_elevator_trim() const { return elevator_trim; }
94 inline double get_rudder() const { return rudder; }
95 inline double get_flaps() const { return flaps; }
96 inline double get_throttle(int engine) const { return throttle[engine]; }
97 inline double get_mixture(int engine) const { return mixture[engine]; }
98 inline double get_prop_advance(int engine) const {
99 return prop_advance[engine];
101 inline double get_brake(int wheel) const { return brake[wheel]; }
104 inline void set_aileron( double pos ) {
106 CLAMP( &aileron, -1.0, 1.0 );
108 // check for autocoordination
109 if ( auto_coordination->getBoolValue() )
111 set_rudder( aileron / 2.0 );
114 inline void move_aileron( double amt ) {
116 CLAMP( &aileron, -1.0, 1.0 );
118 // check for autocoordination
119 if ( auto_coordination->getBoolValue() )
121 set_rudder( aileron / 2.0 );
124 inline void set_elevator( double pos ) {
126 CLAMP( &elevator, -1.0, 1.0 );
128 inline void move_elevator( double amt ) {
130 CLAMP( &elevator, -1.0, 1.0 );
132 inline void set_elevator_trim( double pos ) {
134 CLAMP( &elevator_trim, -1.0, 1.0 );
136 inline void move_elevator_trim( double amt ) {
137 elevator_trim += amt;
138 CLAMP( &elevator_trim, -1.0, 1.0 );
140 inline void set_rudder( double pos ) {
142 CLAMP( &rudder, -1.0, 1.0 );
144 inline void move_rudder( double amt ) {
146 CLAMP( &rudder, -1.0, 1.0 );
148 inline void set_flaps( double pos ) {
149 if ( flaps != pos ) {
150 globals->get_soundmgr()->play_once( "flaps" );
153 CLAMP( &flaps, 0.0, 1.0 );
155 inline void move_flaps( double amt ) {
156 if ( fabs(amt) > 0.0 ) {
157 globals->get_soundmgr()->play_once( "flaps" );
160 CLAMP( &flaps, 0.0, 1.0 );
162 inline void set_throttle( int engine, double pos ) {
163 if ( engine == ALL_ENGINES ) {
164 for ( int i = 0; i < MAX_ENGINES; i++ ) {
166 CLAMP( &throttle[i], 0.0, 1.0 );
169 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
170 throttle[engine] = pos;
171 CLAMP( &throttle[engine], 0.0, 1.0 );
175 inline void move_throttle( int engine, double amt ) {
176 if ( engine == ALL_ENGINES ) {
177 for ( int i = 0; i < MAX_ENGINES; i++ ) {
179 CLAMP( &throttle[i], 0.0, 1.0 );
182 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
183 throttle[engine] += amt;
184 CLAMP( &throttle[engine], 0.0, 1.0 );
188 inline void set_mixture( int engine, double pos ) {
189 if ( engine == ALL_ENGINES ) {
190 for ( int i = 0; i < MAX_ENGINES; i++ ) {
192 CLAMP( &mixture[i], 0.0, 1.0 );
195 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
196 mixture[engine] = pos;
197 CLAMP( &mixture[engine], 0.0, 1.0 );
201 inline void move_mixture( int engine, double amt ) {
202 if ( engine == ALL_ENGINES ) {
203 for ( int i = 0; i < MAX_ENGINES; i++ ) {
205 CLAMP( &mixture[i], 0.0, 1.0 );
208 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
209 mixture[engine] += amt;
210 CLAMP( &mixture[engine], 0.0, 1.0 );
214 inline void set_prop_advance( int engine, double pos ) {
215 if ( engine == ALL_ENGINES ) {
216 for ( int i = 0; i < MAX_ENGINES; i++ ) {
217 prop_advance[i] = pos;
218 CLAMP( &prop_advance[i], 0.0, 1.0 );
221 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
222 prop_advance[engine] = pos;
223 CLAMP( &prop_advance[engine], 0.0, 1.0 );
227 inline void move_prop_advance( int engine, double amt ) {
228 if ( engine == ALL_ENGINES ) {
229 for ( int i = 0; i < MAX_ENGINES; i++ ) {
230 prop_advance[i] += amt;
231 CLAMP( &prop_advance[i], 0.0, 1.0 );
234 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
235 prop_advance[engine] += amt;
236 CLAMP( &prop_advance[engine], 0.0, 1.0 );
240 inline void set_brake( int wheel, double pos ) {
241 if ( wheel == ALL_WHEELS ) {
242 for ( int i = 0; i < MAX_WHEELS; i++ ) {
244 CLAMP( &brake[i], 0.0, 1.0 );
247 if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
249 CLAMP( &brake[wheel], 0.0, 1.0 );
253 inline void move_brake( int wheel, double amt ) {
254 if ( wheel == ALL_WHEELS ) {
255 for ( int i = 0; i < MAX_WHEELS; i++ ) {
257 CLAMP( &brake[i], 0.0, 1.0 );
260 if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
262 CLAMP( &brake[wheel], 0.0, 1.0 );
269 extern FGControls controls;
272 #endif // _CONTROLS_HXX