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