Advertisement
Alvy

Source Mouse acceleration explanation

Feb 23rd, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. float mouse_sensitivity = ( gHUD.GetSensitivity() != 0 ) // mouse sens != 0
  2. ? gHUD.GetSensitivity() : sensitivity.GetFloat(); //get mouse sens
  3.  
  4. if ( m_customaccel.GetInt() == 1 || m_customaccel.GetInt() == 2 ) //if m_customaccel == 1 || == 2
  5. {
  6. float raw_mouse_movement_distance = sqrt( mx * mx + my * my ); //linear curve where sqrt(mx * mx) = mx
  7. float acceleration_scale = m_customaccel_scale.GetFloat(); // scale of acceleration
  8. float accelerated_sensitivity_max = m_customaccel_max.GetFloat(); //max sensitivity you can reach
  9. float accelerated_sensitivity_exponent = m_customaccel_exponent.GetFloat(); //exponent = movement raised to the power of exponent
  10. float accelerated_sensitivity = ( (float)pow( raw_mouse_movement_distance, accelerated_sensitivity_exponent ) * acceleration_scale + mouse_sensitivity ); //((power of float(distance of linear movement, exponent)) * scale + mouse_sensitivity)
  11.  
  12. if ( accelerated_sensitivity_max > 0.0001f &&
  13. accelerated_sensitivity > accelerated_sensitivity_max ) //if accelerated max > 0.0001 and accelerated sens is over max
  14. {
  15. accelerated_sensitivity = accelerated_sensitivity_max; //set accelerated sens to max
  16. }
  17.  
  18. *x *= accelerated_sensitivity; //multiply movement by accelerated sensitivity on pitch
  19. *y *= accelerated_sensitivity; //multiply movement by accelerated sensitivity on yaw
  20.  
  21. if ( m_customaccel.GetInt() == 2 || m_customaccel.GetInt() == 4 ) //if m_customaccel == 2 || == 4
  22. {
  23. *x *= m_yaw.GetFloat(); //use m_yaw value for accel
  24. *y *= m_pitch->GetFloat(); //use m_pitch value for accel
  25. }
  26. }
  27. else if ( m_customaccel.GetInt() == 3 )
  28. {
  29. float raw_mouse_movement_distance_squared = mx * mx + my * my; //hyperbola where (mx * mx) = (mx ^ 2)
  30. float fExp = MAX(0.0f, (m_customaccel_exponent.GetFloat() - 1.0f) / 2.0f); //returns largest of (0.0f) and (m_customaccel_exponent - 1.0f) / 2.0f) if both are the same, 0.0f is returned.
  31. float accelerated_sensitivity = powf( raw_mouse_movement_distance_squared, fExp ) * mouse_sensitivity; //power of float (movement distance in hyperbola, result of exponent) * mouse_sensitivity;
  32.  
  33. *x *= accelerated_sensitivity; //multiply movement by accelerated sensitivity on pitch
  34. *y *= accelerated_sensitivity; //multiply movement by accelerated sensitivity on yaw
  35. }
  36. else
  37. {
  38. *x *= mouse_sensitivity; //if accel is not enabled, handle mouse sensitivity normally on pitch
  39. *y *= mouse_sensitivity; //if accel is not enabled, handle mouse sensitivity normally on yaw
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement