| 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 | #include "HUD_private.hxx" |
| 27 | |
| 28 | #include <Main/globals.hxx> |
| 29 | |
| 30 | // MIL-STD-1787B aiming reticle |
| 31 | |
| 32 | HUD::AimingReticle::AimingReticle(HUD *hud, const SGPropertyNode *n, float x, float y) : |
| 33 | Item(hud, n, x, y), |
| 34 | _active_condition(0), |
| 35 | _tachy_condition(0), |
| 36 | _align_condition(0), |
| 37 | _diameter(n->getNode("diameter-input", false)), |
| 38 | _pitch(n->getNode("pitch-input", false)), |
| 39 | _yaw(n->getNode("yaw-input", false)), |
| 40 | _speed(n->getNode("speed-input", false)), |
| 41 | _range(n->getNode("range-input", false)), |
| 42 | _t0(n->getNode("arc-start-input", false)), |
| 43 | _t1(n->getNode("arc-stop-input", false)), |
| 44 | _offset_x(n->getNode("offset-x-input", false)), |
| 45 | _offset_y(n->getNode("offset-y-input", false)), |
| 46 | _bullet_size(_w / 6.0), |
| 47 | _inner_radius(_w / 2.0), |
| 48 | _compression(n->getFloatValue("compression-factor")), |
| 49 | _limit_x(n->getFloatValue("limit-x")), |
| 50 | _limit_y(n->getFloatValue("limit-y")) |
| 51 | |
| 52 | { |
| 53 | const SGPropertyNode *node = n->getNode("active-condition"); |
| 54 | if (node) |
| 55 | _active_condition = sgReadCondition(globals->get_props(), node); |
| 56 | |
| 57 | const SGPropertyNode *tnode = n->getNode("tachy-condition"); |
| 58 | if (tnode) |
| 59 | _tachy_condition = sgReadCondition(globals->get_props(), tnode); |
| 60 | |
| 61 | const SGPropertyNode *anode = n->getNode("align-condition"); |
| 62 | if (anode) |
| 63 | _align_condition = sgReadCondition(globals->get_props(), anode); |
| 64 | |
| 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() : false; |
| 72 | bool align = _align_condition ? _align_condition->test() : false; |
| 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 | if (active) { // stadiametric (4.2.4.4) |
| 79 | draw_bullet(x, y, _bullet_size); |
| 80 | draw_circle(x, y, _inner_radius); |
| 81 | draw_circle(x, y, diameter * _inner_radius); |
| 82 | } else if (tachy){//tachiametric |
| 83 | float t0 = _t0.isValid() ? _t0.getFloatValue() : 2.0f; // start arc |
| 84 | float t1 = _t1.isValid() ? _t1.getFloatValue() : 2.0f; // stop arc |
| 85 | float yaw_value = _yaw.getFloatValue(); |
| 86 | float pitch_value = _pitch.getFloatValue(); |
| 87 | float tof_value = _range.getFloatValue()* 3 / _speed.getFloatValue(); |
| 88 | draw_bullet(x, y, _bullet_size); |
| 89 | draw_circle(x, y, _inner_radius); |
| 90 | draw_line(x + _inner_radius, y, x + _inner_radius * 3, y); |
| 91 | draw_line(x - _inner_radius, y, x - _inner_radius * 3, y); |
| 92 | draw_line(x, y + _inner_radius, x, y + _inner_radius * 3); |
| 93 | draw_line(x, y - _inner_radius, x, y - _inner_radius * 3); |
| 94 | |
| 95 | if(align){ |
| 96 | draw_line(x + _limit_x, y + _limit_y, x - _limit_x, y + _limit_y); |
| 97 | draw_line(x + _limit_x, y - _limit_y, x - _limit_x, y - _limit_y); |
| 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 | } |
| 101 | |
| 102 | float limit_offset = diameter * _inner_radius; |
| 103 | |
| 104 | float pos_x = x + (yaw_value * tof_value) |
| 105 | * _compression; |
| 106 | |
| 107 | pos_x > x + _limit_x - limit_offset ? |
| 108 | pos_x = x + _limit_x - limit_offset : pos_x; |
| 109 | |
| 110 | pos_x < x - _limit_x + limit_offset ? |
| 111 | pos_x = x - _limit_x + limit_offset: pos_x; |
| 112 | |
| 113 | float pos_y = y + (pitch_value * tof_value) |
| 114 | * _compression; |
| 115 | |
| 116 | pos_y > y + _limit_y - limit_offset ? |
| 117 | pos_y = y + _limit_y - limit_offset : pos_y; |
| 118 | |
| 119 | pos_y < y - _limit_y + limit_offset? |
| 120 | pos_y = y - _limit_y + limit_offset: pos_y; |
| 121 | |
| 122 | draw_circle(pos_x, pos_y, diameter * _inner_radius); |
| 123 | |
| 124 | draw_arc(x, y, t0, t1, (diameter + 2) * _inner_radius ); |
| 125 | |
| 126 | } else { // standby (4.2.4.5) |
| 127 | // TODO |
| 128 | } |
| 129 | |
| 130 | } |
| 131 | |
| 132 |