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