]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBsim/FGControls.h
a47ea58d9b7c938c3a5b2847f50451747ec86876
[flightgear.git] / src / FDM / JSBsim / FGControls.h
1 // controls.hxx -- defines a standard interface to all flight sim controls
2 //
3 // Written by Curtis Olson, started May 1997.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22 // (Log is kept at end of this file)
23
24
25 #ifndef _CONTROLS_HXX
26 #define _CONTROLS_HXX
27
28
29 #ifndef __cplusplus                                                          
30 # error This library requires C++
31 #endif                                   
32
33 //using namespace std;
34
35 // Define a structure containing the control parameters
36
37 class FGControls {
38
39 public:
40
41     static const int ALL_ENGINES = -1;
42     static const int MAX_ENGINES = 10;
43
44     static const int ALL_WHEELS = -1;
45     static const int MAX_WHEELS = 3;
46
47 private:
48
49     double aileron;
50     double elevator;
51     double elevator_trim;
52     double rudder;
53     double throttle[MAX_ENGINES];
54     double brake[MAX_WHEELS];
55
56 public:
57
58     FGControls();
59     ~FGControls();
60
61     // Query functions
62     inline double get_aileron() const { return aileron; }
63     inline double get_elevator() const { return elevator; }
64     inline double get_elevator_trim() const { return elevator_trim; }
65     inline double get_rudder() const { return rudder; }
66     inline double get_throttle(int engine) const { return throttle[engine]; }
67     inline double get_brake(int wheel) const { return brake[wheel]; }
68
69     // Update functions
70     inline void set_aileron( double pos ) {
71         aileron = pos;
72         if ( aileron < -1.0 ) aileron = -1.0;
73         if ( aileron >  1.0 ) aileron =  1.0;
74     }
75     inline void move_aileron( double amt ) {
76         aileron += amt;
77         if ( aileron < -1.0 ) aileron = -1.0;
78         if ( aileron >  1.0 ) aileron =  1.0;
79     }
80     inline void set_elevator( double pos ) {
81         elevator = pos;
82         if ( elevator < -1.0 ) elevator = -1.0;
83         if ( elevator >  1.0 ) elevator =  1.0;
84     }
85     inline void move_elevator( double amt ) {
86         elevator += amt;
87         if ( elevator < -1.0 ) elevator = -1.0;
88         if ( elevator >  1.0 ) elevator =  1.0;
89     }
90     inline void set_elevator_trim( double pos ) {
91         elevator_trim = pos;
92         if ( elevator_trim < -1.0 ) elevator_trim = -1.0;
93         if ( elevator_trim >  1.0 ) elevator_trim =  1.0;
94     }
95     inline void move_elevator_trim( double amt ) {
96         elevator_trim += amt;
97         if ( elevator_trim < -1.0 ) elevator_trim = -1.0;
98         if ( elevator_trim >  1.0 ) elevator_trim =  1.0;
99     }
100     inline void set_rudder( double pos ) {
101         rudder = pos;
102         if ( rudder < -1.0 ) rudder = -1.0;
103         if ( rudder >  1.0 ) rudder =  1.0;
104     }
105     inline void move_rudder( double amt ) {
106         rudder += amt;
107         if ( rudder < -1.0 ) rudder = -1.0;
108         if ( rudder >  1.0 ) rudder =  1.0;
109     }
110     inline void set_throttle( int engine, double pos ) {
111         if ( engine == ALL_ENGINES ) {
112             for ( int i = 0; i < MAX_ENGINES; i++ ) {
113                 throttle[i] = pos;
114                 if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
115                 if ( throttle[i] >  1.0 ) throttle[i] =  1.0;
116             }
117         } else {
118             if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
119                 throttle[engine] = pos;
120                 if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0;
121                 if ( throttle[engine] >  1.0 ) throttle[engine] =  1.0;
122             }
123         }
124     }
125     inline void move_throttle( int engine, double amt ) {
126         if ( engine == ALL_ENGINES ) {
127             for ( int i = 0; i < MAX_ENGINES; i++ ) {
128                 throttle[i] += amt;
129                 if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
130                 if ( throttle[i] >  1.0 ) throttle[i] =  1.0;
131             }
132         } else {
133             if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
134                 throttle[engine] += amt;
135                 if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0;
136                 if ( throttle[engine] >  1.0 ) throttle[engine] =  1.0;
137             }
138         }
139     }
140     inline void set_brake( int wheel, double pos ) {
141         if ( wheel == ALL_WHEELS ) {
142             for ( int i = 0; i < MAX_WHEELS; i++ ) {
143                 brake[i] = pos;
144                 if ( brake[i] < 0.0 ) brake[i] = 0.0;
145                 if ( brake[i] >  1.0 ) brake[i] =  1.0;
146             }
147         } else {
148             if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
149                 brake[wheel] = pos;
150                 if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
151                 if ( brake[wheel] >  1.0 ) brake[wheel] =  1.0;
152             }
153         }
154     }
155     inline void move_brake( int wheel, double amt ) {
156         if ( wheel == ALL_WHEELS ) {
157             for ( int i = 0; i < MAX_WHEELS; i++ ) {
158                 brake[i] += amt;
159                 if ( brake[i] < 0.0 ) brake[i] = 0.0;
160                 if ( brake[i] >  1.0 ) brake[i] =  1.0;
161             }
162         } else {
163             if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
164                 brake[wheel] += amt;
165                 if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
166                 if ( brake[wheel] >  1.0 ) brake[wheel] =  1.0;
167             }
168         }
169     }
170 };
171
172
173 extern FGControls controls;
174
175
176 #endif // _CONTROLS_HXX
177
178
179 // $Log$
180 // Revision 1.6  1999/06/29 15:30:35  curt
181 // Updated contributed by Jon Berndt.
182 //
183 // Revision 1.1  1999/02/13 01:12:03  curt
184 // Initial Revision.
185 //
186 // Revision 1.3  1998/12/05 16:13:13  curt
187 // Renamed class fgCONTROLS to class FGControls.
188 //
189 // Revision 1.2  1998/10/25 14:08:42  curt
190 // Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
191 //
192 // Revision 1.1  1998/10/18 01:51:07  curt
193 // c++-ifying ...
194 //
195 // Revision 1.17  1998/09/29 14:57:00  curt
196 // c++-ified some comments.
197 //
198 // Revision 1.16  1998/09/29 02:01:32  curt
199 // Added a brake.
200 //
201 // Revision 1.15  1998/04/25 22:06:27  curt
202 // Edited cvs log messages in source files ... bad bad bad!
203 //
204 // Revision 1.14  1998/04/22 13:26:19  curt
205 // C++ - ifing the code a bit.
206 //
207 // Revision 1.13  1998/04/21 17:02:35  curt
208 // Prepairing for C++ integration.
209 //
210 // Revision 1.12  1998/02/09 22:56:48  curt
211 // Removed "depend" files from cvs control.  Other minor make tweaks.
212 //
213 // Revision 1.11  1998/02/07 15:29:36  curt
214 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
215 // <chotchkiss@namg.us.anritsu.com>
216 //
217 // Revision 1.10  1998/01/27 00:47:52  curt
218 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
219 // system and commandline/config file processing code.
220 //
221 // Revision 1.9  1998/01/22 02:59:31  curt
222 // Changed #ifdef FILE_H to #ifdef _FILE_H
223 //
224 // Revision 1.8  1998/01/19 18:40:22  curt
225 // Tons of little changes to clean up the code and to remove fatal errors
226 // when building with the c++ compiler.
227 //
228 // Revision 1.7  1997/12/15 23:54:36  curt
229 // Add xgl wrappers for debugging.
230 // Generate terrain normals on the fly.
231 //
232 // Revision 1.6  1997/12/10 22:37:41  curt
233 // Prepended "fg" on the name of all global structures that didn't have it yet.
234 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
235 //
236 // Revision 1.5  1997/08/27 03:30:02  curt
237 // Changed naming scheme of basic shared structures.
238 //
239 // Revision 1.4  1997/07/23 21:52:18  curt
240 // Put comments around the text after an #endif for increased portability.
241 //
242 // Revision 1.3  1997/05/31 19:16:27  curt
243 // Elevator trim added.
244 //
245 // Revision 1.2  1997/05/23 15:40:33  curt
246 // Added GNU copyright headers.
247 //
248 // Revision 1.1  1997/05/16 15:59:48  curt
249 // Initial revision.
250 //