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