]> git.mxchange.org Git - flightgear.git/blob - Controls/controls.c
Added a brake.
[flightgear.git] / Controls / controls.c
1 /**************************************************************************
2  * controls.c -- defines a standard interface to all flight sim controls
3  *
4  * Written by Curtis Olson, started May 1997.
5  *
6  * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  * $Id$
23  * (Log is kept at end of this file)
24  **************************************************************************/
25
26
27 #include <Controls/controls.h>
28 #include <Aircraft/aircraft.h>
29
30
31 fgCONTROLS cur_control_params;
32
33
34 void fgControlsInit( void ) {
35     int i;
36     fgCONTROLS *c;
37     c = current_aircraft.controls;
38
39     FG_Elevator = 0.0;
40     FG_Elev_Trim = 1.969572E-03;
41     FG_Aileron  = 0.0;
42     FG_Rudder   = 0.0;
43
44     for ( i = 0; i < FG_MAX_ENGINES; i++ ) {
45         FG_Throttle[i] = 0.0;
46     }
47
48     FG_Brake_Amt = 0.0;
49 }
50
51
52 void fgElevMove(double amt) {
53     fgCONTROLS *c;
54     c = current_aircraft.controls;
55
56     FG_Elevator += amt;
57
58     if ( FG_Elevator < -1.0 ) FG_Elevator = -1.0;
59     if ( FG_Elevator >  1.0 ) FG_Elevator =  1.0;
60 }
61
62 void fgElevSet(double pos) {
63     fgCONTROLS *c;
64     c = current_aircraft.controls;
65
66     FG_Elevator = pos;
67
68     if ( FG_Elevator < -1.0 ) FG_Elevator = -1.0;
69     if ( FG_Elevator >  1.0 ) FG_Elevator =  1.0;
70 }
71
72 void fgElevTrimMove(double amt) {
73     fgCONTROLS *c;
74     c = current_aircraft.controls;
75
76     FG_Elev_Trim += amt;
77
78     if ( FG_Elev_Trim < -1.0 ) FG_Elev_Trim = -1.0;
79     if ( FG_Elev_Trim >  1.0 ) FG_Elev_Trim =  1.0;
80 }
81
82 void fgElevTrimSet(double pos) {
83     fgCONTROLS *c;
84     c = current_aircraft.controls;
85
86     FG_Elev_Trim = pos;
87
88     if ( FG_Elev_Trim < -1.0 ) FG_Elev_Trim = -1.0;
89     if ( FG_Elev_Trim >  1.0 ) FG_Elev_Trim =  1.0;
90 }
91
92 void fgAileronMove(double amt) {
93     fgCONTROLS *c;
94     c = current_aircraft.controls;
95
96     FG_Aileron += amt;
97
98     if ( FG_Aileron < -1.0 ) FG_Aileron = -1.0;
99     if ( FG_Aileron >  1.0 ) FG_Aileron =  1.0;
100 }
101
102 void fgAileronSet(double pos) {
103     fgCONTROLS *c;
104     c = current_aircraft.controls;
105
106     FG_Aileron = pos;
107
108     if ( FG_Aileron < -1.0 ) FG_Aileron = -1.0;
109     if ( FG_Aileron >  1.0 ) FG_Aileron =  1.0;
110 }
111
112 void fgRudderMove(double amt) {
113     fgCONTROLS *c;
114     c = current_aircraft.controls;
115
116     FG_Rudder += amt;
117
118     if ( FG_Rudder < -1.0 ) FG_Rudder = -1.0;
119     if ( FG_Rudder >  1.0 ) FG_Rudder =  1.0;
120 }
121
122 void fgRudderSet(double pos) {
123     fgCONTROLS *c;
124     c = current_aircraft.controls;
125
126     FG_Rudder = pos;
127
128     if ( FG_Rudder < -1.0 ) FG_Rudder = -1.0;
129     if ( FG_Rudder >  1.0 ) FG_Rudder =  1.0;
130 }
131
132 void fgThrottleMove(int engine, double amt) {
133     int i;
134     fgCONTROLS *c;
135     c = current_aircraft.controls;
136
137     if ( engine == FG_Throttle_All ) {
138         for ( i = 0; i < FG_MAX_ENGINES; i++ ) {
139             FG_Throttle[i] += amt;
140             if ( FG_Throttle[i] < 0.0 ) FG_Throttle[i] = 0.0;
141             if ( FG_Throttle[i] > 1.0 ) FG_Throttle[i] = 1.0;
142         }
143     } else {
144         if ( (engine >= 0) && (engine < FG_MAX_ENGINES) ) {
145             FG_Throttle[engine] += amt;
146             if ( FG_Throttle[engine] < 0.0 ) FG_Throttle[engine] = 0.0;
147             if ( FG_Throttle[engine] > 1.0 ) FG_Throttle[engine] = 1.0;
148         }
149     }
150 }
151
152 void fgThrottleSet(int engine, double pos) {
153     int i;
154     fgCONTROLS *c;
155     c = current_aircraft.controls;
156
157     if ( engine == FG_Throttle_All ) {
158         for ( i = 0; i < FG_MAX_ENGINES; i++ ) {
159             FG_Throttle[i] = pos;
160             if ( FG_Throttle[i] < 0.0 ) FG_Throttle[i] = 0.0;
161             if ( FG_Throttle[i] > 1.0 ) FG_Throttle[i] = 1.0;
162         }
163     } else {
164         if ( (engine >= 0) && (engine < FG_MAX_ENGINES) ) {
165             FG_Throttle[engine] = pos;
166             if ( FG_Throttle[engine] < 0.0 ) FG_Throttle[engine] = 0.0;
167             if ( FG_Throttle[engine] > 1.0 ) FG_Throttle[engine] = 1.0;
168         }
169     }
170 }
171
172
173 double fgBrakeGet( void ) {
174     fgCONTROLS *c;
175     c = current_aircraft.controls;
176
177     return FG_Brake_Amt;
178 }
179
180
181 void fgBrakeSet( double brake_amt ) {
182     fgCONTROLS *c;
183     c = current_aircraft.controls;
184
185     FG_Brake_Amt = brake_amt;
186 }
187
188
189 /* $Log$
190 /* Revision 1.8  1998/09/29 02:01:31  curt
191 /* Added a brake.
192 /*
193  * Revision 1.7  1998/02/07 15:29:36  curt
194  * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
195  * <chotchkiss@namg.us.anritsu.com>
196  *
197  * Revision 1.6  1998/01/19 19:27:02  curt
198  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
199  * This should simplify things tremendously.
200  *
201  * Revision 1.5  1998/01/19 18:40:22  curt
202  * Tons of little changes to clean up the code and to remove fatal errors
203  * when building with the c++ compiler.
204  *
205  * Revision 1.4  1997/12/10 22:37:41  curt
206  * Prepended "fg" on the name of all global structures that didn't have it yet.
207  * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
208  *
209  * Revision 1.3  1997/08/27 03:30:01  curt
210  * Changed naming scheme of basic shared structures.
211  *
212  * Revision 1.2  1997/06/21 17:12:48  curt
213  * Capitalized subdirectory names.
214  *
215  * Revision 1.1  1997/05/31 19:24:04  curt
216  * Initial revision.
217  *
218  */