]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD_misc.cxx
Merge branch 'vivian/tachy' into next
[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 "HUD.hxx"
26
27 // MIL-STD-1787B aiming reticle
28
29 HUD::AimingReticle::AimingReticle(HUD *hud, const SGPropertyNode *n, float x, float y) :
30 Item(hud, n, x, y),
31 _pitch(n->getNode("pitch-input", false)),
32 _yaw(n->getNode("yaw-input", false)),
33 _speed(n->getNode("speed-input", false)),
34 _range(n->getNode("range-input", false)),
35 _offset_x(n->getNode("offset-x-input", false)),
36 _offset_y(n->getNode("offset-y-input", false)),
37 _diameter(n->getNode("diameter-input", false)),
38 _t0(n->getNode("arc-start-input", false)),
39 _t1(n->getNode("arc-stop-input", false)),
40 _compression(n->getFloatValue("compression-factor")),
41 _limit_x(n->getFloatValue("limit-x")),
42 _limit_y(n->getFloatValue("limit-y")),
43 _active_condition(0),
44 _tachy_condition(0),
45 _align_condition(0),
46 _bullet_size(_w / 6.0),
47 _inner_radius(_w / 2.0)
48
49 {
50     const SGPropertyNode *node = n->getNode("active-condition");
51     if (node)
52         _active_condition = sgReadCondition(globals->get_props(), node);
53
54     const SGPropertyNode *tnode = n->getNode("tachy-condition");
55     if (tnode)
56         _tachy_condition = sgReadCondition(globals->get_props(), tnode);
57     
58     const SGPropertyNode *anode = n->getNode("align-condition");
59     if (anode)
60         _align_condition = sgReadCondition(globals->get_props(), anode);
61 }
62
63
64 void HUD::AimingReticle::draw(void)
65 {
66     bool active = _active_condition ? _active_condition->test() : true;
67     bool tachy = _tachy_condition ? _tachy_condition->test() : true;
68     bool align = _align_condition ? _align_condition->test() : true;
69
70     float diameter = _diameter.isValid() ? _diameter.getFloatValue() : 2.0f; // outer circle
71     float x = _center_x + _offset_x.getFloatValue();
72     float y = _center_y + _offset_y.getFloatValue();
73
74     float t0 = _t0.isValid() ? _t0.getFloatValue() : 2.0f; // start arc
75     float t1 = _t1.isValid() ? _t1.getFloatValue() : 2.0f; // start arc
76
77     float yaw_value = _yaw.getFloatValue();
78     float pitch_value = _pitch.getFloatValue();
79     float tof_value = _range.getFloatValue()* 3 / _speed.getFloatValue();
80
81 //        SG_LOG(SG_INPUT, SG_ALERT, "HUD: compression" << _compression);
82
83 //        SG_LOG(SG_INPUT, SG_ALERT, "HUD: limit_x" << _limit_x);
84
85     if (active) { // stadiametric (4.2.4.4)
86         draw_bullet(x, y, _bullet_size);
87         draw_circle(x, y, _inner_radius);
88         draw_circle(x, y, diameter * _inner_radius);
89     } else if (tachy){//tachiametric
90         draw_bullet(x, y, _bullet_size);
91         draw_circle(x, y, _inner_radius);
92         draw_line(x + _inner_radius, y, x + _inner_radius * 3, y);
93         draw_line(x - _inner_radius, y, x - _inner_radius * 3, y);
94         draw_line(x, y + _inner_radius, x, y + _inner_radius * 3);
95         draw_line(x, y - _inner_radius, x, y - _inner_radius * 3);
96
97         if(align){
98             draw_line(x + _limit_x, y + _limit_y, x - _limit_x, y + _limit_y);
99             draw_line(x + _limit_x, y - _limit_y, x - _limit_x, y - _limit_y);
100             draw_line(x + _limit_x, y + _limit_y, x + _limit_x, y - _limit_y);
101             draw_line(x - _limit_x, y + _limit_y, x - _limit_x, y - _limit_y);
102         }
103
104         float limit_offset = diameter * _inner_radius;
105
106         float pos_x = x + (yaw_value * tof_value)
107             * _compression;
108
109         pos_x > x + _limit_x - limit_offset ? 
110             pos_x = x + _limit_x - limit_offset : pos_x;
111
112         pos_x < x - _limit_x + limit_offset ? 
113             pos_x = x - _limit_x + limit_offset: pos_x;
114
115         float pos_y = y + (pitch_value * tof_value)
116             * _compression;
117
118         pos_y > y + _limit_y - limit_offset ? 
119             pos_y = y + _limit_y - limit_offset : pos_y;
120
121         pos_y < y - _limit_y + limit_offset? 
122             pos_y = y - _limit_y + limit_offset: pos_y;
123
124         //        SG_LOG(SG_INPUT, SG_ALERT, "HUD: pos y" << pos_y);
125
126         draw_circle(pos_x, pos_y, diameter * _inner_radius);
127
128         draw_arc(x, y, t0, t1, (diameter + 2) * _inner_radius );
129
130     } else { // standby (4.2.4.5)
131         // TODO
132     }
133
134 }
135
136