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
59 double throttle[MAX_ENGINES];
60 double brake[MAX_WHEELS];
63 inline void CLAMP(double *x, double min, double max ) {
64 if ( *x < min ) { *x = min; }
65 if ( *x > max ) { *x = max; }
77 inline double get_aileron() const { return aileron; }
78 inline double get_elevator() const { return elevator; }
79 inline double get_elevator_trim() const { return elevator_trim; }
80 inline double get_rudder() const { return rudder; }
81 inline double get_flaps() const { return flaps; }
82 inline double get_throttle(int engine) const { return throttle[engine]; }
83 inline double get_brake(int wheel) const { return brake[wheel]; }
86 inline void set_aileron( double pos ) {
88 CLAMP( &aileron, -1.0, 1.0 );
90 // check for autocoordination
91 if ( current_options.get_auto_coordination() ==
92 fgOPTIONS::FG_AUTO_COORD_ENABLED )
94 set_rudder( aileron / 2.0 );
97 inline void move_aileron( double amt ) {
99 CLAMP( &aileron, -1.0, 1.0 );
101 // check for autocoordination
102 if ( current_options.get_auto_coordination() ==
103 fgOPTIONS::FG_AUTO_COORD_ENABLED )
105 set_rudder( aileron / 2.0 );
108 inline void set_elevator( double pos ) {
110 CLAMP( &elevator, -1.0, 1.0 );
112 inline void move_elevator( double amt ) {
114 CLAMP( &elevator, -1.0, 1.0 );
116 inline void set_elevator_trim( double pos ) {
118 CLAMP( &elevator_trim, -1.0, 1.0 );
120 inline void move_elevator_trim( double amt ) {
121 elevator_trim += amt;
122 CLAMP( &elevator_trim, -1.0, 1.0 );
124 inline void set_rudder( double pos ) {
126 CLAMP( &rudder, -1.0, 1.0 );
128 inline void move_rudder( double amt ) {
130 CLAMP( &rudder, -1.0, 1.0 );
132 inline void set_flaps( double pos ) {
134 CLAMP( &flaps, 0.0, 1.0 );
136 inline void move_flaps( double amt ) {
138 CLAMP( &flaps, 0.0, 1.0 );
140 inline void set_throttle( int engine, double pos ) {
141 if ( engine == ALL_ENGINES ) {
142 for ( int i = 0; i < MAX_ENGINES; i++ ) {
144 CLAMP( &throttle[i], 0.0, 1.0 );
147 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
148 throttle[engine] = pos;
149 CLAMP( &throttle[engine], 0.0, 1.0 );
153 inline void move_throttle( int engine, double amt ) {
154 if ( engine == ALL_ENGINES ) {
155 for ( int i = 0; i < MAX_ENGINES; i++ ) {
157 CLAMP( &throttle[i], 0.0, 1.0 );
160 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
161 throttle[engine] += amt;
162 CLAMP( &throttle[engine], 0.0, 1.0 );
166 inline void set_brake( int wheel, double pos ) {
167 if ( wheel == ALL_WHEELS ) {
168 for ( int i = 0; i < MAX_WHEELS; i++ ) {
170 CLAMP( &brake[i], 0.0, 1.0 );
173 if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
175 CLAMP( &brake[wheel], 0.0, 1.0 );
179 inline void move_brake( int wheel, double amt ) {
180 if ( wheel == ALL_WHEELS ) {
181 for ( int i = 0; i < MAX_WHEELS; i++ ) {
183 CLAMP( &brake[i], 0.0, 1.0 );
186 if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
188 CLAMP( &brake[wheel], 0.0, 1.0 );
195 extern FGControls controls;
198 #endif // _CONTROLS_HXX