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];
62 inline void CLAMP(double *x, double min, double max ) {
63 if ( *x < min ) { *x = min; }
64 if ( *x > max ) { *x = max; }
76 inline double get_aileron() const { return aileron; }
77 inline double get_elevator() const { return elevator; }
78 inline double get_elevator_trim() const { return elevator_trim; }
79 inline double get_rudder() const { return rudder; }
80 inline double get_flaps() const { return flaps; }
81 inline double get_throttle(int engine) const { return throttle[engine]; }
82 inline double get_brake(int wheel) const { return brake[wheel]; }
85 inline void set_aileron( double pos ) {
87 CLAMP( &aileron, -1.0, 1.0 );
89 // check for autocoordination
90 if ( current_options.get_auto_coordination() ==
91 fgOPTIONS::FG_AUTO_COORD_ENABLED )
93 set_rudder( aileron / 2.0 );
96 inline void move_aileron( double amt ) {
98 CLAMP( &aileron, -1.0, 1.0 );
100 // check for autocoordination
101 if ( current_options.get_auto_coordination() ==
102 fgOPTIONS::FG_AUTO_COORD_ENABLED )
104 set_rudder( aileron / 2.0 );
107 inline void set_elevator( double pos ) {
109 CLAMP( &elevator, -1.0, 1.0 );
111 inline void move_elevator( double amt ) {
113 CLAMP( &elevator, -1.0, 1.0 );
115 inline void set_elevator_trim( double pos ) {
117 CLAMP( &elevator_trim, -1.0, 1.0 );
119 inline void move_elevator_trim( double amt ) {
120 elevator_trim += amt;
121 CLAMP( &elevator_trim, -1.0, 1.0 );
123 inline void set_rudder( double pos ) {
125 CLAMP( &rudder, -1.0, 1.0 );
127 inline void move_rudder( double amt ) {
129 CLAMP( &rudder, -1.0, 1.0 );
131 inline void set_flaps( double pos ) {
133 CLAMP( &flaps, 0.0, 1.0 );
135 inline void move_flaps( double amt ) {
137 CLAMP( &flaps, 0.0, 1.0 );
139 inline void set_throttle( int engine, double pos ) {
140 if ( engine == ALL_ENGINES ) {
141 for ( int i = 0; i < MAX_ENGINES; i++ ) {
143 CLAMP( &throttle[i], 0.0, 1.0 );
146 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
147 throttle[engine] = pos;
148 CLAMP( &throttle[engine], 0.0, 1.0 );
152 inline void move_throttle( int engine, double amt ) {
153 if ( engine == ALL_ENGINES ) {
154 for ( int i = 0; i < MAX_ENGINES; i++ ) {
156 CLAMP( &throttle[i], 0.0, 1.0 );
159 if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
160 throttle[engine] += amt;
161 CLAMP( &throttle[engine], 0.0, 1.0 );
165 inline void set_brake( int wheel, double pos ) {
166 if ( wheel == ALL_WHEELS ) {
167 for ( int i = 0; i < MAX_WHEELS; i++ ) {
169 CLAMP( &brake[i], 0.0, 1.0 );
172 if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
174 CLAMP( &brake[wheel], 0.0, 1.0 );
178 inline void move_brake( int wheel, double amt ) {
179 if ( wheel == ALL_WHEELS ) {
180 for ( int i = 0; i < MAX_WHEELS; i++ ) {
182 CLAMP( &brake[i], 0.0, 1.0 );
185 if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
187 CLAMP( &brake[wheel], 0.0, 1.0 );
194 extern FGControls controls;
197 #endif // _CONTROLS_HXX