Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: src/gfx/cockpit.cpp
- ===================================================================
- --- src/gfx/cockpit.cpp (revision 13600)
- +++ src/gfx/cockpit.cpp (working copy)
- @@ -522,6 +522,70 @@
- GFXDisable( SMOOTH );
- }
- +inline void DrawInterceptMarker( Unit * player, QVector p, QVector q, QVector r )
- +{
- + static const float scale = XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "min_target_box_size", ".01" ) );
- + const Unit * target = player->Target();
- +
- + // ray-sphere intersection r^2 = (vp * t)^2
- + // (vt * vt) * t^2 + (2 * vt * loc) * t + (loc * loc) - (vp * vp) * t^2 = 0
- + QVector loc = target->Position() - _Universe->AccessCamera()->GetPosition();
- + Vector vt = target->GetVelocity();
- + Vector vp = player->GetVelocity();
- + float a = vt.Dot( vt ) - vp.Dot( vp );
- + float b = 2 * vt.Dot( loc );
- + float c = loc.Dot( loc );
- + float d = b * b - 4 * a * c;
- + if ( d < 0 || fabs(a) < 1E-6 )
- + return;
- +
- + float ds = sqrtf( d );
- + float s = (b < 0) ? 0.5f * ( -b - ds ) : 0.5f * ( -b + ds );
- + float t0 = s / a;
- + float t1 = c / s;
- +
- + // get minimal positive time
- + float t = t0 > 0 ? (t1 > t0 ? t0 : t1) : (t1 > 0 ? t1 : 0);
- +
- + // dont't draw marker if we are a half second away from target
- + if (t < 0.5f)
- + return;
- +
- + // calculate marker position
- + QVector locn = loc / loc.Magnitude(); // normal towards target
- + QVector locv = vt * t; // target travel vector
- + QVector locp = locv - locn * locn.Dot( locv ); // projected target travel vector
- + QVector loct = loc + locp; // interception marker position in space
- +
- + // enforce min marker size
- + float size = target->rSize();
- + float minsize = loct.Magnitude() * scale;
- + if (size < minsize)
- + size = minsize;
- +
- + // fade out marker when close to target box
- + float alpha = std::min(1.0, 0.2 * locp.MagnitudeSquared() / (size * size));
- +
- + GFXEnable( SMOOTH );
- + GFXBlendMode( SRCALPHA, INVSRCALPHA );
- + GFXColor4f( 1, 1, 1, alpha );
- + const QVector v[4] = {
- + loct + p*size + q*size,
- + loct - p*size - q*size,
- + loct - p*size + q*size,
- + loct + p*size - q*size,
- + };
- + const float verts[4 * 3] = {
- + v[0].x, v[0].y, v[0].z,
- + v[1].x, v[1].y, v[1].z,
- + v[2].x, v[2].y, v[2].z,
- + v[3].x, v[3].y, v[3].z,
- + };
- + GFXDraw( GFXLINE, verts, 4 );
- + GFXColor4f( 1, 1, 1, 1 );
- + GFXDisable( SMOOTH );
- +}
- +
- void GameCockpit::DrawTargetBox(const Radar::Sensor& sensor)
- {
- if (sensor.InsideNebula())
- @@ -576,6 +640,8 @@
- }
- GFXDisable( SMOOTH );
- }
- + if (draw_intercept_marker)
- + DrawInterceptMarker( player, CamP, CamQ, CamR );
- static bool draw_target_nav_symbol =
- XMLSupport::parse_bool( vs_config->getVariable( "graphics", "draw_target_nav_symbol", "true" ) );
- static bool draw_jump_nav_symbol =
- @@ -1851,7 +1917,8 @@
- for (i = 0; i < UnitImages< void >::NUMGAUGES; i++)
- gauges[i] = NULL;
- radarSprites[0] = radarSprites[1] = Pit[0] = Pit[1] = Pit[2] = Pit[3] = NULL;
- -
- + static bool st_draw_intercept_marker =
- + XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "drawTargetInterceptPoint", "true" ) );
- static bool st_draw_all_boxes =
- XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "drawAllTargetBoxes", "false" ) );
- static bool st_draw_line_to_target =
- @@ -1863,6 +1930,7 @@
- static bool st_always_itts = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "drawAlwaysITTS", "false" ) );
- static bool st_steady_itts = XMLSupport::parse_bool( vs_config->getVariable( "physics", "steady_itts", "false" ) );
- + draw_intercept_marker = st_draw_intercept_marker;
- draw_all_boxes = st_draw_all_boxes;
- draw_line_to_target = st_draw_line_to_target;
- draw_line_to_targets_target = st_draw_line_to_targets_target;
- Index: src/gfx/cockpit.h
- ===================================================================
- --- src/gfx/cockpit.h (revision 13600)
- +++ src/gfx/cockpit.h (working copy)
- @@ -101,6 +101,8 @@
- Gauge *gauges[UnitImages < void > ::NUMGAUGES];
- ///holds misc panels. Panel[0] is always crosshairs (and adjusted to be in center of view screen, not cockpit)
- std::vector< VSSprite* >Panel;
- + ///draw target intercept point marker
- + bool draw_intercept_marker;
- ///flag to decide whether to draw all target boxes
- bool draw_all_boxes;
- bool draw_line_to_target, draw_line_to_targets_target;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement