Advertisement
imk0tter

LiTHiuM's Mouse Accelerator

Apr 20th, 2022
967
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.57 KB | None | 0 0
  1. inline float CALCULATE_RADIANS2(float line_length)
  2. {
  3.     return acos((2 - (line_length * line_length)) / 2);
  4. }
  5.  
  6. void IN_MouseMove(float frametime, usercmd_t* cmd)
  7. {
  8.  
  9.     int     mx, my;
  10.     vec3_t viewangles;
  11.  
  12.  
  13.     //LiTHiuM
  14.     float current_frame_time_ratio = 1 / frametime;
  15.  
  16.     //float current_frame_time_ratio = MAX_FRAME_TIME / frametime;
  17.  
  18.     float max_move_x = gEngfuncs.GetWindowCenterX() / current_frame_time_ratio;
  19.     float max_move_y = gEngfuncs.GetWindowCenterY() / current_frame_time_ratio;
  20.  
  21.     //END LiTHiuM
  22.  
  23.     gEngfuncs.GetViewAngles((float*)viewangles);
  24.  
  25.     // Ricochet: Don't let them move the mouse when they're in spectator mode
  26.     int iSpectator = !bCanMoveMouse();
  27.  
  28.     //jjb - this disbles normal mouse control if the user is trying to
  29.     //      move the camera
  30.     if (!iMouseInUse && !g_iVisibleMouse && !iSpectator)
  31.     {
  32.         GetCursorPos(&current_pos);
  33.  
  34.         mx = (current_pos.x) - gEngfuncs.GetWindowCenterX();
  35.         my = (current_pos.y) - gEngfuncs.GetWindowCenterY();
  36.  
  37.         IN_ResetMouse();
  38.  
  39.         if (m_filter->value)
  40.         {
  41.             float accel_multiplier_x = max_move_x / 0.2;
  42.             float accel_multiplier_y = max_move_y / 0.2;
  43.  
  44.             //XVAL and YVAL are the number of radians
  45.             float xval = mx / max_move_x;
  46.             float yval = my / max_move_y;
  47.  
  48.             //float xval = (mx * sensitivity->value) / max_move_x;
  49.             //float yval = (my * sensitivity->value) / max_move_y;
  50.  
  51.  
  52.             float x_mul = CALCULATE_RADIANS2(min(abs(xval), 1) * 2) / 0.5;
  53.             float y_mul = CALCULATE_RADIANS2(min(abs(yval), 1) * 2) / 0.5;
  54.             //float x_mul = CALCULATE_RADIANS2(min(abs(xval), 1) * 2) * accel_multiplier_x / 0.5;
  55.             //float y_mul = CALCULATE_RADIANS2(min(abs(yval), 1) * 2) * accel_multiplier_y / 0.5;
  56.  
  57.             mouse_x = x_mul * mx;
  58.             mouse_y = y_mul * my;
  59.  
  60.             //IN_MOUSE_MOVE: frametime = 0.009950, mx = 0, my = 0, mouse_x : 0 mouse_y : 0 xval : 0.000000, yval : 0.000000, accel_multiplier_x : 20.099693, accel_multiplier_y : 35.732788, max_move_x : 47.761921, max_move_y : 26.866081
  61.            
  62.             char msg[256];
  63.             _snprintf(msg, sizeof(msg), "IN_MOUSE_MOVE: frametime=%f, mx=%d, my=%d, mouse_x: %d mouse_y: %d xval: %f, yval: %f, accel_multiplier_x: %f, accel_multiplier_y: %f, max_move_x: %f, max_move_y: %f\n", frametime, mx, my, mouse_x, mouse_y, xval, yval, accel_multiplier_x, accel_multiplier_y, max_move_x, max_move_y);
  64.             ConsolePrint(msg);
  65.         }
  66.         else
  67.         {
  68.             mouse_x = mx;
  69.             mouse_y = my;
  70.         }
  71.  
  72.         /*
  73.         //IF FOV IS NOT DEFAULT_FOV
  74.  
  75.         if (gHUD.GetSensitivity() != 0)
  76.         {
  77.             //mouse_x *= gHUD.GetSensitivity();
  78.             //mouse_y *= gHUD.GetSensitivity();
  79.         }
  80.         //ELSE
  81.         else
  82.         {
  83.             //mouse_x *= sensitivity->value;
  84.             //mouse_y *= sensitivity->value;
  85.         }
  86.         */
  87.  
  88.         // add mouse X/Y movement to cmd
  89.         if ((in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1)))
  90.             cmd->sidemove += m_side->value * mouse_x;
  91.         else
  92.             viewangles[YAW] -= m_yaw->value * mouse_x;
  93.  
  94.         if (in_mlook.state & 1)
  95.         {
  96.             V_StopPitchDrift();
  97.         }
  98.  
  99.         if ((in_mlook.state & 1) && !(in_strafe.state & 1))
  100.         {
  101.             viewangles[PITCH] += m_pitch->value * mouse_y;
  102.             if (viewangles[PITCH] > cl_pitchdown->value)
  103.                 viewangles[PITCH] = cl_pitchdown->value;
  104.             if (viewangles[PITCH] < -cl_pitchup->value)
  105.                 viewangles[PITCH] = -cl_pitchup->value;
  106.         }
  107.         else
  108.         {
  109.             if ((in_strafe.state & 1) && gEngfuncs.IsNoClipping())
  110.             {
  111.                 cmd->upmove -= m_forward->value * mouse_y;
  112.             }
  113.             else
  114.             {
  115.                 cmd->forwardmove -= m_forward->value * mouse_y;
  116.             }
  117.         }
  118.  
  119.         // if the mouse has moved, force it to the center, so there's room to move
  120.         //if (mx || my)
  121.         //{
  122.         //  IN_ResetMouse();
  123.         //}
  124.     }
  125.  
  126.     gEngfuncs.SetViewAngles((float*)viewangles);
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement