]> git.mxchange.org Git - flightgear.git/blob - src/Controls/controls.cxx
Move FGControls declaration to globals.hxx
[flightgear.git] / src / Controls / controls.cxx
1 // controls.cxx -- defines a standard interface to all flight sim controls
2 //
3 // Written by Curtis Olson, started May 1997.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #include "controls.hxx"
25
26 #include <simgear/debug/logstream.hxx>
27 #include <Main/fg_props.hxx>
28
29
30 // Constructor
31 FGControls::FGControls() :
32     aileron( 0.0 ),
33     elevator( 0.0 ),
34     elevator_trim( 1.969572E-03 ),
35     rudder( 0.0 ),
36     throttle_idle( true )
37 {
38 }
39
40
41 void FGControls::reset_all()
42 {
43     set_aileron(0.0);
44     set_elevator(0.0);
45     set_elevator_trim(0.0);
46     set_rudder(0.0);
47     set_throttle(FGControls::ALL_ENGINES, 0.0);
48     throttle_idle = true;
49 }
50
51
52 // Destructor
53 FGControls::~FGControls() {
54 }
55
56
57 void
58 FGControls::init ()
59 {
60     for ( int engine = 0; engine < MAX_ENGINES; engine++ ) {
61         throttle[engine] = 0.0;
62         mixture[engine] = 1.0;
63         prop_advance[engine] = 1.0;
64     }
65
66     for ( int wheel = 0; wheel < MAX_WHEELS; wheel++ ) {
67         brake[wheel] = 0.0;
68     }
69
70     auto_coordination = fgGetNode("/sim/auto-coordination", true);
71 }
72
73
74 void
75 FGControls::bind ()
76 {
77   fgTie("/controls/aileron", this,
78         &FGControls::get_aileron, &FGControls::set_aileron);
79   fgSetArchivable("/controls/aileron");
80   fgTie("/controls/elevator", this,
81        &FGControls::get_elevator, &FGControls::set_elevator);
82   fgSetArchivable("/controls/elevator");
83   fgTie("/controls/elevator-trim", this,
84        &FGControls::get_elevator_trim, &FGControls::set_elevator_trim);
85   fgSetArchivable("/controls/elevator-trim");
86   fgTie("/controls/rudder", this,
87        &FGControls::get_rudder, &FGControls::set_rudder);
88   fgSetArchivable("/controls/rudder");
89   fgTie("/controls/flaps", this,
90        &FGControls::get_flaps, &FGControls::set_flaps);
91   fgSetArchivable("/controls/flaps");
92   int index;
93   for (index = 0; index < MAX_ENGINES; index++) {
94     char name[32];
95     sprintf(name, "/controls/throttle[%d]", index);
96     fgTie(name, this, index,
97           &FGControls::get_throttle, &FGControls::set_throttle);
98     fgSetArchivable(name);
99     sprintf(name, "/controls/mixture[%d]", index);
100     fgTie(name, this, index,
101          &FGControls::get_mixture, &FGControls::set_mixture);
102     fgSetArchivable(name);
103     sprintf(name, "/controls/propellor-pitch[%d]", index);
104     fgTie(name, this, index,
105          &FGControls::get_prop_advance, &FGControls::set_prop_advance);
106     fgSetArchivable(name);
107   }
108   for (index = 0; index < MAX_WHEELS; index++) {
109     char name[32];
110     sprintf(name, "/controls/brakes[%d]", index);
111     fgTie(name, this, index,
112          &FGControls::get_brake, &FGControls::set_brake);
113     fgSetArchivable(name);
114   }
115 }
116
117
118 void
119 FGControls::unbind ()
120 {
121                                 // Tie control properties.
122   fgUntie("/controls/aileron");
123   fgUntie("/controls/elevator");
124   fgUntie("/controls/elevator-trim");
125   fgUntie("/controls/rudder");
126   fgUntie("/controls/flaps");
127   int index;
128   for (index = 0; index < MAX_ENGINES; index++) {
129     char name[32];
130     sprintf(name, "/controls/throttle[%d]", index);
131     fgUntie(name);
132     sprintf(name, "/controls/mixture[%d]", index);
133     fgUntie(name);
134     sprintf(name, "/controls/propellor-pitch[%d]", index);
135     fgUntie(name);
136   }
137   for (index = 0; index < MAX_WHEELS; index++) {
138     char name[32];
139     sprintf(name, "/controls/brakes[%d]", index);
140     fgUntie(name);
141   }
142 }
143
144
145 void
146 FGControls::update ()
147 {
148 }
149