]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD_misc.cxx
Merge branch 'jmt/gps' 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 _active_condition(0),
32 _tachy_condition(0),
33 _align_condition(0),
34 _diameter(n->getNode("diameter-input", false)),
35 _pitch(n->getNode("pitch-input", false)),
36 _yaw(n->getNode("yaw-input", false)),
37 _speed(n->getNode("speed-input", false)),
38 _range(n->getNode("range-input", false)),
39 _t0(n->getNode("arc-start-input", false)),
40 _t1(n->getNode("arc-stop-input", false)),
41 _offset_x(n->getNode("offset-x-input", false)),
42 _offset_y(n->getNode("offset-y-input", false)),
43 _bullet_size(_w / 6.0),
44 _inner_radius(_w / 2.0),
45 _compression(n->getFloatValue("compression-factor")),
46 _limit_x(n->getFloatValue("limit-x")),
47 _limit_y(n->getFloatValue("limit-y"))
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
65 void HUD::AimingReticle::draw(void)
66 {
67     bool active = _active_condition ? _active_condition->test() : true;
68     bool tachy = _tachy_condition ? _tachy_condition->test() : false;
69     bool align = _align_condition ? _align_condition->test() : false;
70
71     float diameter = _diameter.isValid() ? _diameter.getFloatValue() : 2.0f; // outer circle
72     float x = _center_x + (_offset_x.isValid() ? _offset_x.getFloatValue() : 0);
73     float y = _center_y + (_offset_y.isValid() ? _offset_y.getFloatValue() : 0);
74
75     if (active) { // stadiametric (4.2.4.4)
76         draw_bullet(x, y, _bullet_size);
77         draw_circle(x, y, _inner_radius);
78         draw_circle(x, y, diameter * _inner_radius);
79     } else if (tachy){//tachiametric
80         float t0 = _t0.isValid() ? _t0.getFloatValue() : 2.0f; // start arc
81         float t1 = _t1.isValid() ? _t1.getFloatValue() : 2.0f; // stop arc
82         float yaw_value = _yaw.getFloatValue();
83         float pitch_value = _pitch.getFloatValue();
84         float tof_value = _range.getFloatValue()* 3 / _speed.getFloatValue();
85         draw_bullet(x, y, _bullet_size);
86         draw_circle(x, y, _inner_radius);
87         draw_line(x + _inner_radius, y, x + _inner_radius * 3, y);
88         draw_line(x - _inner_radius, y, x - _inner_radius * 3, y);
89         draw_line(x, y + _inner_radius, x, y + _inner_radius * 3);
90         draw_line(x, y - _inner_radius, x, y - _inner_radius * 3);
91
92         if(align){
93             draw_line(x + _limit_x, y + _limit_y, x - _limit_x, y + _limit_y);
94             draw_line(x + _limit_x, y - _limit_y, x - _limit_x, y - _limit_y);
95             draw_line(x + _limit_x, y + _limit_y, x + _limit_x, y - _limit_y);
96             draw_line(x - _limit_x, y + _limit_y, x - _limit_x, y - _limit_y);
97         }
98
99         float limit_offset = diameter * _inner_radius;
100
101         float pos_x = x + (yaw_value * tof_value)
102             * _compression;
103
104         pos_x > x + _limit_x - limit_offset ? 
105             pos_x = x + _limit_x - limit_offset : pos_x;
106
107         pos_x < x - _limit_x + limit_offset ? 
108             pos_x = x - _limit_x + limit_offset: pos_x;
109
110         float pos_y = y + (pitch_value * tof_value)
111             * _compression;
112
113         pos_y > y + _limit_y - limit_offset ? 
114             pos_y = y + _limit_y - limit_offset : pos_y;
115
116         pos_y < y - _limit_y + limit_offset? 
117             pos_y = y - _limit_y + limit_offset: pos_y;
118
119         draw_circle(pos_x, pos_y, diameter * _inner_radius);
120
121         draw_arc(x, y, t0, t1, (diameter + 2) * _inner_radius );
122
123     } else { // standby (4.2.4.5)
124         // TODO
125     }
126
127 }
128
129