1 // HUD_misc.cxx -- HUD miscellaneous elements
3 // Written by Melchior FRANZ, started September 2006.
5 // Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
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.
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.
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.
27 // MIL-STD-1787B aiming reticle
29 HUD::AimingReticle::AimingReticle(HUD *hud, const SGPropertyNode *n, float x, float y) :
31 _diameter(n->getNode("diameter-input", false)),
32 _pitch(n->getNode("pitch-input", false)),
33 _yaw(n->getNode("yaw-input", false)),
34 _speed(n->getNode("speed-input", false)),
35 _range(n->getNode("range-input", false)),
36 _t0(n->getNode("arc-start-input", false)),
37 _t1(n->getNode("arc-stop-input", false)),
38 _offset_x(n->getNode("offset-x-input", false)),
39 _offset_y(n->getNode("offset-y-input", false)),
40 _hasTachyInputs(false),
41 _compression(n->getFloatValue("compression-factor")),
42 _limit_x(n->getFloatValue("limit-x")),
43 _limit_y(n->getFloatValue("limit-y")),
47 _bullet_size(_w / 6.0),
48 _inner_radius(_w / 2.0)
51 const SGPropertyNode *node = n->getNode("active-condition");
53 _active_condition = sgReadCondition(globals->get_props(), node);
55 const SGPropertyNode *tnode = n->getNode("tachy-condition");
57 _tachy_condition = sgReadCondition(globals->get_props(), tnode);
59 const SGPropertyNode *anode = n->getNode("align-condition");
61 _align_condition = sgReadCondition(globals->get_props(), anode);
62 _hasTachyInputs = _pitch.isValid() && _yaw.isValid() && _speed.isValid()
63 && _range.isValid() && _t0.isValid() && _t1.isValid()
64 && _offset_x.isValid() && _offset_y.isValid();
68 void HUD::AimingReticle::draw(void)
70 bool active = _active_condition ? _active_condition->test() : true;
71 bool tachy = _tachy_condition ? _tachy_condition->test() : true;
72 bool align = _align_condition ? _align_condition->test() : true;
74 float diameter = _diameter.isValid() ? _diameter.getFloatValue() : 2.0f; // outer circle
75 float x = _center_x + (_offset_x.isValid() ? _offset_x.getFloatValue() : 0);
76 float y = _center_y + (_offset_y.isValid() ? _offset_y.getFloatValue() : 0);
79 // SG_LOG(SG_INPUT, SG_ALERT, "HUD: compression" << _compression);
81 // SG_LOG(SG_INPUT, SG_ALERT, "HUD: limit_x" << _limit_x);
83 if (active) { // stadiametric (4.2.4.4)
84 draw_bullet(x, y, _bullet_size);
85 draw_circle(x, y, _inner_radius);
86 draw_circle(x, y, diameter * _inner_radius);
87 } else if (tachy && _hasTachyInputs){//tachiametric
88 float t0 = _t0.isValid() ? _t0.getFloatValue() : 2.0f; // start arc
89 float t1 = _t1.isValid() ? _t1.getFloatValue() : 2.0f; // start arc
90 float yaw_value = _yaw.getFloatValue();
91 float pitch_value = _pitch.getFloatValue();
92 float tof_value = _range.getFloatValue()* 3 / _speed.getFloatValue();
94 draw_bullet(x, y, _bullet_size);
95 draw_circle(x, y, _inner_radius);
96 draw_line(x + _inner_radius, y, x + _inner_radius * 3, y);
97 draw_line(x - _inner_radius, y, x - _inner_radius * 3, y);
98 draw_line(x, y + _inner_radius, x, y + _inner_radius * 3);
99 draw_line(x, y - _inner_radius, x, y - _inner_radius * 3);
102 draw_line(x + _limit_x, y + _limit_y, x - _limit_x, y + _limit_y);
103 draw_line(x + _limit_x, y - _limit_y, x - _limit_x, y - _limit_y);
104 draw_line(x + _limit_x, y + _limit_y, x + _limit_x, y - _limit_y);
105 draw_line(x - _limit_x, y + _limit_y, x - _limit_x, y - _limit_y);
108 float limit_offset = diameter * _inner_radius;
110 float pos_x = x + (yaw_value * tof_value)
113 pos_x > x + _limit_x - limit_offset ?
114 pos_x = x + _limit_x - limit_offset : pos_x;
116 pos_x < x - _limit_x + limit_offset ?
117 pos_x = x - _limit_x + limit_offset: pos_x;
119 float pos_y = y + (pitch_value * tof_value)
122 pos_y > y + _limit_y - limit_offset ?
123 pos_y = y + _limit_y - limit_offset : pos_y;
125 pos_y < y - _limit_y + limit_offset?
126 pos_y = y - _limit_y + limit_offset: pos_y;
128 // SG_LOG(SG_INPUT, SG_ALERT, "HUD: pos y" << pos_y);
130 draw_circle(pos_x, pos_y, diameter * _inner_radius);
132 draw_arc(x, y, t0, t1, (diameter + 2) * _inner_radius );
134 } else { // standby (4.2.4.5)