| 1 | // HUD_ladder.cxx -- HUD Ladder Instrument |
| 2 | // |
| 3 | // Written by Michele America, started September 1997. |
| 4 | // |
| 5 | // Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com] |
| 6 | // Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at] |
| 7 | // |
| 8 | // This program is free software; you can redistribute it and/or |
| 9 | // modify it under the terms of the GNU General Public License as |
| 10 | // published by the Free Software Foundation; either version 2 of the |
| 11 | // License, or (at your option) any later version. |
| 12 | // |
| 13 | // This program is distributed in the hope that it will be useful, but |
| 14 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | // General Public License for more details. |
| 17 | // |
| 18 | // You should have received a copy of the GNU General Public License |
| 19 | // along with this program; if not, write to the Free Software |
| 20 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 21 | |
| 22 | #ifdef HAVE_CONFIG_H |
| 23 | # include <config.h> |
| 24 | #endif |
| 25 | |
| 26 | #include <sstream> |
| 27 | #include <simgear/math/SGGeometry.hxx> |
| 28 | #include <Viewer/view.hxx> |
| 29 | |
| 30 | #include "HUD.hxx" |
| 31 | #include "HUD_private.hxx" |
| 32 | |
| 33 | #include <Main/fg_props.hxx> |
| 34 | |
| 35 | using std::string; |
| 36 | |
| 37 | // FIXME |
| 38 | static float get__heading() { return fgGetFloat("/orientation/heading-deg") * M_PI / 180.0; } |
| 39 | static float get__throttleval() { return fgGetFloat("/controls/engines/engine/throttle"); } |
| 40 | static float get__Vx() { return fgGetFloat("/velocities/uBody-fps"); } |
| 41 | static float get__Vy() { return fgGetFloat("/velocities/vBody-fps"); } |
| 42 | static float get__Vz() { return fgGetFloat("/velocities/wBody-fps"); } |
| 43 | static float get__Ax() { return fgGetFloat("/accelerations/pilot/x-accel-fps_sec"); } |
| 44 | static float get__Ay() { return fgGetFloat("/accelerations/pilot/y-accel-fps_sec"); } |
| 45 | static float get__Az() { return fgGetFloat("/accelerations/pilot/z-accel-fps_sec"); } |
| 46 | static float get__alpha() { return fgGetFloat("/orientation/alpha-deg"); } |
| 47 | static float get__beta() { return fgGetFloat("/orientation/side-slip-deg"); } |
| 48 | #undef ENABLE_SP_FDM |
| 49 | |
| 50 | |
| 51 | HUD::Ladder::Ladder(HUD *hud, const SGPropertyNode *n, float x, float y) : |
| 52 | Item(hud, n, x, y), |
| 53 | _pitch(n->getNode("pitch-input", false)), |
| 54 | _roll(n->getNode("roll-input", false)), |
| 55 | _width_units(int(n->getFloatValue("display-span"))), |
| 56 | _div_units(int(fabs(n->getFloatValue("divisions")))), |
| 57 | _scr_hole(fabs(n->getFloatValue("screen-hole")) * 0.5f), |
| 58 | _zero_bar_overlength(n->getFloatValue("zero-bar-overlength", 10)), |
| 59 | _dive_bar_angle(n->getBoolValue("enable-dive-bar-angle")), |
| 60 | _tick_length(n->getFloatValue("tick-length")), |
| 61 | _compression(n->getFloatValue("compression-factor")), |
| 62 | _dynamic_origin(n->getBoolValue("enable-dynamic-origin")), |
| 63 | _frl(n->getBoolValue("enable-fuselage-ref-line")), |
| 64 | _target_spot(n->getBoolValue("enable-target-spot")), |
| 65 | _target_markers(n->getBoolValue("enable-target-markers")), |
| 66 | _velocity_vector(n->getBoolValue("enable-velocity-vector")), |
| 67 | _ground_velocity_vector(n->getBoolValue("enable-ground-velocity-vector")), |
| 68 | _drift_marker(n->getBoolValue("enable-drift-marker")), |
| 69 | _alpha_bracket(n->getBoolValue("enable-alpha-bracket")), |
| 70 | _energy_marker(n->getBoolValue("enable-energy-marker")), |
| 71 | _climb_dive_marker(n->getBoolValue("enable-climb-dive-marker")), |
| 72 | _glide_slope_marker(n->getBoolValue("enable-glide-slope-marker")), |
| 73 | _glide_slope(n->getFloatValue("glide-slope", -4.0)), |
| 74 | _energy_worm(n->getBoolValue("enable-energy-marker")), |
| 75 | _waypoint_marker(n->getBoolValue("enable-waypoint-marker")), |
| 76 | _zenith(n->getBoolValue("enable-zenith")), |
| 77 | _nadir(n->getBoolValue("enable-nadir")), |
| 78 | _hat(n->getBoolValue("enable-hat")), |
| 79 | _clip_box(new ClipBox(n->getNode("clipping"))) |
| 80 | { |
| 81 | string t = n->getStringValue("type"); |
| 82 | _type = t != "climb-dive" ? PITCH : CLIMB_DIVE; |
| 83 | |
| 84 | if (!_width_units) |
| 85 | _width_units = 45; |
| 86 | |
| 87 | _vmax = _width_units / 2; |
| 88 | _vmin = -_vmax; |
| 89 | } |
| 90 | |
| 91 | |
| 92 | HUD::Ladder::~Ladder() |
| 93 | { |
| 94 | delete _clip_box; |
| 95 | } |
| 96 | |
| 97 | void HUD::Ladder::draw(void) |
| 98 | { |
| 99 | if (!_pitch.isValid() || !_roll.isValid()) |
| 100 | return; |
| 101 | |
| 102 | float roll_value = _roll.getFloatValue() * SGD_DEGREES_TO_RADIANS; |
| 103 | float pitch_value = _pitch.getFloatValue(); |
| 104 | |
| 105 | //************************************************************** |
| 106 | glPushMatrix(); |
| 107 | glTranslatef(_center_x, _center_y, 0); |
| 108 | |
| 109 | // OBJECT STATIC RETICLE |
| 110 | // TYPE FRL (FUSELAGE REFERENCE LINE) |
| 111 | // ATTRIB - ALWAYS |
| 112 | // Draw the FRL spot and line |
| 113 | if (_frl) { |
| 114 | #define FRL_DIAMOND_SIZE 2.0 |
| 115 | glBegin(GL_LINE_LOOP); |
| 116 | glVertex2f(-FRL_DIAMOND_SIZE, 0.0); |
| 117 | glVertex2f(0.0, FRL_DIAMOND_SIZE); |
| 118 | glVertex2f(FRL_DIAMOND_SIZE, 0.0); |
| 119 | glVertex2f(0.0, -FRL_DIAMOND_SIZE); |
| 120 | glEnd(); |
| 121 | |
| 122 | glBegin(GL_LINE_STRIP); |
| 123 | glVertex2f(0, FRL_DIAMOND_SIZE); |
| 124 | glVertex2f(0, 8.0); |
| 125 | glEnd(); |
| 126 | #undef FRL_DIAMOND_SIZE |
| 127 | } |
| 128 | // TYPE WATERLINE_MARK (W shaped _ _ ) // TODO (-> HUD_misc.cxx) |
| 129 | // \/\/ |
| 130 | |
| 131 | //**************************************************************** |
| 132 | // TYPE TARGET_SPOT |
| 133 | // Draw the target spot. |
| 134 | if (_target_spot) { |
| 135 | #define CENTER_DIAMOND_SIZE 6.0 |
| 136 | glBegin(GL_LINE_LOOP); |
| 137 | glVertex2f(-CENTER_DIAMOND_SIZE, 0.0); |
| 138 | glVertex2f(0.0, CENTER_DIAMOND_SIZE); |
| 139 | glVertex2f(CENTER_DIAMOND_SIZE, 0.0); |
| 140 | glVertex2f(0.0, -CENTER_DIAMOND_SIZE); |
| 141 | glEnd(); |
| 142 | #undef CENTER_DIAMOND_SIZE |
| 143 | } |
| 144 | |
| 145 | //**************************************************************** |
| 146 | //velocity vector reticle - computations |
| 147 | float xvvr, /* yvvr, */ Vxx = 0.0, Vyy = 0.0, Vzz = 0.0; |
| 148 | float Axx = 0.0, Ayy = 0.0, Azz = 0.0, total_vel = 0.0, pot_slope; //, t1; |
| 149 | float up_vel, ground_vel, actslope = 0.0, psi = 0.0; |
| 150 | float vel_x = 0.0, vel_y = 0.0, drift; |
| 151 | float alpha; |
| 152 | |
| 153 | if (_ground_velocity_vector || _velocity_vector) { |
| 154 | Vxx = get__Vx(); |
| 155 | Vyy = get__Vy(); |
| 156 | Vzz = get__Vz(); |
| 157 | } |
| 158 | |
| 159 | if (_ground_velocity_vector) { |
| 160 | double gvel_x = atan2(Vyy, Vxx) * SGD_RADIANS_TO_DEGREES * _compression; |
| 161 | double gvel_y = -atan2(Vzz, Vxx) * SGD_RADIANS_TO_DEGREES * _compression; |
| 162 | |
| 163 | /* \ / |
| 164 | | |
| 165 | */ |
| 166 | int outer = 8; |
| 167 | int inner = 2; |
| 168 | glBegin(GL_LINE_STRIP); |
| 169 | glVertex2f(gvel_x - outer, gvel_y + outer); |
| 170 | glVertex2f(gvel_x - inner, gvel_y + inner); |
| 171 | glEnd(); |
| 172 | glBegin(GL_LINE_STRIP); |
| 173 | glVertex2f(gvel_x + outer, gvel_y + outer); |
| 174 | glVertex2f(gvel_x + inner, gvel_y + inner); |
| 175 | glEnd(); |
| 176 | glBegin(GL_LINE_STRIP); |
| 177 | glVertex2f(gvel_x + 0, gvel_y - inner*3/2); |
| 178 | glVertex2f(gvel_x + 0, gvel_y - outer*3/2); |
| 179 | glEnd(); |
| 180 | } |
| 181 | |
| 182 | if (_velocity_vector) { |
| 183 | drift = get__beta(); |
| 184 | alpha = get__alpha(); |
| 185 | |
| 186 | Axx = get__Ax(); |
| 187 | Ayy = get__Ay(); |
| 188 | Azz = get__Az(); |
| 189 | psi = get__heading(); |
| 190 | |
| 191 | if (psi > 180.0) |
| 192 | psi = psi - 360; |
| 193 | |
| 194 | total_vel = sqrt(Vxx * Vxx + Vyy * Vyy + Vzz * Vzz); |
| 195 | ground_vel = sqrt(Vxx * Vxx + Vyy * Vyy); |
| 196 | up_vel = Vzz; |
| 197 | |
| 198 | if (ground_vel < 2.0) { |
| 199 | if (fabs(up_vel) < 2.0) |
| 200 | actslope = 0.0; |
| 201 | else |
| 202 | actslope = (up_vel / fabs(up_vel)) * 90.0; |
| 203 | |
| 204 | } else { |
| 205 | actslope = atan(up_vel / ground_vel) * SGD_RADIANS_TO_DEGREES; |
| 206 | } |
| 207 | |
| 208 | xvvr = drift * _compression; |
| 209 | // drift = ((atan2(Vyy, Vxx) * SGD_RADIANS_TO_DEGREES) - psi); |
| 210 | // yvvr = (-alpha * _compression); |
| 211 | // vel_y = (-alpha * cos(roll_value) + drift * sin(roll_value)) * _compression; |
| 212 | // vel_x = (alpha * sin(roll_value) + drift * cos(roll_value)) |
| 213 | // * (_compression / globals->get_current_view()->get_aspect_ratio()); |
| 214 | vel_y = -alpha * _compression; |
| 215 | vel_x = drift * _compression; |
| 216 | // printf("%f %f %f %f\n",vel_x, vel_y, drift, psi); |
| 217 | |
| 218 | //**************************************************************** |
| 219 | // OBJECT MOVING RETICLE |
| 220 | // TYPE - DRIFT MARKER |
| 221 | // ATTRIB - ALWAYS |
| 222 | // drift marker |
| 223 | if (_drift_marker) { |
| 224 | glBegin(GL_LINE_STRIP); |
| 225 | glVertex2f((xvvr * 25 / 120) - 6, -4); |
| 226 | glVertex2f(xvvr * 25 / 120, 8); |
| 227 | glVertex2f((xvvr * 25 / 120) + 6, -4); |
| 228 | glEnd(); |
| 229 | } |
| 230 | |
| 231 | //**************************************************************** |
| 232 | // OBJECT MOVING RETICLE |
| 233 | // TYPE VELOCITY VECTOR |
| 234 | // ATTRIB - ALWAYS |
| 235 | // velocity vector |
| 236 | draw_circle(vel_x, vel_y, 6); |
| 237 | |
| 238 | //velocity vector reticle orientation lines |
| 239 | glBegin(GL_LINE_STRIP); |
| 240 | glVertex2f(vel_x - 12, vel_y); |
| 241 | glVertex2f(vel_x - 6, vel_y); |
| 242 | glEnd(); |
| 243 | glBegin(GL_LINE_STRIP); |
| 244 | glVertex2f(vel_x + 12, vel_y); |
| 245 | glVertex2f(vel_x + 6, vel_y); |
| 246 | glEnd(); |
| 247 | glBegin(GL_LINE_STRIP); |
| 248 | glVertex2f(vel_x, vel_y + 12); |
| 249 | glVertex2f(vel_x, vel_y + 6); |
| 250 | glEnd(); |
| 251 | |
| 252 | #ifdef ENABLE_SP_FDM |
| 253 | int lgear = get__iaux3(); |
| 254 | int ihook = get__iaux6(); |
| 255 | |
| 256 | // OBJECT MOVING RETICLE |
| 257 | // TYPE LINE |
| 258 | // ATTRIB - ON CONDITION |
| 259 | if (lgear == 1) { |
| 260 | // undercarriage status |
| 261 | glBegin(GL_LINE_STRIP); |
| 262 | glVertex2f(vel_x + 8, vel_y); |
| 263 | glVertex2f(vel_x + 8, vel_y - 4); |
| 264 | glEnd(); |
| 265 | |
| 266 | // OBJECT MOVING RETICLE |
| 267 | // TYPE LINE |
| 268 | // ATTRIB - ON CONDITION |
| 269 | glBegin(GL_LINE_STRIP); |
| 270 | glVertex2f(vel_x - 8, vel_y); |
| 271 | glVertex2f(vel_x - 8, vel_y - 4); |
| 272 | glEnd(); |
| 273 | |
| 274 | // OBJECT MOVING RETICLE |
| 275 | // TYPE LINE |
| 276 | // ATTRIB - ON CONDITION |
| 277 | glBegin(GL_LINE_STRIP); |
| 278 | glVertex2f(vel_x, vel_y - 6); |
| 279 | glVertex2f(vel_x, vel_y - 10); |
| 280 | glEnd(); |
| 281 | } |
| 282 | |
| 283 | // OBJECT MOVING RETICLE |
| 284 | // TYPE V |
| 285 | // ATTRIB - ON CONDITION |
| 286 | if (ihook == 1) { |
| 287 | // arrestor hook status |
| 288 | glBegin(GL_LINE_STRIP); |
| 289 | glVertex2f(vel_x - 4, vel_y - 8); |
| 290 | glVertex2f(vel_x, vel_y - 10); |
| 291 | glVertex2f(vel_x + 4, vel_y - 8); |
| 292 | glEnd(); |
| 293 | } |
| 294 | #endif |
| 295 | } // if _velocity_vector |
| 296 | |
| 297 | // draw hud markers on top of each AI/MP target |
| 298 | if (_target_markers) { |
| 299 | SGPropertyNode *models = globals->get_props()->getNode("/ai/models", true); |
| 300 | for (int i = 0; i < models->nChildren(); i++) { |
| 301 | SGPropertyNode *chld = models->getChild(i); |
| 302 | string name; |
| 303 | name = chld->getNameString(); |
| 304 | if (name == "tanker" || name == "aircraft" || name == "multiplayer") { |
| 305 | bool valid = chld->getBoolValue("valid"); |
| 306 | bool in_range = chld->getBoolValue("radar/in-range", true); |
| 307 | if (valid && in_range) { |
| 308 | float h_deg = chld->getFloatValue("radar/h-offset"); |
| 309 | float v_deg = chld->getFloatValue("radar/v-offset"); |
| 310 | float pos_x = (h_deg * cos(roll_value) - |
| 311 | v_deg * sin(roll_value)) * _compression; |
| 312 | float pos_y = (v_deg * cos(roll_value) + |
| 313 | h_deg * sin(roll_value)) * _compression; |
| 314 | draw_circle(pos_x, pos_y, 8); |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | //*************************************************************** |
| 321 | // OBJECT MOVING RETICLE |
| 322 | // TYPE - SQUARE_BRACKET |
| 323 | // ATTRIB - ON CONDITION |
| 324 | // alpha bracket |
| 325 | #ifdef ENABLE_SP_FDM |
| 326 | alpha = get__alpha(); |
| 327 | |
| 328 | if (_alpha_bracket && ihook == 1) { |
| 329 | glBegin(GL_LINE_STRIP); |
| 330 | glVertex2f(vel_x - 20, vel_y - (16 - alpha) * _compression); |
| 331 | glVertex2f(vel_x - 17, vel_y - (16 - alpha) * _compression); |
| 332 | glVertex2f(vel_x - 17, vel_y - (14 - alpha) * _compression); |
| 333 | glVertex2f(vel_x - 20, vel_y - (14 - alpha) * _compression); |
| 334 | glEnd(); |
| 335 | |
| 336 | glBegin(GL_LINE_STRIP); |
| 337 | glVertex2f(vel_x + 20, vel_y - (16 - alpha) * _compression); |
| 338 | glVertex2f(vel_x + 17, vel_y - (16 - alpha) * _compression); |
| 339 | glVertex2f(vel_x + 17, vel_y - (14 - alpha) * _compression); |
| 340 | glVertex2f(vel_x + 20, vel_y - (14 - alpha) * _compression); |
| 341 | glEnd(); |
| 342 | } |
| 343 | #endif |
| 344 | //printf("xvr=%f, yvr=%f, Vx=%f, Vy=%f, Vz=%f\n",xvvr, yvvr, Vx, Vy, Vz); |
| 345 | //printf("Ax=%f, Ay=%f, Az=%f\n",Ax, Ay, Az); |
| 346 | |
| 347 | //**************************************************************** |
| 348 | // OBJECT MOVING RETICLE |
| 349 | // TYPE ENERGY_MARKERS |
| 350 | // ATTRIB - ALWAYS |
| 351 | //energy markers - compute potential slope |
| 352 | float pla = get__throttleval(); |
| 353 | float t2 = 0.0; |
| 354 | |
| 355 | if (_energy_marker) { |
| 356 | if (total_vel < 5.0) { |
| 357 | // t1 = 0; |
| 358 | t2 = 0; |
| 359 | } else { |
| 360 | // t1 = up_vel / total_vel; |
| 361 | t2 = asin((Vxx * Axx + Vyy * Ayy + Vzz * Azz) / (9.81 * total_vel)); |
| 362 | } |
| 363 | pot_slope = ((t2 / 3) * SGD_RADIANS_TO_DEGREES) * _compression + vel_y; |
| 364 | // if (pot_slope < (vel_y - 45)) pot_slope = vel_y - 45; |
| 365 | // if (pot_slope > (vel_y + 45)) pot_slope = vel_y + 45; |
| 366 | |
| 367 | //energy markers |
| 368 | glBegin(GL_LINE_STRIP); |
| 369 | glVertex2f(vel_x - 20, pot_slope - 5); |
| 370 | glVertex2f(vel_x - 15, pot_slope); |
| 371 | glVertex2f(vel_x - 20, pot_slope + 5); |
| 372 | glEnd(); |
| 373 | |
| 374 | glBegin(GL_LINE_STRIP); |
| 375 | glVertex2f(vel_x + 20, pot_slope - 5); |
| 376 | glVertex2f(vel_x + 15, pot_slope); |
| 377 | glVertex2f(vel_x + 20, pot_slope + 5); |
| 378 | glEnd(); |
| 379 | |
| 380 | if (pla > (105.0 / 131.0)) { |
| 381 | glBegin(GL_LINE_STRIP); |
| 382 | glVertex2f(vel_x - 24, pot_slope - 5); |
| 383 | glVertex2f(vel_x - 19, pot_slope); |
| 384 | glVertex2f(vel_x - 24, pot_slope + 5); |
| 385 | glEnd(); |
| 386 | |
| 387 | glBegin(GL_LINE_STRIP); |
| 388 | glVertex2f(vel_x + 24, pot_slope - 5); |
| 389 | glVertex2f(vel_x + 19, pot_slope); |
| 390 | glVertex2f(vel_x + 24, pot_slope + 5); |
| 391 | glEnd(); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | //********************************************************** |
| 396 | // ramp reticle |
| 397 | // OBJECT STATIC RETICLE |
| 398 | // TYPE LINE |
| 399 | // ATTRIB - ON CONDITION |
| 400 | #ifdef ENABLE_SP_FDM |
| 401 | int ilcanclaw = get__iaux2(); |
| 402 | |
| 403 | if (_energy_worm && ilcanclaw == 1) { |
| 404 | glBegin(GL_LINE_STRIP); |
| 405 | glVertex2f(-15, -134); |
| 406 | glVertex2f(15, -134); |
| 407 | glEnd(); |
| 408 | |
| 409 | // OBJECT MOVING RETICLE |
| 410 | // TYPE BOX |
| 411 | // ATTRIB - ON CONDITION |
| 412 | glBegin(GL_LINE_STRIP); |
| 413 | glVertex2f(-6, -134); |
| 414 | glVertex2f(-6, t2 * SGD_RADIANS_TO_DEGREES * 4.0 - 134); |
| 415 | glVertex2f(+6, t2 * SGD_RADIANS_TO_DEGREES * 4.0 - 134); |
| 416 | glVertex2f(6, -134); |
| 417 | glEnd(); |
| 418 | |
| 419 | // OBJECT MOVING RETICLE |
| 420 | // TYPE DIAMOND |
| 421 | // ATTRIB - ON CONDITION |
| 422 | glBegin(GL_LINE_LOOP); |
| 423 | glVertex2f(-6, actslope * 4.0 - 134); |
| 424 | glVertex2f(0, actslope * 4.0 -134 + 3); |
| 425 | glVertex2f(6, actslope * 4.0 - 134); |
| 426 | glVertex2f(0, actslope * 4.0 -134 -3); |
| 427 | glEnd(); |
| 428 | } |
| 429 | #endif |
| 430 | |
| 431 | //************************************************************* |
| 432 | // OBJECT MOVING RETICLE |
| 433 | // TYPE DIAMOND |
| 434 | // ATTRIB - ALWAYS |
| 435 | // Draw the locked velocity vector. |
| 436 | if (_climb_dive_marker) { |
| 437 | glBegin(GL_LINE_LOOP); |
| 438 | glVertex2f(-3.0, 0.0 + vel_y); |
| 439 | glVertex2f(0.0, 6.0 + vel_y); |
| 440 | glVertex2f(3.0, 0.0 + vel_y); |
| 441 | glVertex2f(0.0, -6.0 + vel_y); |
| 442 | glEnd(); |
| 443 | } |
| 444 | |
| 445 | //**************************************************************** |
| 446 | |
| 447 | _clip_box->set(); |
| 448 | |
| 449 | if (_dynamic_origin) { |
| 450 | // ladder moves with alpha/beta offset projected onto horizon |
| 451 | // line (so that the horizon line always aligns with the |
| 452 | // actual horizon. |
| 453 | _vmin = pitch_value - _width_units * 0.5f; |
| 454 | _vmax = pitch_value + _width_units * 0.5f; |
| 455 | { |
| 456 | // the hud ladder center point should move relative to alpha/beta |
| 457 | // however the horizon line should always stay on the horizon. We |
| 458 | // project the alpha/beta offset onto the horizon line to get the |
| 459 | // result we want. |
| 460 | |
| 461 | SGVec3d d(cos(roll_value), sin(roll_value), 0.0); |
| 462 | SGRayd r(SGVec3d::zeros(), d); |
| 463 | SGVec3d p = r.getClosestPointTo(SGVec3d(vel_x, vel_y, 0.0)); |
| 464 | glTranslatef(p[0], p[1], 0); |
| 465 | } |
| 466 | } else { |
| 467 | // ladder position is fixed relative to the center of the screen. |
| 468 | _vmin = pitch_value - _width_units * 0.5f; |
| 469 | _vmax = pitch_value + _width_units * 0.5f; |
| 470 | } |
| 471 | |
| 472 | glRotatef(roll_value * SGD_RADIANS_TO_DEGREES, 0.0, 0.0, 1.0); |
| 473 | |
| 474 | // FRL marker not rotated - this line shifted below |
| 475 | float half_span = _w * 0.5f; |
| 476 | float y = 0; |
| 477 | struct { float x, y; } lo, li, ri, ro, numoffs; // left/right inner/outer |
| 478 | |
| 479 | if (_div_units) { |
| 480 | _locTextList.setFont(_hud->_font_renderer); |
| 481 | _locTextList.erase(); |
| 482 | _locLineList.erase(); |
| 483 | _locStippleLineList.erase(); |
| 484 | |
| 485 | for (int i = int(_vmin); i < int(_vmax) + 1; i++) { |
| 486 | if (i % _div_units) |
| 487 | continue; |
| 488 | |
| 489 | if (_type == PITCH) |
| 490 | y = float(i - pitch_value) * _compression + .5; |
| 491 | else // _type == CLIMB_DIVE |
| 492 | y = float(i - actslope) * _compression + .5; |
| 493 | |
| 494 | // OBJECT LADDER MARK |
| 495 | // TYPE LINE |
| 496 | // ATTRIB - ON CONDITION |
| 497 | // draw approach glide slope marker |
| 498 | #ifdef ENABLE_SP_FDM |
| 499 | if (_glide_slope_marker && ihook) { |
| 500 | draw_line(-half_span + 15, (_glide_slope - actslope) * _compression, |
| 501 | -half_span + hole, (_glide_slope - actslope) * _compression); |
| 502 | draw_line(half_span - 15, (_glide_slope - actslope) * _compression, |
| 503 | half_span - hole, (_glide_slope - actslope) * _compression); |
| 504 | } |
| 505 | #endif |
| 506 | |
| 507 | // draw symbols |
| 508 | if (i == 90 && _zenith) |
| 509 | draw_zenith(0.0, y); |
| 510 | else if (i == -90 && _nadir) |
| 511 | draw_nadir(0.0, y); |
| 512 | |
| 513 | if ((_zenith && i > 85) || i > 90) |
| 514 | continue; |
| 515 | if ((_nadir && i < -85) || i < -90) |
| 516 | continue; |
| 517 | |
| 518 | lo.x = -half_span; |
| 519 | ro.x = half_span; |
| 520 | li.x = ri.x = 0; |
| 521 | lo.y = ro.y = li.y = ri.y = y; |
| 522 | numoffs.x = 4; |
| 523 | numoffs.y = 0; |
| 524 | |
| 525 | if (i == 0) { |
| 526 | lo.x -= _zero_bar_overlength; |
| 527 | ro.x += _zero_bar_overlength; |
| 528 | } |
| 529 | |
| 530 | if (_scr_hole > 0.0f) { |
| 531 | li.x = -_scr_hole; |
| 532 | ri.x = _scr_hole; |
| 533 | |
| 534 | if (_dive_bar_angle && i < 0) { |
| 535 | float alpha = i * SG_DEGREES_TO_RADIANS * 0.5; |
| 536 | float xoffs = (ro.x - ri.x) * cos(alpha); |
| 537 | float yoffs = (ro.x - ri.x) * sin(alpha); |
| 538 | lo.x = li.x - xoffs; |
| 539 | ro.x = ri.x + xoffs; |
| 540 | lo.y = ro.y = li.y + yoffs; |
| 541 | numoffs.x = 0; |
| 542 | numoffs.y = 4 - yoffs * 0.3; |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | // draw bars |
| 547 | if (_scr_hole) { |
| 548 | draw_line(li.x, li.y, lo.x, lo.y, i < 0); |
| 549 | draw_line(ri.x, ri.y, ro.x, ro.y, i < 0); |
| 550 | } else { |
| 551 | draw_line(lo.x, lo.y, ro.x, ro.y, i < 0); |
| 552 | } |
| 553 | |
| 554 | // draw ticks |
| 555 | if (_tick_length) { |
| 556 | if (i < 0) { |
| 557 | draw_line(li.x, li.y, li.x, li.y + _tick_length); |
| 558 | draw_line(ri.x, ri.y, ri.x, ri.y + _tick_length); |
| 559 | } else if (i > 0 || _zero_bar_overlength == 0) { |
| 560 | if (_tick_length > 0) { |
| 561 | numoffs.x = -0.3; |
| 562 | numoffs.y = -0.3; |
| 563 | draw_line(lo.x, lo.y, lo.x, lo.y - _tick_length); |
| 564 | draw_line(ro.x, ro.y, ro.x, ro.y - _tick_length); |
| 565 | } else { |
| 566 | draw_line(li.x, li.y, li.x, li.y - _tick_length); |
| 567 | draw_line(ri.x, ri.y, ri.x, ri.y - _tick_length); |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | // draw numbers |
| 573 | std::ostringstream str; |
| 574 | str << i; |
| 575 | // must keep this string, otherwise it will free the c_str! |
| 576 | string num_str = str.str(); |
| 577 | const char *num = num_str.c_str(); |
| 578 | int valign = numoffs.y > 0 ? BOTTOM : numoffs.y < 0 ? TOP : VCENTER; |
| 579 | draw_text(lo.x - numoffs.x, lo.y + numoffs.y, num, |
| 580 | valign | (numoffs.x == 0 ? CENTER : numoffs.x > 0 ? RIGHT : LEFT)); |
| 581 | draw_text(ro.x + numoffs.x, lo.y + numoffs.y, num, |
| 582 | valign | (numoffs.x == 0 ? CENTER : numoffs.x > 0 ? LEFT : RIGHT)); |
| 583 | |
| 584 | } |
| 585 | _locTextList.draw(); |
| 586 | |
| 587 | glLineWidth(0.2); |
| 588 | |
| 589 | _locLineList.draw(); |
| 590 | |
| 591 | glEnable(GL_LINE_STIPPLE); |
| 592 | glLineStipple(1, 0x00FF); |
| 593 | _locStippleLineList.draw(); |
| 594 | glDisable(GL_LINE_STIPPLE); |
| 595 | } |
| 596 | _clip_box->unset(); |
| 597 | glPopMatrix(); |
| 598 | //************************************************************* |
| 599 | |
| 600 | //************************************************************* |
| 601 | #ifdef ENABLE_SP_FDM |
| 602 | if (_waypoint_marker) { |
| 603 | //waypoint marker computation |
| 604 | float fromwp_lat, towp_lat, fromwp_lon, towp_lon, dist, delx, dely, hyp, theta, brg; |
| 605 | |
| 606 | fromwp_lon = get__longitude() * SGD_DEGREES_TO_RADIANS; |
| 607 | fromwp_lat = get__latitude() * SGD_DEGREES_TO_RADIANS; |
| 608 | towp_lon = get__aux2() * SGD_DEGREES_TO_RADIANS; |
| 609 | towp_lat = get__aux1() * SGD_DEGREES_TO_RADIANS; |
| 610 | |
| 611 | dist = acos(sin(fromwp_lat) * sin(towp_lat) + cos(fromwp_lat) |
| 612 | * cos(towp_lat) * cos(fabs(fromwp_lon - towp_lon))); |
| 613 | delx= towp_lat - fromwp_lat; |
| 614 | dely = towp_lon - fromwp_lon; |
| 615 | hyp = sqrt(pow(delx, 2) + pow(dely, 2)); |
| 616 | |
| 617 | if (hyp != 0) |
| 618 | theta = asin(dely / hyp); |
| 619 | else |
| 620 | theta = 0.0; |
| 621 | |
| 622 | brg = theta * SGD_RADIANS_TO_DEGREES; |
| 623 | if (brg > 360.0) |
| 624 | brg = 0.0; |
| 625 | if (delx < 0) |
| 626 | brg = 180 - brg; |
| 627 | |
| 628 | // {Brg = asin(cos(towp_lat)*sin(fabs(fromwp_lon-towp_lon))/ sin(dist)); |
| 629 | // Brg = Brg * SGD_RADIANS_TO_DEGREES; } |
| 630 | |
| 631 | dist *= SGD_RADIANS_TO_DEGREES * 60.0 * 1852.0; //rad->deg->nm->m |
| 632 | // end waypoint marker computation |
| 633 | |
| 634 | //********************************************************* |
| 635 | // OBJECT MOVING RETICLE |
| 636 | // TYPE ARROW |
| 637 | // waypoint marker |
| 638 | if (fabs(brg - psi) > 10.0) { |
| 639 | glPushMatrix(); |
| 640 | glTranslatef(_center_x, _center_y, 0); |
| 641 | glTranslatef(vel_x, vel_y, 0); |
| 642 | glRotatef(brg - psi, 0.0, 0.0, -1.0); |
| 643 | glBegin(GL_LINE_LOOP); |
| 644 | glVertex2f(-2.5, 20.0); |
| 645 | glVertex2f(-2.5, 30.0); |
| 646 | glVertex2f(-5.0, 30.0); |
| 647 | glVertex2f(0.0, 35.0); |
| 648 | glVertex2f(5.0, 30.0); |
| 649 | glVertex2f(2.5, 30.0); |
| 650 | glVertex2f(2.5, 20.0); |
| 651 | glEnd(); |
| 652 | glPopMatrix(); |
| 653 | } |
| 654 | |
| 655 | // waypoint marker on heading scale |
| 656 | if (fabs(brg - psi) < 12.0) { |
| 657 | if (!_hat) { |
| 658 | glBegin(GL_LINE_LOOP); |
| 659 | GLfloat x = (brg - psi) * 60 / 25; |
| 660 | glVertex2f(x + 320, 240.0); |
| 661 | glVertex2f(x + 326, 240.0 - 4); |
| 662 | glVertex2f(x + 323, 240.0 - 4); |
| 663 | glVertex2f(x + 323, 240.0 - 8); |
| 664 | glVertex2f(x + 317, 240.0 - 8); |
| 665 | glVertex2f(x + 317, 240.0 - 4); |
| 666 | glVertex2f(x + 314, 240.0 - 4); |
| 667 | glEnd(); |
| 668 | |
| 669 | } else { // if (_hat) |
| 670 | float x = (brg - psi) * 60 / 25 + 320, y = 240.0, r = 5.0; |
| 671 | float x1, y1; |
| 672 | |
| 673 | glEnable(GL_POINT_SMOOTH); |
| 674 | glBegin(GL_POINTS); |
| 675 | |
| 676 | for (int count = 0; count <= 200; count++) { |
| 677 | float temp = count * SG_PI * 3 / (200.0 * 2.0); |
| 678 | float temp1 = temp - (45.0 * SGD_DEGREES_TO_RADIANS); |
| 679 | x1 = x + r * cos(temp1); |
| 680 | y1 = y + r * sin(temp1); |
| 681 | glVertex2f(x1, y1); |
| 682 | } |
| 683 | |
| 684 | glEnd(); |
| 685 | glDisable(GL_POINT_SMOOTH); |
| 686 | } |
| 687 | |
| 688 | } //brg<12 |
| 689 | } // if _waypoint_marker |
| 690 | #endif |
| 691 | }//draw |
| 692 | |
| 693 | |
| 694 | /******************************************************************/ |
| 695 | // draws the zenith symbol (highest possible climb angle i.e. 90 degree climb angle) |
| 696 | // |
| 697 | void HUD::Ladder::draw_zenith(float x, float y) |
| 698 | { |
| 699 | draw_line(x - 9.0, y, x - 3.0, y + 1.3); |
| 700 | draw_line(x - 9.0, y, x - 3.0, y - 1.3); |
| 701 | |
| 702 | draw_line(x + 9.0, y, x + 3.0, y + 1.3); |
| 703 | draw_line(x + 9.0, y, x + 3.0, y - 1.3); |
| 704 | |
| 705 | draw_line(x, y + 9.0, x - 1.3, y + 3.0); |
| 706 | draw_line(x, y + 9.0, x + 1.3, y + 3.0); |
| 707 | |
| 708 | draw_line(x - 3.9, y + 3.9, x - 3.0, y + 1.3); |
| 709 | draw_line(x - 3.9, y + 3.9, x - 1.3, y + 3.0); |
| 710 | |
| 711 | draw_line(x + 3.9, y + 3.9, x + 1.3, y + 3.0); |
| 712 | draw_line(x + 3.9, y + 3.9, x + 3.0, y + 1.3); |
| 713 | |
| 714 | draw_line(x - 3.9, y - 3.9, x - 3.0, y - 1.3); |
| 715 | draw_line(x - 3.9, y - 3.9, x - 1.3, y - 2.6); |
| 716 | |
| 717 | draw_line(x + 3.9, y - 3.9, x + 3.0, y - 1.3); |
| 718 | draw_line(x + 3.9, y - 3.9, x + 1.3, y - 2.6); |
| 719 | |
| 720 | draw_line(x - 1.3, y - 2.6, x, y - 27.0); |
| 721 | draw_line(x + 1.3, y - 2.6, x, y - 27.0); |
| 722 | } |
| 723 | |
| 724 | |
| 725 | // draws the nadir symbol (lowest possible dive angle i.e. 90 degree dive angle)) |
| 726 | // |
| 727 | void HUD::Ladder::draw_nadir(float x, float y) |
| 728 | { |
| 729 | const float R = 7.5; |
| 730 | |
| 731 | draw_circle(x, y, R); |
| 732 | draw_line(x, y + R, x, y + 22.5); // line above the circle |
| 733 | draw_line(x - R, y, x + R, y); // line at middle of circle |
| 734 | |
| 735 | float theta = asin(2.5 / R); |
| 736 | float theta1 = asin(5.0 / R); |
| 737 | float x1, y1, x2, y2; |
| 738 | |
| 739 | x1 = x + R * cos(theta); |
| 740 | y1 = y + 2.5; |
| 741 | x2 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) - theta); |
| 742 | y2 = y + 2.5; |
| 743 | draw_line(x1, y1, x2, y2); |
| 744 | |
| 745 | x1 = x + R * cos(theta1); |
| 746 | y1 = y + 5.0; |
| 747 | x2 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) - theta1); |
| 748 | y2 = y + 5.0; |
| 749 | draw_line(x1, y1, x2, y2); |
| 750 | |
| 751 | x1 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) + theta); |
| 752 | y1 = y - 2.5; |
| 753 | x2 = x + R * cos((360.0 * SGD_DEGREES_TO_RADIANS) - theta); |
| 754 | y2 = y - 2.5; |
| 755 | draw_line(x1, y1, x2, y2); |
| 756 | |
| 757 | x1 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) + theta1); |
| 758 | y1 = y - 5.0; |
| 759 | x2 = x + R * cos((360.0 * SGD_DEGREES_TO_RADIANS) - theta1); |
| 760 | y2 = y - 5.0; |
| 761 | draw_line(x1, y1, x2, y2); |
| 762 | } |
| 763 | |
| 764 |