]> git.mxchange.org Git - flightgear.git/blob - src/Controls/controls.cxx
1. Added src/Main/fgfs.hxx as a standard, top-level include file for
[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 FGControls controls;
31
32
33 // Constructor
34 FGControls::FGControls() :
35     aileron( 0.0 ),
36     elevator( 0.0 ),
37     elevator_trim( 1.969572E-03 ),
38     rudder( 0.0 ),
39     throttle_idle( true )
40 {
41     for ( int engine = 0; engine < MAX_ENGINES; engine++ ) {
42         throttle[engine] = 0.0;
43         mixture[engine] = 1.0;
44         prop_advance[engine] = 1.0;
45     }
46
47     for ( int wheel = 0; wheel < MAX_WHEELS; wheel++ ) {
48         brake[wheel] = 0.0;
49     }
50 }
51
52
53 void FGControls::reset_all()
54 {
55     set_aileron(0.0);
56     set_elevator(0.0);
57     set_elevator_trim(0.0);
58     set_rudder(0.0);
59     set_throttle(FGControls::ALL_ENGINES, 0.0);
60     throttle_idle = true;
61 }
62
63
64 // Destructor
65 FGControls::~FGControls() {
66 }
67
68
69 void
70 FGControls::init ()
71 {
72 }
73
74
75 void
76 FGControls::bind ()
77 {
78   fgTie("/controls/aileron", this,
79                     &FGControls::get_aileron, &FGControls::set_aileron);
80   fgTie("/controls/elevator", this,
81        &FGControls::get_elevator, &FGControls::set_elevator);
82   fgTie("/controls/elevator-trim", this,
83        &FGControls::get_elevator_trim, &FGControls::set_elevator_trim);
84   fgTie("/controls/rudder", this,
85        &FGControls::get_rudder, &FGControls::set_rudder);
86   fgTie("/controls/flaps", this,
87        &FGControls::get_flaps, &FGControls::set_flaps);
88   for (int index = 0; index < MAX_ENGINES; index++) {
89     char name[32];
90     sprintf(name, "/controls/throttle[%d]", index);
91     fgTie(name, this, index,
92           &FGControls::get_throttle, &FGControls::set_throttle);
93     sprintf(name, "/controls/mixture[%d]", index);
94     fgTie(name, this, index,
95          &FGControls::get_mixture, &FGControls::set_mixture);
96     sprintf(name, "/controls/propellor-pitch[%d]", index);
97     fgTie(name, this, index,
98          &FGControls::get_prop_advance, &FGControls::set_prop_advance);
99   }
100   fgTie("/controls/throttle/all", this, ALL_ENGINES,
101         &FGControls::get_throttle, &FGControls::set_throttle);
102   fgTie("/controls/mixture/all", this, ALL_ENGINES,
103         &FGControls::get_mixture, &FGControls::set_mixture);
104   fgTie("/controls/propellor-pitch/all", this, ALL_ENGINES,
105         &FGControls::get_prop_advance, &FGControls::set_prop_advance);
106   for (int index = 0; index < MAX_WHEELS; index++) {
107     char name[32];
108     sprintf(name, "/controls/brakes[%d]", index);
109     fgTie(name, this, index,
110          &FGControls::get_brake, &FGControls::set_brake);
111   }
112   fgTie("/controls/brakes/all", this, ALL_WHEELS,
113         &FGControls::get_brake, &FGControls::set_brake);
114 }
115
116
117 void
118 FGControls::unbind ()
119 {
120                                 // Tie control properties.
121   fgUntie("/controls/aileron");
122   fgUntie("/controls/elevator");
123   fgUntie("/controls/elevator-trim");
124   fgUntie("/controls/rudder");
125   fgUntie("/controls/flaps");
126   for (int index = 0; index < MAX_ENGINES; index++) {
127     char name[32];
128     sprintf(name, "/controls/throttle[%d]", index);
129     fgUntie(name);
130     sprintf(name, "/controls/mixture[%d]", index);
131     fgUntie(name);
132     sprintf(name, "/controls/propellor-pitch[%d]", index);
133     fgUntie(name);
134   }
135   for (int index = 0; index < MAX_WHEELS; index++) {
136     char name[32];
137     sprintf(name, "/controls/brakes[%d]", index);
138     fgUntie(name);
139   }
140 }
141
142
143 void
144 FGControls::update ()
145 {
146 }
147