Skip to content

Commit

Permalink
implement interpolation on ApplyCustomSensitivity
Browse files Browse the repository at this point in the history
  • Loading branch information
Valkirie committed Mar 21, 2022
1 parent 5c4dde5 commit b02c989
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ControllerCommon/Utils/InputUtils.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Numerics;

Expand Down Expand Up @@ -144,6 +145,7 @@ public static Vector2 ApplyAntiDeadzone(Vector2 ThumbValue, float DeadzoneIn)

// Custom sensitivity
// Interpolation function (linear), takes list of nodes coordinates and gamepad joystick position returns game input
private static int SensivityIdx = 2;
public static float ApplyCustomSensitivity(float AngularValue, float MaxValue, List<ProfileVector> Nodes)
{
int NodeAmount = Profile.array_size;
Expand All @@ -166,8 +168,12 @@ public static float ApplyCustomSensitivity(float AngularValue, float MaxValue, L
// Calculate custom sensitivty
else
{
ProfileVector vector = Nodes.Where(n => JoystickPosAbs <= n.x).FirstOrDefault();
JoystickPosAdjusted = (float)vector.y * 2.0f;
var closests = Nodes.Select(n => new { n, distance = Math.Abs(n.x - JoystickPosAbs) }).OrderBy(p => p.distance).Take(SensivityIdx);
foreach (var item in closests)
JoystickPosAdjusted += (float)(item.n.y / (1.0f + item.distance));

JoystickPosAdjusted /= SensivityIdx;
JoystickPosAdjusted *= 2.0f; // a 1.0f vector means a 100% increase
}

// Apply direction
Expand Down

0 comments on commit b02c989

Please sign in to comment.