]> git.mxchange.org Git - flightgear.git/blob - src/Controls/controls.hxx
43286b08dba2acee5f81c5f98998dd8acc9e8b18
[flightgear.git] / src / 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     // Reset function
66     void reset_all(void);
67         
68     // Query functions
69     inline double get_aileron() const { return aileron; }
70     inline double get_elevator() const { return elevator; }
71     inline double get_elevator_trim() const { return elevator_trim; }
72     inline double get_rudder() const { return rudder; }
73     inline double get_throttle(int engine) const { return throttle[engine]; }
74     inline double get_brake(int wheel) const { return brake[wheel]; }
75
76     // Update functions
77     inline void set_aileron( double pos ) {
78         aileron = pos;
79         if ( aileron < -1.0 ) aileron = -1.0;
80         if ( aileron >  1.0 ) aileron =  1.0;
81     }
82     inline void move_aileron( double amt ) {
83         aileron += amt;
84         if ( aileron < -1.0 ) aileron = -1.0;
85         if ( aileron >  1.0 ) aileron =  1.0;
86     }
87     inline void set_elevator( double pos ) {
88         elevator = pos;
89         if ( elevator < -1.0 ) elevator = -1.0;
90         if ( elevator >  1.0 ) elevator =  1.0;
91     }
92     inline void move_elevator( double amt ) {
93         elevator += amt;
94         if ( elevator < -1.0 ) elevator = -1.0;
95         if ( elevator >  1.0 ) elevator =  1.0;
96     }
97     inline void set_elevator_trim( double pos ) {
98         elevator_trim = pos;
99         if ( elevator_trim < -1.0 ) elevator_trim = -1.0;
100         if ( elevator_trim >  1.0 ) elevator_trim =  1.0;
101     }
102     inline void move_elevator_trim( double amt ) {
103         elevator_trim += amt;
104         if ( elevator_trim < -1.0 ) elevator_trim = -1.0;
105         if ( elevator_trim >  1.0 ) elevator_trim =  1.0;
106     }
107     inline void set_rudder( double pos ) {
108         rudder = pos;
109         if ( rudder < -1.0 ) rudder = -1.0;
110         if ( rudder >  1.0 ) rudder =  1.0;
111     }
112     inline void move_rudder( double amt ) {
113         rudder += amt;
114         if ( rudder < -1.0 ) rudder = -1.0;
115         if ( rudder >  1.0 ) rudder =  1.0;
116     }
117     inline void set_throttle( int engine, double pos ) {
118         if ( engine == ALL_ENGINES ) {
119             for ( int i = 0; i < MAX_ENGINES; i++ ) {
120                 throttle[i] = pos;
121                 if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
122                 if ( throttle[i] >  1.0 ) throttle[i] =  1.0;
123             }
124         } else {
125             if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
126                 throttle[engine] = pos;
127                 if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0;
128                 if ( throttle[engine] >  1.0 ) throttle[engine] =  1.0;
129             }
130         }
131     }
132     inline void move_throttle( int engine, double amt ) {
133         if ( engine == ALL_ENGINES ) {
134             for ( int i = 0; i < MAX_ENGINES; i++ ) {
135                 throttle[i] += amt;
136                 if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
137                 if ( throttle[i] >  1.0 ) throttle[i] =  1.0;
138             }
139         } else {
140             if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
141                 throttle[engine] += amt;
142                 if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0;
143                 if ( throttle[engine] >  1.0 ) throttle[engine] =  1.0;
144             }
145         }
146     }
147     inline void set_brake( int wheel, double pos ) {
148         if ( wheel == ALL_WHEELS ) {
149             for ( int i = 0; i < MAX_WHEELS; i++ ) {
150                 brake[i] = pos;
151                 if ( brake[i] < 0.0 ) brake[i] = 0.0;
152                 if ( brake[i] >  1.0 ) brake[i] =  1.0;
153             }
154         } else {
155             if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
156                 brake[wheel] = pos;
157                 if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
158                 if ( brake[wheel] >  1.0 ) brake[wheel] =  1.0;
159             }
160         }
161     }
162     inline void move_brake( int wheel, double amt ) {
163         if ( wheel == ALL_WHEELS ) {
164             for ( int i = 0; i < MAX_WHEELS; i++ ) {
165                 brake[i] += amt;
166                 if ( brake[i] < 0.0 ) brake[i] = 0.0;
167                 if ( brake[i] >  1.0 ) brake[i] =  1.0;
168             }
169         } else {
170             if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
171                 brake[wheel] += amt;
172                 if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
173                 if ( brake[wheel] >  1.0 ) brake[wheel] =  1.0;
174             }
175         }
176     }
177 };
178
179
180 extern FGControls controls;
181
182
183 #endif // _CONTROLS_HXX
184
185