psy_commando

handling code mostly by the ES guys

Apr 17th, 2012
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.29 KB | None | 0 0
  1. void CESTestVehicle::CommitInputs(float Interval)
  2. {
  3.     // Ok, it's time to redo this flying code, and write long comments like this one
  4.     // The main idea behind this is to go for full arcade flight
  5.     // with a bit of a newtonian flare on the "cut engines" key
  6.     // so what we will do is rotate the velocity vector, rather than do all the acceleration shit
  7.     // that will allow us to use realistic accels for translational without compromising turn speed
  8.  
  9.     // Define a bunch of vectors over here
  10.     Vector localvelocity, accel;
  11.     AngularImpulse angaccel(0,0,0);
  12.  
  13.     {
  14.         // Speed depends on wether or not turbo is on
  15.         float flSpeedMax = 100.0f;
  16.  
  17.         VectorIRotate( GetAbsVelocity(), EntityToWorldTransform(), localvelocity );
  18.  
  19.         // Just regular turning for angles
  20.         VectorMultiply( m_angTurnMax, input_torque, angaccel );
  21.         angaccel -= m_vecEntityAngVelocity.Get();  //  "angaccel" and "angular" are angular velocities
  22.         angaccel /= Interval;  //  "angaccel" now an angular acceleration
  23.         angaccel.x = MIN( m_angAccelMax.x, angaccel.x );
  24.       angaccel.y = MIN( m_angAccelMax.y, angaccel.y );
  25.       angaccel.z = MIN( m_angAccelMax.z, angaccel.z );
  26.  
  27.         // Poor man's normalization. Basically projects the box to a circle
  28.         // Its not perfect, but it works (problem is being at 0.7 x and 0.7 y is the same as 1 x and 1 y)
  29.         float vel = input_force.LengthSqr();
  30.         if( vel > 1.0f )
  31.             input_force *= FastRSqrt( vel );
  32.  
  33.         accel = input_force * flSpeedMax - localvelocity; //  "accel" now a velocity delta in local space
  34.         //  Note: here and in the VectorMultiply following are the only
  35.         //  cases in which a specific input parameter is referenced.
  36.         accel /= Interval;  //  "accel" now an acceleration
  37.         accel.x = MIN( m_vecAccelMax.x, accel.x );  //  Clamp to max
  38.       accel.y = MIN( m_vecAccelMax.y, accel.y );  //  Clamp to max
  39.       accel.z = MIN( m_vecAccelMax.z, accel.z );  //  Clamp to max
  40.  
  41.         accel *= Interval;
  42.         angaccel *= Interval;
  43.         localvelocity += accel;
  44.         m_vecEntityAngVelocity += angaccel;
  45.  
  46.         QAngle angvel;
  47.         matrix3x4_t AngVel, output, localToWorld;
  48.  
  49.         AngularImpulseToQAngle( m_vecEntityAngVelocity, angvel );
  50.  
  51. #ifdef CLIENT_DLL
  52.         AngleMatrix( GetNetworkAngles(), localToWorld ); // Nothing lost here, it gets done if you call EntityToWorld too
  53. #else
  54.         AngleMatrix( GetLocalAngles(), localToWorld ); // Nothing lost here, it gets done if you call EntityToWorld too
  55. #endif
  56.         AngleMatrix( angvel * Interval, AngVel );
  57.         ConcatTransforms( localToWorld, AngVel, output );
  58.         MatrixAngles( output, angvel );
  59. #ifdef CLIENT_DLL
  60.         // This should fix pred errors
  61.         angvel[0] = anglemod(angvel[0]);
  62.         angvel[1] = anglemod(angvel[1]);
  63.         angvel[2] = anglemod(angvel[2]);
  64. #endif
  65.  
  66.         SetAbsAngles( angvel );
  67.  
  68.         // NOTE: output is the new angle, this bypasses all the slippage inducing stuff by hard clamping the rotation
  69.         VectorRotate( localvelocity, output, accel );
  70.         SetAbsVelocity( accel );
  71.     }
  72.  
  73.     //m_iEngineBits = EngineBits( input_force );
  74.  
  75. #ifdef CLIENT_DLL
  76.     Vector origin = GetNetworkOrigin() + GetAbsVelocity() * TICK_INTERVAL;
  77. #else
  78.     Vector origin = GetLocalOrigin() + GetAbsVelocity() * TICK_INTERVAL;
  79. #endif
  80.  
  81.     SetAbsOrigin( origin );
  82.  
  83. #ifdef GAME_DLL
  84.     if( VPhysicsGetObject() )
  85.     {
  86.         VPhysicsGetObject()->UpdateShadow( GetAbsOrigin(), GetAbsAngles(), false, TICK_INTERVAL );
  87.     }
  88. #endif
  89. }
Advertisement
Add Comment
Please, Sign In to add comment