]> git.mxchange.org Git - flightgear.git/blob - Controls/controls.c
d5128ca41280a7b8e5c4a024895bc7adc6db7bbe
[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 void fgControlsInit( void ) {
32     int i;
33     struct fgCONTROLS *c;
34     c = &current_aircraft.controls;
35
36     FG_Elevator = 0.0;
37     FG_Elev_Trim = 1.969572E-03;
38     FG_Aileron  = 0.0;
39     FG_Rudder   = 0.0;
40
41     for ( i = 0; i < FG_MAX_ENGINES; i++ ) {
42         FG_Throttle[i] = 0.0;
43     }
44
45 }
46
47
48 void fgElevMove(double amt) {
49     struct fgCONTROLS *c;
50     c = &current_aircraft.controls;
51
52     FG_Elevator += amt;
53
54     if ( FG_Elevator < -1.0 ) FG_Elevator = -1.0;
55     if ( FG_Elevator >  1.0 ) FG_Elevator =  1.0;
56 }
57
58 void fgElevSet(double pos) {
59     struct fgCONTROLS *c;
60     c = &current_aircraft.controls;
61
62     FG_Elevator = pos;
63
64     if ( FG_Elevator < -1.0 ) FG_Elevator = -1.0;
65     if ( FG_Elevator >  1.0 ) FG_Elevator =  1.0;
66 }
67
68 void fgElevTrimMove(double amt) {
69     struct fgCONTROLS *c;
70     c = &current_aircraft.controls;
71
72     FG_Elev_Trim += amt;
73
74     if ( FG_Elev_Trim < -1.0 ) FG_Elev_Trim = -1.0;
75     if ( FG_Elev_Trim >  1.0 ) FG_Elev_Trim =  1.0;
76 }
77
78 void fgElevTrimSet(double pos) {
79     struct fgCONTROLS *c;
80     c = &current_aircraft.controls;
81
82     FG_Elev_Trim = pos;
83
84     if ( FG_Elev_Trim < -1.0 ) FG_Elev_Trim = -1.0;
85     if ( FG_Elev_Trim >  1.0 ) FG_Elev_Trim =  1.0;
86 }
87
88 void fgAileronMove(double amt) {
89     struct fgCONTROLS *c;
90     c = &current_aircraft.controls;
91
92     FG_Aileron += amt;
93
94     if ( FG_Aileron < -1.0 ) FG_Aileron = -1.0;
95     if ( FG_Aileron >  1.0 ) FG_Aileron =  1.0;
96 }
97
98 void fgAileronSet(double pos) {
99     struct fgCONTROLS *c;
100     c = &current_aircraft.controls;
101
102     FG_Aileron = pos;
103
104     if ( FG_Aileron < -1.0 ) FG_Aileron = -1.0;
105     if ( FG_Aileron >  1.0 ) FG_Aileron =  1.0;
106 }
107
108 void fgRudderMove(double amt) {
109     struct fgCONTROLS *c;
110     c = &current_aircraft.controls;
111
112     FG_Rudder += amt;
113
114     if ( FG_Rudder < -1.0 ) FG_Rudder = -1.0;
115     if ( FG_Rudder >  1.0 ) FG_Rudder =  1.0;
116 }
117
118 void fgRudderSet(double pos) {
119     struct fgCONTROLS *c;
120     c = &current_aircraft.controls;
121
122     FG_Rudder = pos;
123
124     if ( FG_Rudder < -1.0 ) FG_Rudder = -1.0;
125     if ( FG_Rudder >  1.0 ) FG_Rudder =  1.0;
126 }
127
128 void fgThrottleMove(int engine, double amt) {
129     int i;
130     struct fgCONTROLS *c;
131     c = &current_aircraft.controls;
132
133     if ( engine == FG_Throttle_All ) {
134         for ( i = 0; i < FG_MAX_ENGINES; i++ ) {
135             FG_Throttle[i] += amt;
136             if ( FG_Throttle[i] < 0.0 ) FG_Throttle[i] = 0.0;
137             if ( FG_Throttle[i] > 1.0 ) FG_Throttle[i] = 1.0;
138         }
139     } else {
140         if ( (engine >= 0) && (engine < FG_MAX_ENGINES) ) {
141             FG_Throttle[engine] += amt;
142             if ( FG_Throttle[engine] < 0.0 ) FG_Throttle[engine] = 0.0;
143             if ( FG_Throttle[engine] > 1.0 ) FG_Throttle[engine] = 1.0;
144         }
145     }
146 }
147
148 void fgThrottleSet(int engine, double pos) {
149     int i;
150     struct fgCONTROLS *c;
151     c = &current_aircraft.controls;
152
153     if ( engine == FG_Throttle_All ) {
154         for ( i = 0; i < FG_MAX_ENGINES; i++ ) {
155             FG_Throttle[i] = pos;
156             if ( FG_Throttle[i] < 0.0 ) FG_Throttle[i] = 0.0;
157             if ( FG_Throttle[i] > 1.0 ) FG_Throttle[i] = 1.0;
158         }
159     } else {
160         if ( (engine >= 0) && (engine < FG_MAX_ENGINES) ) {
161             FG_Throttle[engine] = pos;
162             if ( FG_Throttle[engine] < 0.0 ) FG_Throttle[engine] = 0.0;
163             if ( FG_Throttle[engine] > 1.0 ) FG_Throttle[engine] = 1.0;
164         }
165     }
166 }
167
168
169 /* $Log$
170 /* Revision 1.6  1998/01/19 19:27:02  curt
171 /* Merged in make system changes from Bob Kuehne <rpk@sgi.com>
172 /* This should simplify things tremendously.
173 /*
174  * Revision 1.5  1998/01/19 18:40:22  curt
175  * Tons of little changes to clean up the code and to remove fatal errors
176  * when building with the c++ compiler.
177  *
178  * Revision 1.4  1997/12/10 22:37:41  curt
179  * Prepended "fg" on the name of all global structures that didn't have it yet.
180  * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
181  *
182  * Revision 1.3  1997/08/27 03:30:01  curt
183  * Changed naming scheme of basic shared structures.
184  *
185  * Revision 1.2  1997/06/21 17:12:48  curt
186  * Capitalized subdirectory names.
187  *
188  * Revision 1.1  1997/05/31 19:24:04  curt
189  * Initial revision.
190  *
191  */