]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD_misc.cxx
initialize variables before using them
[flightgear.git] / src / Instrumentation / HUD / HUD_misc.cxx
1 // HUD_misc.cxx -- HUD miscellaneous elements
2 //
3 // Written by Melchior FRANZ, started September 2006.
4 //
5 // Copyright (C) 2006  Melchior FRANZ  [mfranz#aon:at]
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
21 #ifdef HAVE_CONFIG_H
22 #  include <config.h>
23 #endif
24
25 #include <simgear/props/condition.hxx>
26 #include "HUD.hxx"
27
28
29 // MIL-STD-1787B aiming reticle
30
31 HUD::AimingReticle::AimingReticle(HUD *hud, const SGPropertyNode *n, float x, float y) :
32     Item(hud, n, x, y),
33     _active_condition(0),
34     _diameter(n->getNode("diameter-input", false)),
35     _bullet_size(_w / 6.0),
36     _inner_radius(_w / 2.0)
37 {
38     const SGPropertyNode *node = n->getNode("active-condition");
39     if (node)
40        _active_condition = sgReadCondition(globals->get_props(), node);
41 }
42
43
44 void HUD::AimingReticle::draw(void)
45 {
46     bool active = _active_condition ? _active_condition->test() : true;
47     float diameter = _diameter.isValid() ? _diameter.getFloatValue() : 2.0f; // outer circle
48
49     float x = _center_x;
50     float y = _center_y;
51
52     if (active) { // stadiametric (4.2.4.4)
53         draw_bullet(x, y, _bullet_size);
54         draw_circle(x, y, _inner_radius);
55         draw_circle(x, y, diameter * _inner_radius);
56
57     } else { // standby (4.2.4.5)
58         // TODO
59     }
60 }
61
62