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];
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]; }
77 inline void set_aileron( double pos ) {
79 if ( aileron < -1.0 ) aileron = -1.0;
80 if ( aileron > 1.0 ) aileron = 1.0;
82 inline void move_aileron( double amt ) {
84 if ( aileron < -1.0 ) aileron = -1.0;
85 if ( aileron > 1.0 ) aileron = 1.0;
87 inline void set_elevator( double pos ) {
89 if ( elevator < -1.0 ) elevator = -1.0;
90 if ( elevator > 1.0 ) elevator = 1.0;
92 inline void move_elevator( double amt ) {
94 if ( elevator < -1.0 ) elevator = -1.0;
95 if ( elevator > 1.0 ) elevator = 1.0;
97 inline void set_elevator_trim( double pos ) {
99 if ( elevator_trim < -1.0 ) elevator_trim = -1.0;
100 if ( elevator_trim > 1.0 ) elevator_trim = 1.0;
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;
107 inline void set_rudder( double pos ) {
109 if ( rudder < -1.0 ) rudder = -1.0;
110 if ( rudder > 1.0 ) rudder = 1.0;
112 inline void move_rudder( double amt ) {
114 if ( rudder < -1.0 ) rudder = -1.0;
115 if ( rudder > 1.0 ) rudder = 1.0;
117 inline void set_throttle( int engine, double pos ) {
118 if ( engine == ALL_ENGINES ) {
119 for ( int i = 0; i < MAX_ENGINES; i++ ) {
121 if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
122 if ( throttle[i] > 1.0 ) throttle[i] = 1.0;
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;
132 inline void move_throttle( int engine, double amt ) {
133 if ( engine == ALL_ENGINES ) {
134 for ( int i = 0; i < MAX_ENGINES; i++ ) {
136 if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
137 if ( throttle[i] > 1.0 ) throttle[i] = 1.0;
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;
147 inline void set_brake( int wheel, double pos ) {
148 if ( wheel == ALL_WHEELS ) {
149 for ( int i = 0; i < MAX_WHEELS; i++ ) {
151 if ( brake[i] < 0.0 ) brake[i] = 0.0;
152 if ( brake[i] > 1.0 ) brake[i] = 1.0;
155 if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
157 if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
158 if ( brake[wheel] > 1.0 ) brake[wheel] = 1.0;
162 inline void move_brake( int wheel, double amt ) {
163 if ( wheel == ALL_WHEELS ) {
164 for ( int i = 0; i < MAX_WHEELS; i++ ) {
166 if ( brake[i] < 0.0 ) brake[i] = 0.0;
167 if ( brake[i] > 1.0 ) brake[i] = 1.0;
170 if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
172 if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
173 if ( brake[wheel] > 1.0 ) brake[wheel] = 1.0;
180 extern FGControls controls;
183 #endif // _CONTROLS_HXX