Advertisement
Guest User

Untitled

a guest
Feb 21st, 2013
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. bool CTFWeaponBaseMelee::DoSwingTrace( trace_t &trace )
  2. {
  3.     // Setup a volume for the melee weapon to be swung - approx size, so all melee behave the same.
  4.     static Vector vecSwingMins( -18, -18, -18 );
  5.     static Vector vecSwingMaxs( 18, 18, 18 );
  6.  
  7.     // Get the current player.
  8.     CTFPlayer *pPlayer = GetTFPlayerOwner();
  9.     if ( !pPlayer )
  10.         return false;
  11.  
  12.     // Setup the swing range.
  13.     Vector vecForward;
  14.     AngleVectors( pPlayer->EyeAngles(), &vecForward );
  15.     Vector vecSwingStart = pPlayer->Weapon_ShootPosition();
  16.     Vector vecSwingEnd = vecSwingStart + vecForward * 48;
  17.  
  18.     // See if we hit anything.
  19.     UTIL_TraceLine( vecSwingStart, vecSwingEnd, MASK_SOLID, pPlayer, COLLISION_GROUP_NONE, &trace );
  20.     if ( trace.fraction >= 1.0 )
  21.     {
  22.         UTIL_TraceHull( vecSwingStart, vecSwingEnd, vecSwingMins, vecSwingMaxs, MASK_SOLID, pPlayer, COLLISION_GROUP_NONE, &trace );
  23.         if ( trace.fraction < 1.0 )
  24.         {
  25.             // Calculate the point of intersection of the line (or hull) and the object we hit
  26.             // This is and approximation of the "best" intersection
  27.             CBaseEntity *pHit = trace.m_pEnt;
  28.             if ( !pHit || pHit->IsBSPModel() )
  29.             {
  30.                 // Why duck hull min/max?
  31.                 FindHullIntersection( vecSwingStart, trace, VEC_DUCK_HULL_MIN, VEC_DUCK_HULL_MAX, pPlayer );
  32.             }
  33.  
  34.             // This is the point on the actual surface (the hull could have hit space)
  35.             vecSwingEnd = trace.endpos;
  36.         }
  37.     }
  38.  
  39.     return ( trace.fraction < 1.0f );
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement