Advertisement
Guest User

interceptmarker.patch

a guest
Mar 25th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.66 KB | None | 0 0
  1. Index: src/gfx/cockpit.cpp
  2. ===================================================================
  3. --- src/gfx/cockpit.cpp (revision 13600)
  4. +++ src/gfx/cockpit.cpp (working copy)
  5. @@ -522,6 +522,70 @@
  6.      GFXDisable( SMOOTH );
  7.  }
  8.  
  9. +inline void DrawInterceptMarker( Unit * player, QVector p, QVector q, QVector r )
  10. +{
  11. +    static const float scale = XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "min_target_box_size", ".01" ) );
  12. +    const Unit * target = player->Target();
  13. +
  14. +    // ray-sphere intersection r^2 = (vp * t)^2
  15. +    // (vt * vt) * t^2 + (2 * vt * loc) * t + (loc * loc) - (vp * vp) * t^2 = 0
  16. +    QVector loc = target->Position() - _Universe->AccessCamera()->GetPosition();
  17. +    Vector vt = target->GetVelocity();
  18. +    Vector vp = player->GetVelocity();
  19. +    float a = vt.Dot( vt ) - vp.Dot( vp );
  20. +    float b = 2 * vt.Dot( loc );
  21. +    float c = loc.Dot( loc );
  22. +    float d = b * b - 4 * a * c;
  23. +    if ( d < 0 || fabs(a) < 1E-6 )
  24. +        return;
  25. +
  26. +    float ds = sqrtf( d );
  27. +    float s = (b < 0) ? 0.5f * ( -b - ds ) : 0.5f * ( -b + ds );
  28. +    float t0 = s / a;
  29. +    float t1 = c / s;
  30. +
  31. +    // get minimal positive time
  32. +    float t = t0 > 0 ? (t1 > t0 ? t0 : t1) : (t1 > 0 ? t1 : 0);
  33. +
  34. +    // dont't draw marker if we are a half second away from target
  35. +    if (t < 0.5f)
  36. +        return;
  37. +
  38. +    // calculate marker position
  39. +    QVector locn = loc / loc.Magnitude();          // normal towards target
  40. +    QVector locv = vt * t;                         // target travel vector
  41. +    QVector locp = locv - locn * locn.Dot( locv ); // projected target travel vector
  42. +    QVector loct = loc + locp;                     // interception marker position in space
  43. +
  44. +    // enforce min marker size
  45. +    float size = target->rSize();
  46. +    float minsize = loct.Magnitude() * scale;
  47. +    if (size < minsize)
  48. +        size = minsize;
  49. +
  50. +    // fade out marker when close to target box
  51. +    float alpha = std::min(1.0, 0.2 * locp.MagnitudeSquared() / (size * size));
  52. +
  53. +    GFXEnable( SMOOTH );
  54. +    GFXBlendMode( SRCALPHA, INVSRCALPHA );
  55. +    GFXColor4f( 1, 1, 1, alpha );
  56. +    const QVector v[4] = {
  57. +        loct + p*size + q*size,
  58. +        loct - p*size - q*size,
  59. +        loct - p*size + q*size,
  60. +        loct + p*size - q*size,
  61. +    };
  62. +    const float verts[4 * 3] = {
  63. +        v[0].x, v[0].y, v[0].z,
  64. +        v[1].x, v[1].y, v[1].z,
  65. +        v[2].x, v[2].y, v[2].z,
  66. +        v[3].x, v[3].y, v[3].z,
  67. +    };
  68. +    GFXDraw( GFXLINE, verts, 4 );
  69. +    GFXColor4f( 1, 1, 1, 1 );
  70. +    GFXDisable( SMOOTH );
  71. +}
  72. +
  73.  void GameCockpit::DrawTargetBox(const Radar::Sensor& sensor)
  74.  {
  75.      if (sensor.InsideNebula())
  76. @@ -576,6 +640,8 @@
  77.          }
  78.          GFXDisable( SMOOTH );
  79.      }
  80. +    if (draw_intercept_marker)
  81. +        DrawInterceptMarker( player, CamP, CamQ, CamR );
  82.      static bool draw_target_nav_symbol =
  83.          XMLSupport::parse_bool( vs_config->getVariable( "graphics", "draw_target_nav_symbol", "true" ) );
  84.      static bool draw_jump_nav_symbol   =
  85. @@ -1851,7 +1917,8 @@
  86.      for (i = 0; i < UnitImages< void >::NUMGAUGES; i++)
  87.          gauges[i] = NULL;
  88.      radarSprites[0] = radarSprites[1] = Pit[0] = Pit[1] = Pit[2] = Pit[3] = NULL;
  89. -
  90. +    static bool st_draw_intercept_marker =
  91. +        XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "drawTargetInterceptPoint", "true" ) );
  92.      static bool st_draw_all_boxes =
  93.          XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "drawAllTargetBoxes", "false" ) );
  94.      static bool st_draw_line_to_target =
  95. @@ -1863,6 +1930,7 @@
  96.      static bool st_always_itts = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "drawAlwaysITTS", "false" ) );
  97.      static bool st_steady_itts = XMLSupport::parse_bool( vs_config->getVariable( "physics", "steady_itts", "false" ) );
  98.  
  99. +    draw_intercept_marker = st_draw_intercept_marker;
  100.      draw_all_boxes = st_draw_all_boxes;
  101.      draw_line_to_target = st_draw_line_to_target;
  102.      draw_line_to_targets_target = st_draw_line_to_targets_target;
  103. Index: src/gfx/cockpit.h
  104. ===================================================================
  105. --- src/gfx/cockpit.h   (revision 13600)
  106. +++ src/gfx/cockpit.h   (working copy)
  107. @@ -101,6 +101,8 @@
  108.      Gauge     *gauges[UnitImages < void > ::NUMGAUGES];
  109.      ///holds misc panels.  Panel[0] is always crosshairs (and adjusted to be in center of view screen, not cockpit)
  110.      std::vector< VSSprite* >Panel;
  111. +    ///draw target intercept point marker
  112. +    bool     draw_intercept_marker;
  113.      ///flag to decide whether to draw all target boxes
  114.      bool     draw_all_boxes;
  115.      bool     draw_line_to_target, draw_line_to_targets_target;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement