]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD_misc.cxx
Merge branch 'jmt/font' 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 _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")),
44 _active_condition(0),
45 _tachy_condition(0),
46 _align_condition(0),
47 _bullet_size(_w / 6.0),
48 _inner_radius(_w / 2.0)
49
50 {
51     const SGPropertyNode *node = n->getNode("active-condition");
52     if (node)
53         _active_condition = sgReadCondition(globals->get_props(), node);
54
55     const SGPropertyNode *tnode = n->getNode("tachy-condition");
56     if (tnode)
57         _tachy_condition = sgReadCondition(globals->get_props(), tnode);
58     
59     const SGPropertyNode *anode = n->getNode("align-condition");
60     if (anode)
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();
65 }
66
67
68 void HUD::AimingReticle::draw(void)
69 {
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;
73
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);
77
78
79 //        SG_LOG(SG_INPUT, SG_ALERT, "HUD: compression" << _compression);
80
81 //        SG_LOG(SG_INPUT, SG_ALERT, "HUD: limit_x" << _limit_x);
82
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();
93         
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);
100
101         if(align){
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);
106         }
107
108         float limit_offset = diameter * _inner_radius;
109
110         float pos_x = x + (yaw_value * tof_value)
111             * _compression;
112
113         pos_x > x + _limit_x - limit_offset ? 
114             pos_x = x + _limit_x - limit_offset : pos_x;
115
116         pos_x < x - _limit_x + limit_offset ? 
117             pos_x = x - _limit_x + limit_offset: pos_x;
118
119         float pos_y = y + (pitch_value * tof_value)
120             * _compression;
121
122         pos_y > y + _limit_y - limit_offset ? 
123             pos_y = y + _limit_y - limit_offset : pos_y;
124
125         pos_y < y - _limit_y + limit_offset? 
126             pos_y = y - _limit_y + limit_offset: pos_y;
127
128         //        SG_LOG(SG_INPUT, SG_ALERT, "HUD: pos y" << pos_y);
129
130         draw_circle(pos_x, pos_y, diameter * _inner_radius);
131
132         draw_arc(x, y, t0, t1, (diameter + 2) * _inner_radius );
133
134     } else { // standby (4.2.4.5)
135         // TODO
136     }
137
138 }
139
140