]> git.mxchange.org Git - flightgear.git/blob - Simulator/Controls/controls.hxx
Initial revision.
[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
23
24 #ifndef _CONTROLS_HXX
25 #define _CONTROLS_HXX
26
27
28 #ifndef __cplusplus                                                          
29 # error This library requires C++
30 #endif                                   
31
32
33 // Define a structure containing the control parameters
34
35 class FGControls {
36
37 public:
38
39     enum
40     {
41         ALL_ENGINES = -1,
42         MAX_ENGINES = 10
43     };
44
45     enum
46     {
47         ALL_WHEELS = -1,
48         MAX_WHEELS = 3
49     };
50
51 private:
52
53     double aileron;
54     double elevator;
55     double elevator_trim;
56     double rudder;
57     double throttle[MAX_ENGINES];
58     double brake[MAX_WHEELS];
59
60 public:
61
62     FGControls();
63     ~FGControls();
64
65     // Query functions
66     inline double get_aileron() const { return aileron; }
67     inline double get_elevator() const { return elevator; }
68     inline double get_elevator_trim() const { return elevator_trim; }
69     inline double get_rudder() const { return rudder; }
70     inline double get_throttle(int engine) const { return throttle[engine]; }
71     inline double get_brake(int wheel) const { return brake[wheel]; }
72
73     // Update functions
74     inline void set_aileron( double pos ) {
75         aileron = pos;
76         if ( aileron < -1.0 ) aileron = -1.0;
77         if ( aileron >  1.0 ) aileron =  1.0;
78     }
79     inline void move_aileron( double amt ) {
80         aileron += amt;
81         if ( aileron < -1.0 ) aileron = -1.0;
82         if ( aileron >  1.0 ) aileron =  1.0;
83     }
84     inline void set_elevator( double pos ) {
85         elevator = pos;
86         if ( elevator < -1.0 ) elevator = -1.0;
87         if ( elevator >  1.0 ) elevator =  1.0;
88     }
89     inline void move_elevator( double amt ) {
90         elevator += amt;
91         if ( elevator < -1.0 ) elevator = -1.0;
92         if ( elevator >  1.0 ) elevator =  1.0;
93     }
94     inline void set_elevator_trim( double pos ) {
95         elevator_trim = pos;
96         if ( elevator_trim < -1.0 ) elevator_trim = -1.0;
97         if ( elevator_trim >  1.0 ) elevator_trim =  1.0;
98     }
99     inline void move_elevator_trim( double amt ) {
100         elevator_trim += amt;
101         if ( elevator_trim < -1.0 ) elevator_trim = -1.0;
102         if ( elevator_trim >  1.0 ) elevator_trim =  1.0;
103     }
104     inline void set_rudder( double pos ) {
105         rudder = pos;
106         if ( rudder < -1.0 ) rudder = -1.0;
107         if ( rudder >  1.0 ) rudder =  1.0;
108     }
109     inline void move_rudder( double amt ) {
110         rudder += amt;
111         if ( rudder < -1.0 ) rudder = -1.0;
112         if ( rudder >  1.0 ) rudder =  1.0;
113     }
114     inline void set_throttle( int engine, double pos ) {
115         if ( engine == ALL_ENGINES ) {
116             for ( int i = 0; i < MAX_ENGINES; i++ ) {
117                 throttle[i] = pos;
118                 if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
119                 if ( throttle[i] >  1.0 ) throttle[i] =  1.0;
120             }
121         } else {
122             if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
123                 throttle[engine] = pos;
124                 if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0;
125                 if ( throttle[engine] >  1.0 ) throttle[engine] =  1.0;
126             }
127         }
128     }
129     inline void move_throttle( int engine, double amt ) {
130         if ( engine == ALL_ENGINES ) {
131             for ( int i = 0; i < MAX_ENGINES; i++ ) {
132                 throttle[i] += amt;
133                 if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
134                 if ( throttle[i] >  1.0 ) throttle[i] =  1.0;
135             }
136         } else {
137             if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
138                 throttle[engine] += amt;
139                 if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0;
140                 if ( throttle[engine] >  1.0 ) throttle[engine] =  1.0;
141             }
142         }
143     }
144     inline void set_brake( int wheel, double pos ) {
145         if ( wheel == ALL_WHEELS ) {
146             for ( int i = 0; i < MAX_WHEELS; i++ ) {
147                 brake[i] = pos;
148                 if ( brake[i] < 0.0 ) brake[i] = 0.0;
149                 if ( brake[i] >  1.0 ) brake[i] =  1.0;
150             }
151         } else {
152             if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
153                 brake[wheel] = pos;
154                 if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
155                 if ( brake[wheel] >  1.0 ) brake[wheel] =  1.0;
156             }
157         }
158     }
159     inline void move_brake( int wheel, double amt ) {
160         if ( wheel == ALL_WHEELS ) {
161             for ( int i = 0; i < MAX_WHEELS; i++ ) {
162                 brake[i] += amt;
163                 if ( brake[i] < 0.0 ) brake[i] = 0.0;
164                 if ( brake[i] >  1.0 ) brake[i] =  1.0;
165             }
166         } else {
167             if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
168                 brake[wheel] += amt;
169                 if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
170                 if ( brake[wheel] >  1.0 ) brake[wheel] =  1.0;
171             }
172         }
173     }
174 };
175
176
177 extern FGControls controls;
178
179
180 #endif // _CONTROLS_HXX
181
182