1 // controls.hxx -- defines a standard interface to all flight sim controls
3 // Written by Curtis Olson, started May 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
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.
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.
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.
29 # error This library requires C++
33 // Define a structure containing the control parameters
57 double throttle[MAX_ENGINES];
58 double brake[MAX_WHEELS];
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]; }
74 inline void set_aileron( double pos ) {
76 if ( aileron < -1.0 ) aileron = -1.0;
77 if ( aileron > 1.0 ) aileron = 1.0;
79 inline void move_aileron( double amt ) {
81 if ( aileron < -1.0 ) aileron = -1.0;
82 if ( aileron > 1.0 ) aileron = 1.0;
84 inline void set_elevator( double pos ) {
86 if ( elevator < -1.0 ) elevator = -1.0;
87 if ( elevator > 1.0 ) elevator = 1.0;
89 inline void move_elevator( double amt ) {
91 if ( elevator < -1.0 ) elevator = -1.0;
92 if ( elevator > 1.0 ) elevator = 1.0;
94 inline void set_elevator_trim( double pos ) {
96 if ( elevator_trim < -1.0 ) elevator_trim = -1.0;
97 if ( elevator_trim > 1.0 ) elevator_trim = 1.0;
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;
104 inline void set_rudder( double pos ) {
106 if ( rudder < -1.0 ) rudder = -1.0;
107 if ( rudder > 1.0 ) rudder = 1.0;
109 inline void move_rudder( double amt ) {
111 if ( rudder < -1.0 ) rudder = -1.0;
112 if ( rudder > 1.0 ) rudder = 1.0;
114 inline void set_throttle( int engine, double pos ) {
115 if ( engine == ALL_ENGINES ) {
116 for ( int i = 0; i < MAX_ENGINES; i++ ) {
118 if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
119 if ( throttle[i] > 1.0 ) throttle[i] = 1.0;
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;
129 inline void move_throttle( int engine, double amt ) {
130 if ( engine == ALL_ENGINES ) {
131 for ( int i = 0; i < MAX_ENGINES; i++ ) {
133 if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
134 if ( throttle[i] > 1.0 ) throttle[i] = 1.0;
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;
144 inline void set_brake( int wheel, double pos ) {
145 if ( wheel == ALL_WHEELS ) {
146 for ( int i = 0; i < MAX_WHEELS; i++ ) {
148 if ( brake[i] < 0.0 ) brake[i] = 0.0;
149 if ( brake[i] > 1.0 ) brake[i] = 1.0;
152 if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
154 if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
155 if ( brake[wheel] > 1.0 ) brake[wheel] = 1.0;
159 inline void move_brake( int wheel, double amt ) {
160 if ( wheel == ALL_WHEELS ) {
161 for ( int i = 0; i < MAX_WHEELS; i++ ) {
163 if ( brake[i] < 0.0 ) brake[i] = 0.0;
164 if ( brake[i] > 1.0 ) brake[i] = 1.0;
167 if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
169 if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
170 if ( brake[wheel] > 1.0 ) brake[wheel] = 1.0;
177 extern FGControls controls;
180 #endif // _CONTROLS_HXX