Skip to content

Commit b82a72f

Browse files
committed
Merge branch 'smoothingfilter' into antichatterfilter
2 parents 9b1883a + 198b144 commit b82a72f

File tree

7 files changed

+112
-21
lines changed

7 files changed

+112
-21
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule ".modules/OpenTabletDriver"]
2+
path = .modules/OpenTabletDriver
3+
url = https://github.com/InfinityGhost/OpenTabletDriver

.modules/OpenTabletDriver

Submodule OpenTabletDriver added at 01e068b

TabletDriverFilters/TabletFilterAntiChatter.cs renamed to DevocubFilters/AntiChatter.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
using System;
2-
using TabletDriverPlugin;
3-
using TabletDriverPlugin.Attributes;
4-
using TabletDriverPlugin.Tablet;
2+
using System.Numerics;
3+
using OpenTabletDriver.Plugin.Attributes;
4+
using OpenTabletDriver.Plugin.Tablet;
55

6-
namespace TabletDriverFilters
6+
namespace TabletDriverFilters.Devocub
77
{
88
using static Math;
99

10-
[PluginName("TabletDriver AntiChatterFilter")]
11-
public class TabletFilterAntiChatter : IFilter
10+
[PluginName("TabletDriver AntiChatter Filter")]
11+
public class AntiChatter : IFilter
1212
{
13-
private Point _lastPos;
13+
private Vector2 _lastPos;
1414
private float _timerInterval;
1515
private const float _threshold = 0.63f;
1616
private float _latency;
1717

18-
public Point Filter(Point point)
18+
public Vector2 Filter(Vector2 point)
1919
{
20-
Point calcTarget = new Point();
20+
Vector2 calcTarget = new Vector2();
2121
double deltaX, deltaY, distance, weightModifier, predictionModifier;
2222

2323
if (_lastPos == null)
@@ -80,7 +80,7 @@ public Point Filter(Point point)
8080
_lastPos.Y += (float)(deltaY * weightModifier);
8181

8282
// OTDPlugin 0.3.2 feature
83-
// TabletDriverPlugin.Log.Write("Antichatter", $"orig: ({point}) new: ({_lastPos}) dist: ({point.DistanceFrom(_lastPos)})", LogLevel.Debug);
83+
// OpenTabletDriver.Plugin.Log.Write("Antichatter", $"orig: ({point}) new: ({_lastPos}) dist: ({point.DistanceFrom(_lastPos)})", LogLevel.Debug);
8484
return _lastPos;
8585
}
8686

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
5-
</PropertyGroup>
6-
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
77
<ItemGroup>
8-
<PackageReference Include="TabletDriverPlugin" Version="0.3.0" />
9-
</ItemGroup>
10-
11-
</Project>
8+
<ProjectReference Include="../.modules/OpenTabletDriver/OpenTabletDriver.Plugin/OpenTabletDriver.Plugin.csproj" />
9+
</ItemGroup>
10+
11+
</Project>

HawkuFilters/HawkuFilters.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<ProjectReference Include="../.modules/OpenTabletDriver/OpenTabletDriver.Plugin/OpenTabletDriver.Plugin.csproj" />
9+
</ItemGroup>
10+
11+
</Project>

HawkuFilters/Smoothing.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Numerics;
3+
using OpenTabletDriver.Plugin.Attributes;
4+
using OpenTabletDriver.Plugin.Tablet;
5+
6+
namespace TabletDriverFilters.Hawku
7+
{
8+
using static Math;
9+
10+
[PluginName("TabletDriver Smoothing Filter")]
11+
public class Smoothing : IFilter
12+
{
13+
private DateTime? _lastFilterTime;
14+
private Vector2 _lastPos;
15+
private float _timerInterval;
16+
private const float _threshold = 0.63f;
17+
18+
public Vector2 Filter(Vector2 point)
19+
{
20+
var timeDelta = DateTime.Now - _lastFilterTime;
21+
// If a time difference hasn't been established or it has been 100 milliseconds since the last filter
22+
if (timeDelta == null || timeDelta.Value.TotalMilliseconds > 100 || _lastPos == null)
23+
{
24+
SetPreviousState(point);
25+
return point;
26+
}
27+
else
28+
{
29+
Vector2 pos = new Vector2(_lastPos.X, _lastPos.Y);
30+
float deltaX = point.X - _lastPos.X;
31+
float deltaY = point.Y - _lastPos.Y;
32+
33+
double stepCount = Latency / TimerInterval;
34+
double target = 1 - _threshold;
35+
double weight = 1.0 - (1.0 / Pow(1.0 / target, 1.0 / stepCount));
36+
37+
pos.X += (float)(deltaX * weight);
38+
pos.Y += (float)(deltaY * weight);
39+
SetPreviousState(pos);
40+
return pos;
41+
}
42+
}
43+
44+
private void SetPreviousState(Vector2 lastPosition)
45+
{
46+
_lastPos = lastPosition;
47+
_lastFilterTime = DateTime.Now;
48+
}
49+
50+
public FilterStage FilterStage => FilterStage.PostTranspose;
51+
52+
[SliderProperty("Latency", 0f, 5f, 2f)]
53+
public float Latency { set; get; }
54+
55+
[UnitProperty("Timer Interval", "hz")]
56+
public float TimerInterval
57+
{
58+
set => _timerInterval = 1000f / value;
59+
get => _timerInterval;
60+
}
61+
}
62+
}

TabletDriverFilters.sln

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.26124.0
55
MinimumVisualStudioVersion = 15.0.26124.0
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TabletDriverFilters", "TabletDriverFilters\TabletDriverFilters.csproj", "{EBD5C9CA-5B65-40B9-8923-696819BEF243}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HawkuFilters", "HawkuFilters\HawkuFilters.csproj", "{EBD5C9CA-5B65-40B9-8923-696819BEF243}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevocubFilters", "DevocubFilters\DevocubFilters.csproj", "{7FE69139-B75B-44D8-8771-76FA8A8B5193}"
79
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -30,5 +32,17 @@ Global
3032
{EBD5C9CA-5B65-40B9-8923-696819BEF243}.Release|x64.Build.0 = Release|Any CPU
3133
{EBD5C9CA-5B65-40B9-8923-696819BEF243}.Release|x86.ActiveCfg = Release|Any CPU
3234
{EBD5C9CA-5B65-40B9-8923-696819BEF243}.Release|x86.Build.0 = Release|Any CPU
35+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Debug|Any CPU.Build.0 = Debug|Any CPU
37+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Debug|x64.ActiveCfg = Debug|Any CPU
38+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Debug|x64.Build.0 = Debug|Any CPU
39+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Debug|x86.ActiveCfg = Debug|Any CPU
40+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Debug|x86.Build.0 = Debug|Any CPU
41+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Release|Any CPU.ActiveCfg = Release|Any CPU
42+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Release|Any CPU.Build.0 = Release|Any CPU
43+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Release|x64.ActiveCfg = Release|Any CPU
44+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Release|x64.Build.0 = Release|Any CPU
45+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Release|x86.ActiveCfg = Release|Any CPU
46+
{7FE69139-B75B-44D8-8771-76FA8A8B5193}.Release|x86.Build.0 = Release|Any CPU
3347
EndGlobalSection
3448
EndGlobal

0 commit comments

Comments
 (0)