Skip to content

Instantly share code, notes, and snippets.

@Ryochan7
Last active March 8, 2016 23:28
Show Gist options
  • Save Ryochan7/5c939fd53c508ad63a59 to your computer and use it in GitHub Desktop.
Save Ryochan7/5c939fd53c508ad63a59 to your computer and use it in GitHub Desktop.
Touchmote fpsmouse mode tests
diff --git a/WiiTUIO/Input/WiiProvider/Keymap/WiiKeyMap.cs b/WiiTUIO/Input/WiiProvider/Keymap/WiiKeyMap.cs
index 4e2f131..bcc6014 100644
--- a/WiiTUIO/Input/WiiProvider/Keymap/WiiKeyMap.cs
+++ b/WiiTUIO/Input/WiiProvider/Keymap/WiiKeyMap.cs
@@ -161,12 +161,12 @@ public void updateAccelerometer(AccelState accelState)
updateStickHandlers(outConfig, 0);
}
- if (accelState.Values.X * 2 > outConfig.Threshold && !PressedButtons["AccelX+"])
+ if (accelState.Values.X > outConfig.Threshold && !PressedButtons["AccelX+"])
{
PressedButtons["AccelX+"] = true;
this.executeButtonDown("AccelX+");
}
- else if (accelState.Values.X * 2 < outConfig.Threshold && PressedButtons["AccelX+"])
+ else if (accelState.Values.X < outConfig.Threshold && PressedButtons["AccelX+"])
{
PressedButtons["AccelX+"] = false;
this.executeButtonUp("AccelX+");
@@ -183,12 +183,12 @@ public void updateAccelerometer(AccelState accelState)
updateStickHandlers(outConfig, 0);
}
- if (accelState.Values.X * -2 > outConfig.Threshold && !PressedButtons["AccelX-"])
+ if (accelState.Values.X * -1 > outConfig.Threshold && !PressedButtons["AccelX-"])
{
PressedButtons["AccelX-"] = true;
this.executeButtonDown("AccelX-");
}
- else if (accelState.Values.X * -2 < outConfig.Threshold && PressedButtons["AccelX-"])
+ else if (accelState.Values.X * -1 < outConfig.Threshold && PressedButtons["AccelX-"])
{
PressedButtons["AccelX-"] = false;
this.executeButtonUp("AccelX-");
@@ -205,12 +205,12 @@ public void updateAccelerometer(AccelState accelState)
updateStickHandlers(outConfig, 0);
}
- if (accelState.Values.Y * 2 > outConfig.Threshold && !PressedButtons["AccelY+"])
+ if (accelState.Values.Y > outConfig.Threshold && !PressedButtons["AccelY+"])
{
PressedButtons["AccelY+"] = true;
this.executeButtonDown("AccelY+");
}
- else if (accelState.Values.Y * 2 < outConfig.Threshold && PressedButtons["AccelY+"])
+ else if (accelState.Values.Y < outConfig.Threshold && PressedButtons["AccelY+"])
{
PressedButtons["AccelY+"] = false;
this.executeButtonUp("AccelY+");
@@ -227,12 +227,12 @@ public void updateAccelerometer(AccelState accelState)
updateStickHandlers(outConfig, 0);
}
- if (accelState.Values.Y * -2 > outConfig.Threshold && !PressedButtons["AccelY-"])
+ if (accelState.Values.Y * -1 > outConfig.Threshold && !PressedButtons["AccelY-"])
{
PressedButtons["AccelY-"] = true;
this.executeButtonDown("AccelY-");
}
- else if (accelState.Values.Y * -2 < outConfig.Threshold && PressedButtons["AccelY-"])
+ else if (accelState.Values.Y * -1 < outConfig.Threshold && PressedButtons["AccelY-"])
{
PressedButtons["AccelY-"] = false;
this.executeButtonUp("AccelY-");
@@ -249,12 +249,12 @@ public void updateAccelerometer(AccelState accelState)
updateStickHandlers(outConfig, 0);
}
- if (accelState.Values.Z * 2 > outConfig.Threshold && !PressedButtons["AccelZ+"])
+ if (accelState.Values.Z > outConfig.Threshold && !PressedButtons["AccelZ+"])
{
PressedButtons["AccelZ+"] = true;
this.executeButtonDown("AccelZ+");
}
- else if (accelState.Values.Z * 2 < outConfig.Threshold && PressedButtons["AccelZ+"])
+ else if (accelState.Values.Z < outConfig.Threshold && PressedButtons["AccelZ+"])
{
PressedButtons["AccelZ+"] = false;
this.executeButtonUp("AccelZ+");
@@ -271,12 +271,12 @@ public void updateAccelerometer(AccelState accelState)
updateStickHandlers(outConfig, 0);
}
- if (accelState.Values.Z * -2 > outConfig.Threshold && !PressedButtons["AccelZ-"])
+ if (accelState.Values.Z * -1 > outConfig.Threshold && !PressedButtons["AccelZ-"])
{
PressedButtons["AccelZ-"] = true;
this.executeButtonDown("AccelZ-");
}
- else if (accelState.Values.Z * -2 < outConfig.Threshold && PressedButtons["AccelZ-"])
+ else if (accelState.Values.Z * -1 < outConfig.Threshold && PressedButtons["AccelZ-"])
{
PressedButtons["AccelZ-"] = false;
this.executeButtonUp("AccelZ-");
@@ -392,12 +392,12 @@ public void updateNunchuk(NunchukState nunchuk)
updateStickHandlers(outConfig, 0);
}
- if (accelState.Values.X * 2 > outConfig.Threshold && !PressedButtons["Nunchuk.AccelX+"])
+ if (accelState.Values.X > outConfig.Threshold && !PressedButtons["Nunchuk.AccelX+"])
{
PressedButtons["Nunchuk.AccelX+"] = true;
this.executeButtonDown("Nunchuk.AccelX+");
}
- else if (accelState.Values.X * 2 < outConfig.Threshold && PressedButtons["Nunchuk.AccelX+"])
+ else if (accelState.Values.X < outConfig.Threshold && PressedButtons["Nunchuk.AccelX+"])
{
PressedButtons["Nunchuk.AccelX+"] = false;
this.executeButtonUp("Nunchuk.AccelX+");
@@ -414,12 +414,12 @@ public void updateNunchuk(NunchukState nunchuk)
updateStickHandlers(outConfig, 0);
}
- if (accelState.Values.X * -2 > outConfig.Threshold && !PressedButtons["Nunchuk.AccelX-"])
+ if (accelState.Values.X * -1 > outConfig.Threshold && !PressedButtons["Nunchuk.AccelX-"])
{
PressedButtons["Nunchuk.AccelX-"] = true;
this.executeButtonDown("Nunchuk.AccelX-");
}
- else if (accelState.Values.X * -2 < outConfig.Threshold && PressedButtons["Nunchuk.AccelX-"])
+ else if (accelState.Values.X * -1 < outConfig.Threshold && PressedButtons["Nunchuk.AccelX-"])
{
PressedButtons["Nunchuk.AccelX-"] = false;
this.executeButtonUp("Nunchuk.AccelX-");
@@ -436,12 +436,12 @@ public void updateNunchuk(NunchukState nunchuk)
updateStickHandlers(outConfig, 0);
}
- if (accelState.Values.Y * 2 > outConfig.Threshold && !PressedButtons["Nunchuk.AccelY+"])
+ if (accelState.Values.Y > outConfig.Threshold && !PressedButtons["Nunchuk.AccelY+"])
{
PressedButtons["Nunchuk.AccelY+"] = true;
this.executeButtonDown("Nunchuk.AccelY+");
}
- else if (accelState.Values.Y * 2 < outConfig.Threshold && PressedButtons["Nunchuk.AccelY+"])
+ else if (accelState.Values.Y < outConfig.Threshold && PressedButtons["Nunchuk.AccelY+"])
{
PressedButtons["Nunchuk.AccelY+"] = false;
this.executeButtonUp("Nunchuk.AccelY+");
@@ -458,12 +458,12 @@ public void updateNunchuk(NunchukState nunchuk)
updateStickHandlers(outConfig, 0);
}
- if (accelState.Values.Y * -2 > outConfig.Threshold && !PressedButtons["Nunchuk.AccelY-"])
+ if (accelState.Values.Y * -1 > outConfig.Threshold && !PressedButtons["Nunchuk.AccelY-"])
{
PressedButtons["Nunchuk.AccelY-"] = true;
this.executeButtonDown("Nunchuk.AccelY-");
}
- else if (accelState.Values.Y * -2 < outConfig.Threshold && PressedButtons["Nunchuk.AccelY-"])
+ else if (accelState.Values.Y * -1 < outConfig.Threshold && PressedButtons["Nunchuk.AccelY-"])
{
PressedButtons["Nunchuk.AccelY-"] = false;
this.executeButtonUp("Nunchuk.AccelY-");
@@ -480,12 +480,12 @@ public void updateNunchuk(NunchukState nunchuk)
updateStickHandlers(outConfig, 0);
}
- if (accelState.Values.Z * 2 > outConfig.Threshold && !PressedButtons["Nunchuk.AccelZ+"])
+ if (accelState.Values.Z > outConfig.Threshold && !PressedButtons["Nunchuk.AccelZ+"])
{
PressedButtons["Nunchuk.AccelZ+"] = true;
this.executeButtonDown("Nunchuk.AccelZ+");
}
- else if (accelState.Values.Z * 2 < outConfig.Threshold && PressedButtons["Nunchuk.AccelZ+"])
+ else if (accelState.Values.Z < outConfig.Threshold && PressedButtons["Nunchuk.AccelZ+"])
{
PressedButtons["Nunchuk.AccelZ+"] = false;
this.executeButtonUp("Nunchuk.AccelZ+");
@@ -502,12 +502,12 @@ public void updateNunchuk(NunchukState nunchuk)
updateStickHandlers(outConfig, 0);
}
- if (accelState.Values.Z * -2 > outConfig.Threshold && !PressedButtons["Nunchuk.AccelZ-"])
+ if (accelState.Values.Z * -1 > outConfig.Threshold && !PressedButtons["Nunchuk.AccelZ-"])
{
PressedButtons["Nunchuk.AccelZ-"] = true;
this.executeButtonDown("Nunchuk.AccelZ-");
}
- else if (accelState.Values.Z * -2 < outConfig.Threshold && PressedButtons["Nunchuk.AccelZ-"])
+ else if (accelState.Values.Z * -1 < outConfig.Threshold && PressedButtons["Nunchuk.AccelZ-"])
{
PressedButtons["Nunchuk.AccelZ-"] = false;
this.executeButtonUp("Nunchuk.AccelZ-");
diff --git a/WiiTUIO/Output/Handlers/MouseHandler.cs b/WiiTUIO/Output/Handlers/MouseHandler.cs
index 7aa5f8b..f632fe6 100644
--- a/WiiTUIO/Output/Handlers/MouseHandler.cs
+++ b/WiiTUIO/Output/Handlers/MouseHandler.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -10,6 +11,7 @@
using WindowsInput;
using WindowsInput.Native;
+
namespace WiiTUIO.Output.Handlers
{
public class MouseHandler : IButtonHandler, IStickHandler, ICursorHandler
@@ -19,12 +21,52 @@ public class MouseHandler : IButtonHandler, IStickHandler, ICursorHandler
private bool mouseLeftDown = false;
private bool mouseRightDown = false;
+ // Remainder values used for partial mouse distance calculations.
+ private double remainderX = 0.0;
+ private double remainderY = 0.0;
+ // PointerX and PointerY values from previous Wiimote poll.
+ private double previousPointerX = 0.5;
+ private double previousPointerY = 0.5;
+
+ // Check elapsed time that delta acceleration is applied.
+ private Stopwatch deltaEasingTimeX;
+ private Stopwatch deltaEasingTimeY;
+
+ // Keep track of current acceleration multiplier in directions.
+ private double accelHelperX = 0.0;
+ private double accelHelperY = 0.0;
+ // Keep track of travel value that caused acceleration
+ private double accelTravelX = 0.0;
+ private double accelTravelY = 0.0;
+
+ // Add period of mouse movement when remote is out of IR range.
+ private Stopwatch outOfReachElapsed;
+ private bool outOfReachStatus = true;
+
+ // Add dead period when remote is initially moved into IR range.
+ private Stopwatch initialInReachElapsed;
+ private bool initialInReachStatus = false;
+
+ // Add small easing region in final acceleration region
+ // for X axis
+ private Stopwatch regionEasingX;
+ //private bool enableRegionEasing = true;
+
private CursorPositionHelper cursorPositionHelper;
+ // Measured in milliseconds
+ public const int OUTOFREACH_ELAPSED_TIME = 1000;
+ public const int INITIAL_INREACH_ELAPSED_TIME = 125;
+
public MouseHandler()
{
this.inputSimulator = new InputSimulator();
cursorPositionHelper = new CursorPositionHelper();
+ this.deltaEasingTimeX = new Stopwatch();
+ this.deltaEasingTimeY = new Stopwatch();
+ this.outOfReachElapsed = new Stopwatch();
+ this.initialInReachElapsed = new Stopwatch();
+ this.regionEasingX = new Stopwatch();
}
public bool reset()
@@ -76,7 +118,7 @@ public bool setButtonUp(string key)
break;
case MouseCode.MOUSERIGHT:
this.inputSimulator.Mouse.RightButtonUp();
- mouseLeftDown = false;
+ mouseRightDown = false;
break;
default:
return false;
@@ -101,26 +143,520 @@ public bool setPosition(string key, CursorPos cursorPos)
if (key.Equals("fpsmouse"))
{
- Point smoothedPos = cursorPositionHelper.getSmoothedPosition(new Point(cursorPos.RelativeX, cursorPos.RelativeY));
+ bool shouldMoveFPSCursor = !outOfReachStatus;
- /*
- * TODO: Consider sensor bar position?
- if (Settings.Default.pointer_sensorBarPos == "top")
+ if (!cursorPos.OutOfReach)
{
- smoothedPos.Y = smoothedPos.Y - Settings.Default.pointer_sensorBarPosCompensation;
+ // If remote in IR range, uncheck out of reach status.
+ outOfReachStatus = false;
+ if (outOfReachElapsed.IsRunning)
+ {
+ outOfReachElapsed.Stop();
+ }
+
+ // Check if remote has been moved into IR range.
+ if (initialInReachStatus)
+ {
+ if (!initialInReachElapsed.IsRunning)
+ {
+ // Start timer if not running.
+ initialInReachElapsed.Restart();
+ }
+
+ if (initialInReachElapsed.IsRunning)
+ {
+ if (initialInReachElapsed.ElapsedMilliseconds < INITIAL_INREACH_ELAPSED_TIME)
+ {
+ shouldMoveFPSCursor = false;
+ }
+ else
+ {
+ shouldMoveFPSCursor = true;
+ initialInReachStatus = false;
+ initialInReachElapsed.Stop();
+ }
+ }
+ }
+ else
+ {
+ shouldMoveFPSCursor = true;
+ }
}
- else if (Settings.Default.pointer_sensorBarPos == "bottom")
+ else if (!outOfReachStatus)
{
- smoothedPos.Y = smoothedPos.Y + Settings.Default.pointer_sensorBarPosCompensation;
+ if (!outOfReachElapsed.IsRunning)
+ {
+ // Start timer if not running.
+ outOfReachElapsed.Restart();
+ }
+
+ if (outOfReachElapsed.IsRunning)
+ {
+ // Check if time has passed. If so, mark out of reach
+ // status bool shouldMoveFPSCursor = !outOfReachStatus;and stop timer.
+ long elapsed = outOfReachElapsed.ElapsedMilliseconds;
+ if (elapsed >= OUTOFREACH_ELAPSED_TIME)
+ {
+ outOfReachStatus = true;
+ outOfReachElapsed.Stop();
+ }
+ else
+ {
+ // Time has not elapsed. Keep out of reach status
+ // at false.
+ outOfReachStatus = false;
+ }
+ }
+
}
- */
- double deadzone = Settings.Default.fpsmouse_deadzone; // TODO: Move to settings
- double shiftX = Math.Abs(smoothedPos.X - 0.5) > deadzone ? smoothedPos.X - 0.5 : 0;
- double shiftY = Math.Abs(smoothedPos.Y - 0.5) > deadzone ? smoothedPos.Y - 0.5 : 0;
- this.inputSimulator.Mouse.MoveMouseBy((int)(Settings.Default.fpsmouse_speed * shiftX), (int)(Settings.Default.fpsmouse_speed * shiftY));
+ // Checks show that remote should be considered in IR range.
+ if (shouldMoveFPSCursor)
+ //if (!outOfReachStatus)
+ {
+ //Point smoothedPos = cursorPositionHelper.getSmoothedPosition(new Point(cursorPos.RelativeX, cursorPos.RelativeY));
+ // Use proper IR values for full IR range and to take
+ // margins into account.
+ Point smoothedPos = cursorPositionHelper.getRelativePosition(new Point(cursorPos.X, cursorPos.Y));
- return true;
+ /*
+ * TODO: Consider sensor bar position?
+ if (Settings.Default.pointer_sensorBarPos == "top")
+ {
+ smoothedPos.Y = smoothedPos.Y - Settings.Default.pointer_sensorBarPosCompensation;
+ }
+ else if (Settings.Default.pointer_sensorBarPos == "bottom")
+ {
+ smoothedPos.Y = smoothedPos.Y + Settings.Default.pointer_sensorBarPosCompensation;
+ }
+ */
+ //double deadzone = Settings.Default.fpsmouse_deadzone; // TODO: Move to settings
+ double deadzone = Settings.Default.fpsmouse_deadzone;
+
+ // Make dead zone region circular instead of a square.
+ double tempdeadangle = Math.Atan2(-(smoothedPos.Y - 0.5), smoothedPos.X - 0.5);
+ double deadzoneX = deadzone * Math.Abs(Math.Cos(tempdeadangle));
+ double deadzoneY = deadzone * 1.0 * Math.Abs(Math.Sin(tempdeadangle));
+
+ double fps_mouse_speed = Settings.Default.fpsmouse_speed;
+
+ double testAccelMulti = Settings.Default.test_deltaAccelMulti;
+ double testAccelMinTravel = Settings.Default.test_deltaAccelMinTravel;
+ double testAccelMaxTravel = Settings.Default.test_deltaAccelMaxTravel > testAccelMinTravel ? Settings.Default.test_deltaAccelMaxTravel : 0.5;
+ double testAccelEasingDuration = Settings.Default.test_deltaAccelEasingDuration;
+ bool testDeltaAccel = Settings.Default.test_deltaAccel;
+
+ double shiftX = 0.0;
+ double shiftY = 0.0;
+
+ // Find X distance away from assigned dead zone
+ if (Math.Abs(smoothedPos.X - 0.5) > deadzoneX)
+ {
+ if (smoothedPos.X >= 0.5)
+ {
+ shiftX = (smoothedPos.X - 0.5 - deadzoneX) / (1.0 - 0.5 - deadzoneX);
+ }
+ else
+ {
+ shiftX = (smoothedPos.X - (0.5 - deadzoneX)) / (1.0 - 0.5 - deadzoneX);
+ }
+ }
+
+ // Find Y distance away from assigned dead zone
+ if (Math.Abs(smoothedPos.Y - 0.5) > deadzoneY)
+ {
+ if (smoothedPos.Y >= 0.5)
+ {
+ shiftY = (smoothedPos.Y - 0.5 - deadzoneY) / (1.0 - 0.5 - deadzoneY);
+ }
+ else
+ {
+ shiftY = (smoothedPos.Y - (0.5 - deadzoneY)) / (1.0 - 0.5 - deadzoneY);
+ }
+ }
+
+ //double shiftX = Math.Abs(smoothedPos.X - 0.5) > deadzone ? (smoothedPos.X - 0.5) : 0;
+ //double shiftY = Math.Abs(smoothedPos.Y - 0.5) > deadzone ? (smoothedPos.Y - 0.5) : 0;
+
+ // Need sign components for later calculations
+ double signshiftX = (shiftX >= 0) ? 1.0 : -1.0;
+ double signshiftY = (shiftY >= 0) ? 1.0 : -1.0;
+
+ // Need absolute values for later calculations
+ double absX = Math.Abs(shiftX);
+ double absY = Math.Abs(shiftY);
+
+ if (absX <= 0.75 && regionEasingX.IsRunning)
+ {
+ // No longer in easing region
+ regionEasingX.Stop();
+ }
+ else if (absX > 0.75 && regionEasingX.IsRunning &&
+ (previousPointerX >= 0.5) != (smoothedPos.X >= 0.5))
+ {
+ // Direction changed quickly. Restart easing timer.
+ regionEasingX.Restart();
+ }
+
+ // Use three types of acceleration depending on distance
+ // away from dead zone. Will need to change later.
+ if (absX <= 0.4)
+ {
+ shiftX = 0.395 * absX;
+ }
+ else if (absX <= 0.75)
+ {
+ shiftX = 1.0 * absX - 0.242;
+ }
+ else
+ {
+ double tempAbsx = absX;
+ bool enableRegionEasing = Settings.Default.test_regionEasingXDuration > 0.0;
+ if (enableRegionEasing)
+ {
+ double easingDuration = Settings.Default.test_regionEasingXDuration;
+ double easingOffset = Settings.Default.test_regionEasingXOffset;
+ double easingElapsed = 0.0;
+ double elapsedDiff = 1.0;
+ if (regionEasingX.IsRunning)
+ {
+ easingElapsed = regionEasingX.ElapsedMilliseconds;
+ }
+ else
+ {
+ regionEasingX.Restart();
+ }
+
+ double adjustedEasingDuration = ((4.0 * absX) - 3.0) * easingDuration;
+ //double adjustedEasingDuration = easingDuration;
+ if (easingDuration > 0.0 && adjustedEasingDuration > 0.0 &&
+ (easingElapsed * 0.001) < adjustedEasingDuration)
+ {
+ //elapsedDiff = (easingElapsed * 0.001) / easingDuration;
+ //double minAbsRegionX = 0.75;
+ double minAbsRegionX = absX + (easingOffset * (absX - 0.75));
+ elapsedDiff = (easingElapsed * 0.001) / adjustedEasingDuration;
+ //elapsedDiff = (absX - 0.75) * elapsedDiff + 0.75;
+ elapsedDiff = (absX - minAbsRegionX) * elapsedDiff + minAbsRegionX;
+ }
+ else
+ {
+ elapsedDiff = absX;
+ }
+
+ tempAbsx = elapsedDiff;
+ }
+
+ shiftX = 1.968 * tempAbsx - 0.968;
+ }
+
+ // Use three types of acceleration depending on distance
+ // away from dead zone. Will need to change later.
+ if (absY <= 0.4)
+ {
+ shiftY = 0.395 * absY;
+ }
+ else if (absY <= 0.75)
+ {
+ shiftY = 1.0 * absY - 0.242;
+ }
+ else
+ {
+ shiftY = 1.968 * absY - 0.968;
+ }
+
+ // Add sign bit
+ shiftX = signshiftX * shiftX;
+ shiftY = signshiftY * shiftY;
+
+ // Calculate delta acceleration slope and offset.
+ double accelSlope = (testAccelMulti - 1.0) / (testAccelMaxTravel - testAccelMinTravel);
+ double accelOffset = 1.0 - (accelSlope * testAccelMinTravel);
+
+ // If deltaX >= 0.1 and displacement is increasing then
+ // use acceleration multiplier.
+ if (testDeltaAccel && Math.Abs(previousPointerX - smoothedPos.X) >= testAccelMinTravel &&
+ (smoothedPos.X - previousPointerX >= 0.0) == (smoothedPos.X >= 0.5))
+ {
+ double tempTravel = Math.Min(Math.Abs(previousPointerX - smoothedPos.X), testAccelMaxTravel);
+ if (accelHelperX > 1.0)
+ {
+ // Already in acceleration mode. Add accel
+ // dead zone to travel.
+ tempTravel = Math.Min(tempTravel + testAccelMinTravel, testAccelMaxTravel);
+ }
+
+ //double tempDist = Math.Min(tempTravel / 0.5, 1.0);
+ double tempDist = Math.Min(tempTravel, testAccelMaxTravel);
+
+ /*double currentAccelMultiTemp = (accelSlope * tempDist + accelOffset);
+ double getMultiDiff = (currentAccelMultiTemp - 1.0) / (testAccelMulti - 1.0);
+ //currentAccelMultiTemp = -(testAccelMulti - 1.0) / (getMultiDiff * (getMultiDiff - 2.0)) + 1.0;
+ currentAccelMultiTemp = (testAccelMulti - 1.0) / Math.Sin(getMultiDiff * (Math.PI / 2.0)) + 1.0;
+
+ shiftX = shiftX * currentAccelMultiTemp;
+ previousPointerX = smoothedPos.X;
+ accelHelperX = currentAccelMultiTemp;
+ accelTravelX = tempTravel;
+ deltaEasingTimeX.Restart();
+ */
+
+ shiftX = shiftX * (accelSlope * tempDist + accelOffset);
+ previousPointerX = smoothedPos.X;
+ accelHelperX = (accelSlope * tempDist + accelOffset);
+ accelTravelX = tempTravel;
+ deltaEasingTimeX.Restart();
+ }
+ else if (testDeltaAccel && testAccelEasingDuration > 0.00 &&
+ accelHelperX > 0.0 &&
+ Math.Abs(smoothedPos.X - previousPointerX) < testAccelMinTravel &&
+ (previousPointerX >= 0.5) == (smoothedPos.X >= 0.5))
+ {
+ double timeElapsed = deltaEasingTimeX.ElapsedMilliseconds;
+ double elapsedDiff = 1.0;
+ double tempAccel = accelHelperX;
+ double tempTravel = accelTravelX;
+
+ if ((smoothedPos.X - previousPointerX >= 0.0) != (smoothedPos.X >= 0.5))
+ {
+ // Travelling towards dead zone. Decrease acceleration and duration.
+ tempTravel = Math.Min(Math.Abs(previousPointerX - smoothedPos.X), testAccelMaxTravel);
+ tempTravel = Math.Max(Math.Min((accelTravelX - tempTravel), testAccelMaxTravel), testAccelMinTravel);
+ tempAccel = (accelSlope * tempTravel + accelOffset);
+ }
+
+ double elapsedDuration = testAccelEasingDuration * (tempAccel / testAccelMulti);
+
+ /*double getMultiDiff = (tempAccel - 1.0) / (testAccelMulti - 1.0);
+ //double tempinner = getMultiDiff * (getMultiDiff - 2.0);
+ //timeElapsed = (-testAccelEasingDuration * tempinner + 0.0);
+ //double currentAccelMultiTemp = -(testAccelMulti - 1.0) * tempinner + 1.0;
+ double tempinner = Math.Sin(getMultiDiff * (Math.PI / 2.0));
+ timeElapsed = testAccelEasingDuration * tempinner + 0.0;
+ double currentAccelMultiTemp = (testAccelMulti - 1.0) * tempinner + 1.0;
+ tempAccel = currentAccelMultiTemp;
+ */
+
+ if (elapsedDuration > 0.0 && (timeElapsed * 0.001) < elapsedDuration)
+ {
+ elapsedDiff = ((timeElapsed * 0.001) / elapsedDuration);
+ elapsedDiff = (1.0 - tempAccel) * (elapsedDiff * elapsedDiff * elapsedDiff) + tempAccel;
+ shiftX = elapsedDiff * shiftX;
+ }
+ else
+ {
+ // Easing time has ended. Reset values.
+ previousPointerX = smoothedPos.X;
+ accelHelperX = 0.0;
+ accelTravelX = 0.0;
+ deltaEasingTimeX.Stop();
+ //regionEasingX.Stop();
+ }
+ }
+ else
+ {
+ // Don't apply acceleration. Reset values.
+ previousPointerX = smoothedPos.X;
+ accelHelperX = 0.0;
+ accelTravelX = 0.0;
+ if (deltaEasingTimeX.IsRunning)
+ {
+ deltaEasingTimeX.Stop();
+ }
+ }
+
+ // If deltaY >= 0.1 and displacement is increasing then
+ // use acceleration multiplier.
+ if (testDeltaAccel && Math.Abs(previousPointerY - smoothedPos.Y) >= testAccelMinTravel &&
+ (smoothedPos.Y - previousPointerY >= 0.0) == (smoothedPos.Y >= 0.5))
+ {
+ double tempTravel = Math.Min(Math.Abs(previousPointerY - smoothedPos.Y), testAccelMaxTravel);
+ if (accelHelperY > 1.0)
+ {
+ // Already in acceleration mode. Add accel
+ // dead zone to travel.
+ tempTravel = Math.Min(tempTravel + testAccelMinTravel, testAccelMaxTravel);
+ }
+
+ //double tempDist = Math.Min(tempTravel / 0.5, 1.0);
+ double tempDist = Math.Min(tempTravel, testAccelMaxTravel);
+
+ /*double currentAccelMultiTemp = (accelSlope * tempDist + accelOffset);
+ double getMultiDiff = (currentAccelMultiTemp - 1.0) / (testAccelMulti - 1.0);
+ //currentAccelMultiTemp = -(testAccelMulti - 1.0) / (getMultiDiff * (getMultiDiff - 2.0)) + 1.0;
+ currentAccelMultiTemp = (testAccelMulti - 1.0) / Math.Sin(getMultiDiff * (Math.PI / 2.0)) + 1.0;
+
+ shiftY = shiftY * currentAccelMultiTemp;
+ previousPointerY = smoothedPos.Y;
+ accelHelperY = currentAccelMultiTemp;
+ accelTravelY = tempTravel;
+ deltaEasingTimeY.Restart();
+ */
+
+ shiftY = shiftY * (accelSlope * tempDist + accelOffset);
+ previousPointerY = smoothedPos.Y;
+ accelHelperY = (accelSlope * tempDist + accelOffset);
+ accelTravelY = tempTravel;
+ deltaEasingTimeY.Restart();
+ }
+ else if (testDeltaAccel && testAccelEasingDuration > 0.00 &&
+ accelHelperY > 0.0 &&
+ Math.Abs(smoothedPos.Y - previousPointerY) < testAccelMinTravel &&
+ (previousPointerY >= 0.5) == (smoothedPos.Y >= 0.5))
+ {
+ double timeElapsed = deltaEasingTimeY.ElapsedMilliseconds;
+ double elapsedDiff = 1.0;
+ double tempAccel = accelHelperY;
+ double tempTravel = accelTravelY;
+
+ if ((smoothedPos.Y - previousPointerY >= 0.0) != (smoothedPos.Y >= 0.5))
+ {
+ // Travelling towards dead zone. Decrease acceleration and duration.
+ tempTravel = Math.Min(Math.Abs(previousPointerY - smoothedPos.Y), testAccelMaxTravel);
+ tempTravel = Math.Max(Math.Min((accelTravelY - tempTravel), testAccelMaxTravel), testAccelMinTravel);
+ tempAccel = (accelSlope * tempTravel + accelOffset);
+ }
+
+ double elapsedDuration = testAccelEasingDuration * (tempAccel / testAccelMulti);
+
+ /*double getMultiDiff = (tempAccel - 1.0) / (testAccelMulti - 1.0);
+ //double tempinner = getMultiDiff * (getMultiDiff - 2.0);
+ //timeElapsed = -testAccelEasingDuration * tempinner + 0.0;
+ //double currentAccelMultiTemp = -(testAccelMulti - 1.0) * tempinner + 1.0;
+ double tempinner = Math.Sin(getMultiDiff * (Math.PI / 2.0));
+ timeElapsed = testAccelEasingDuration * tempinner + 0.0;
+ double currentAccelMultiTemp = (testAccelMulti - 1.0) * tempinner + 1.0;
+ tempAccel = currentAccelMultiTemp;
+ */
+
+ if (elapsedDuration > 0.0 && (timeElapsed * 0.001) < elapsedDuration)
+ {
+ elapsedDiff = ((timeElapsed * 0.001) / elapsedDuration);
+ elapsedDiff = (1.0 - tempAccel) * (elapsedDiff * elapsedDiff * elapsedDiff) + tempAccel;
+ shiftY = elapsedDiff * shiftY;
+ }
+ else
+ {
+ // Easing time has ended. Reset values.
+ previousPointerY = smoothedPos.Y;
+ accelHelperY = 0.0;
+ accelTravelY = 0.0;
+ deltaEasingTimeY.Stop();
+ }
+ }
+ else
+ {
+ // Don't apply acceleration. Reset values.
+ previousPointerY = smoothedPos.Y;
+ accelHelperY = 0.0;
+ accelTravelY = 0.0;
+ if (deltaEasingTimeY.IsRunning)
+ {
+ deltaEasingTimeY.Stop();
+ }
+ }
+
+ // Find initial relative mouse speed
+ double mouseX = fps_mouse_speed * shiftX;
+ double mouseY = fps_mouse_speed * shiftY;
+
+ // Only apply remainder if both current displacement and
+ // remainder follow the same direction.
+ if ((remainderX >= 0) == (mouseX >= 0))
+ {
+ mouseX += remainderX;
+ }
+
+ // Only apply remainder if both current displacement and
+ // remainder follow the same direction.
+ if ((remainderY >= 0) == (mouseY >= 0))
+ {
+ mouseY += remainderY;
+ }
+
+ // Make sure relative mouse movement does not exceed 127 pixels.
+ if (Math.Abs(mouseX) > 127)
+ {
+ mouseX = (mouseX < 0) ? -127 : 127;
+ }
+
+ // Make sure relative mouse movement does not exceed 127 pixels.
+ if (Math.Abs(mouseY) > 127)
+ {
+ mouseY = (mouseY < 0) ? -127 : 127;
+ }
+
+ // Reset remainder values
+ remainderX = 0.0;
+ remainderY = 0.0;
+
+ // Round mouseX distance to zero and save remainder.
+ // Prefer over rounding to nearest.
+ if (mouseX > 0.0)
+ {
+ double temp = Math.Floor(mouseX);
+ remainderX = mouseX - temp;
+ mouseX = temp;
+ }
+ else if (mouseX < 0.0)
+ {
+ double temp = Math.Ceiling(mouseX);
+ remainderX = mouseX - temp;
+ mouseX = temp;
+ }
+
+ // Round mouseY distance to zero and save remainder.
+ // Prefer over rounding to nearest.
+ if (mouseY > 0.0)
+ {
+ double temp = Math.Floor(mouseY);
+ remainderY = mouseY - temp;
+ mouseY = temp;
+ }
+ else if (mouseY < 0.0)
+ {
+ double temp = Math.Ceiling(mouseY);
+ remainderY = mouseY - temp;
+ mouseY = temp;
+ }
+
+ //this.inputSimulator.Mouse.MoveMouseBy((int)(Settings.Default.fpsmouse_speed * shiftX), (int)(Settings.Default.fpsmouse_speed * shiftY));
+ // Need to double check if sync would happen if (0,0).
+ if (mouseX != 0.0 || mouseY != 0.0)
+ {
+ this.inputSimulator.Mouse.MoveMouseBy((int)mouseX, (int)mouseY);
+ }
+
+ return true;
+ }
+ else
+ {
+ // Consider outside of IR range. Reset some values.
+ remainderX = 0.0;
+ remainderY = 0.0;
+
+ accelHelperX = 0.0;
+ accelHelperY = 0.0;
+ accelTravelX = 0.0;
+ accelTravelY = 0.0;
+
+ if (deltaEasingTimeX.IsRunning)
+ {
+ deltaEasingTimeX.Stop();
+ }
+
+ if (deltaEasingTimeY.IsRunning)
+ {
+ deltaEasingTimeY.Stop();
+ }
+
+ initialInReachStatus = true;
+
+ if (regionEasingX.IsRunning)
+ {
+ regionEasingX.Stop();
+ }
+ }
}
return false;
}
diff --git a/WiiTUIO/Properties/Settings.cs b/WiiTUIO/Properties/Settings.cs
index 003d6c8..31aec74 100644
--- a/WiiTUIO/Properties/Settings.cs
+++ b/WiiTUIO/Properties/Settings.cs
@@ -347,6 +347,110 @@ public int pointer_FPS
}
}
+ // Should delta acceleration be enabled.
+ private bool _test_deltaAccel = true;
+ public bool test_deltaAccel
+ {
+ get { return _test_deltaAccel; }
+ set
+ {
+ _test_deltaAccel = value;
+ OnPropertyChanged("test_deltaAccel");
+ }
+ }
+
+ // Maximum multiplier to use for delta acceleration.
+ private double _test_deltaAccelMulti = 4.0;
+ public double test_deltaAccelMulti
+ {
+ get { return _test_deltaAccelMulti; }
+ set
+ {
+ if (value >= 1.0 && value <= 20.0)
+ {
+ _test_deltaAccelMulti = value;
+ OnPropertyChanged("test_deltaAccelMulti");
+ }
+ }
+ }
+
+ // Minimum delta travel before delta acceleration is applied.
+ private double _test_deltaAccelMinTravel = 0.1;
+ public double test_deltaAccelMinTravel
+ {
+ get { return _test_deltaAccelMinTravel; }
+ set
+ {
+ if (value >= 0.01 && value <= 0.5)
+ {
+ _test_deltaAccelMinTravel = value;
+ OnPropertyChanged("test_deltaAccelMinTravel");
+ }
+ }
+ }
+
+ // Maximum duration that delta acceleration should be applied.
+ // Value is in seconds.
+ private double _test_deltaAccelEasingDuration = 0.05;
+ public double test_deltaAccelEasingDuration
+ {
+ get { return _test_deltaAccelEasingDuration; }
+ set
+ {
+ if (value >= 0.00 && value <= 10.0)
+ {
+ _test_deltaAccelEasingDuration = value;
+ OnPropertyChanged("test_deltaAccelEasingDuration");
+ }
+ }
+
+ }
+
+ // Maximum duration that easing is applied to upper acceleration
+ // region.
+ private double _test_regionEasingXDuration = 0.025;
+ public double test_regionEasingXDuration
+ {
+ get { return _test_regionEasingXDuration; }
+ set
+ {
+ if (value >= 0.00 && value <= 10.0)
+ {
+ _test_regionEasingXDuration = value;
+ OnPropertyChanged("test_regionEasingXDuration");
+ }
+ }
+ }
+
+ // Maximum delta travel before maximum delta acceleration is applied.
+ private double _test_deltaAccelMaxTravel = 0.5;
+ public double test_deltaAccelMaxTravel
+ {
+ get { return _test_deltaAccelMaxTravel; }
+ set
+ {
+ if (value >= 0.01 && value <= 0.5)
+ {
+ _test_deltaAccelMaxTravel = value;
+ OnPropertyChanged("test_deltaAccelMaxTravel");
+ }
+ }
+ }
+
+ private double _test_regionEasingXOffset = 0.8;
+ public double test_regionEasingXOffset
+ {
+ get { return _test_regionEasingXOffset; }
+ set
+ {
+ if (value >= 0.0 && value <= 1.0)
+ {
+ _test_regionEasingXOffset = value;
+ OnPropertyChanged("test_regionEasingXOffset");
+ }
+ }
+ }
+
private int _pointer_positionSmoothing = 3;
public int pointer_positionSmoothing
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment