private void CalcDiag(Vector2 mouseDelta, BetaGamesManager.GameSettings gs) { if (gs.DiagonalCoeff != 0) { Vector2 absDelta = new Vector2(Math.Abs(mouseDelta.X), Math.Abs(mouseDelta.Y)); absDelta.Cap(0, (double)Xim.Stick.Max); double association = 0; if (absDelta.X > absDelta.Y) { association = absDelta.Y / absDelta.X; if (association != 0 && !Double.IsNaN(association) && !Double.IsInfinity(association)) { //mouseDelta.Y = mouseDelta.Y + mouseDelta.Y * (0.1 - association / 10) * gs.DiagonalCoeff; mouseDelta.Scale(1 - association * gs.DiagonalCoeff); } } else { association = absDelta.X / absDelta.Y; if (association != 0 && !Double.IsNaN(association) && !Double.IsInfinity(association)) { //mouseDelta.X = mouseDelta.X + mouseDelta.X * (0.1 - association / 10) * gs.DiagonalCoeff; mouseDelta.Scale(1 - association * gs.DiagonalCoeff); } } } }
public void XSoftMouseMovement(ref Xim.Input input, ref Xim.Input startState) { GamesManager.GameSettings gameSettings = gamesManager.GetGameSettings((GamesManager.Games)m_currentGame.Value); // User Values double speed, accel, yaw, pitch, mouseDpi; GetUserSettings(out speed, out accel, out mouseDpi, out pitch, out yaw); double delay = (1000 / (1000 / (double)m_rate.Value)); double revolutionsperinch = speed / 15; double userScale = revolutionsperinch * delay / mouseDpi; Vector2 delta; GetMouseDelta(out delta); if (delta.X == 0 && delta.Y == 0) return; Vector2 mouseDelta = new Vector2(delta.X, delta.Y); // Transform mouseDelta into Angular Velocity ( revolutions / time ) = delta^accel * sens * delay mouseDelta.Pow(accel); mouseDelta.Scale(userScale); // Factor in game Y:X ratio mouseDelta.X = mouseDelta.X * yaw; mouseDelta.Y = mouseDelta.Y * pitch; CalcDelta(mouseDelta, gameSettings); CalcDiag(mouseDelta, gameSettings); CalcAveraging(mouseDelta, gameSettings); // Add deadzone Vector2 deadzoneVec = CalcDeadzone(mouseDelta, gameSettings); mouseDelta.Add(deadzoneVec); // pixelCap is the number of pixels per frame that can be processed by the current angular velocity formula. // Anything above this value is useless to translate but we can carry the leftover value to the next frame. if (gameSettings.XAxis.Cap != -1) { double pixelCapX = Math.Pow((gameSettings.XAxis.GetPixelCapValue(gameSettings.Deadzone) / (userScale * yaw)), (double)1 / accel); if (Math.Abs(delta.X) > pixelCapX) { int sign = Math.Sign(delta.X); highEndCarry.X = (Math.Abs(delta.X) - pixelCapX) * sign; mouseDelta.X = (short)(gameSettings.XAxis.Cap * sign); } } if (gameSettings.YAxis.Cap != -1) { double pixelCapY = Math.Pow((gameSettings.YAxis.GetPixelCapValue(gameSettings.Deadzone) / (userScale * pitch)), (double)1 / accel); if (Math.Abs(delta.Y) > pixelCapY) { int sign = Math.Sign(mouseDelta.Y); highEndCarry.Y = (Math.Abs(delta.Y) - pixelCapY) * sign; mouseDelta.Y = (short)(gameSettings.YAxis.Cap * sign); } } // pixelsAtMax is the number of pixels we can process when moving at Xim.Stick.Max, if we have moved more than // this number of pixels then we should carry the leftover and use Xim.Stick.Max for our output. if (gameSettings.XAxis.MaxSpeed != -1) { double pixelsAtMaxX = Math.Pow((gameSettings.XAxis.MaxSpeed) / (userScale * pitch), 1 / accel); if (Math.Abs(delta.X) > pixelsAtMaxX) { InfoTextManager.Instance.WriteLineDebug("CarryX!" + delta.X); int sign = Math.Sign(delta.X); highEndCarry.X = (Math.Abs(delta.X) - pixelsAtMaxX) * sign; mouseDelta.X = ((short)Xim.Stick.Max * sign); } } if (gameSettings.YAxis.MaxSpeed != -1) { double pixelsAtMaxY = Math.Pow((gameSettings.YAxis.MaxSpeed) / (userScale * yaw), 1 / accel); if (Math.Abs(delta.Y) > pixelsAtMaxY) { InfoTextManager.Instance.WriteLineDebug("CarryY!" + delta.Y); int sign = Math.Sign(delta.Y); highEndCarry.Y = (Math.Abs(delta.Y) - pixelsAtMaxY) * sign; mouseDelta.Y = ((short)Xim.Stick.Max * sign); } } // Some games ( like UT3 ) have a strange Y step function going on, account for that. if (gameSettings.XAxis.CarryZone != -1) { if (Math.Abs(mouseDelta.X) < gameSettings.XAxis.CarryZone) { lowEndCarry.X = delta.X; mouseDelta.X = 0; } } if (gameSettings.YAxis.CarryZone != -1) { if (Math.Abs(mouseDelta.Y) < gameSettings.YAxis.CarryZone) { lowEndCarry.Y = delta.Y; mouseDelta.Y = 0; } } mouseDelta.Cap(-(double)Xim.Stick.Max, (double)Xim.Stick.Max); SaveDrivingModeData(mouseDelta, delta); SetXboxInput(ref input, mouseDelta); }