55
66namespace TabletDriverFilters . Devocub
77{
8- using static Math ;
8+ using static MathF ;
99
1010 [ PluginName ( "TabletDriver AntiChatter Filter" ) ]
1111 public class AntiChatter : IFilter
1212 {
1313 private Vector2 _lastPos ;
1414 private float _timerInterval ;
15- private const float _threshold = 0.63f ;
16- private float _latency ;
15+ private const float _threshold = 0.9f ;
16+ private float _latency = 2.0f ;
1717
1818 public Vector2 Filter ( Vector2 point )
1919 {
2020 Vector2 calcTarget = new Vector2 ( ) ;
21- double deltaX , deltaY , distance , weightModifier , predictionModifier ;
21+ float deltaX , deltaY , distance , weightModifier , predictionModifier ;
2222
2323 if ( _lastPos == null )
2424 {
@@ -60,9 +60,9 @@ public Vector2 Filter(Vector2 point)
6060 deltaY = calcTarget . Y - _lastPos . Y ;
6161 distance = Sqrt ( deltaX * deltaX + deltaY * deltaY ) ;
6262
63- double stepCount = Latency / TimerInterval ;
64- double target = 1 - _threshold ;
65- double weight = 1.0 - ( 1.0 / Pow ( 1.0 / target , 1.0 / stepCount ) ) ;
63+ float stepCount = Latency / TimerInterval ;
64+ float target = 1 - _threshold ;
65+ float weight = ( float ) ( 1.0 - ( 1.0 / Pow ( ( float ) ( 1.0 / target ) , ( float ) ( 1.0 / stepCount ) ) ) ) ;
6666
6767 // Devocub smoothing
6868 // Increase weight of filter in {formula} times
@@ -75,12 +75,10 @@ public Vector2 Filter(Vector2 point)
7575 weightModifier += AntichatterOffsetY ;
7676
7777 weightModifier = weight / weightModifier ;
78- weightModifier = Clamp ( weightModifier , 0 , 1 ) ;
78+ weightModifier = Math . Clamp ( weightModifier , 0 , 1 ) ;
7979 _lastPos . X += ( float ) ( deltaX * weightModifier ) ;
8080 _lastPos . Y += ( float ) ( deltaY * weightModifier ) ;
8181
82- // OTDPlugin 0.3.2 feature
83- // OpenTabletDriver.Plugin.Log.Write("Antichatter", $"orig: ({point}) new: ({_lastPos}) dist: ({point.DistanceFrom(_lastPos)})", LogLevel.Debug);
8482 return _lastPos ;
8583 }
8684
@@ -89,11 +87,11 @@ public Vector2 Filter(Vector2 point)
8987 [ SliderProperty ( "Latency" , 0f , 5f , 2f ) ]
9088 public float Latency
9189 {
92- set => _latency = Clamp ( value , 0 , 1000 ) ;
90+ set => _latency = Math . Clamp ( value , 0 , 1000 ) ;
9391 get => _latency ;
9492 }
9593
96- [ UnitProperty ( "Timer Interval" , "hz" ) ]
94+ [ Property ( "Timer Interval" ) , Unit ( "hz" ) ]
9795 public float TimerInterval
9896 {
9997 set => _timerInterval = 1000f / value ;
@@ -110,7 +108,7 @@ public float TimerInterval
110108 public float AntichatterOffsetX { set ; get ; }
111109
112110 [ Property ( "Antichatter Offset Y" ) ]
113- public float AntichatterOffsetY { set ; get ; }
111+ public float AntichatterOffsetY { set ; get ; } = 1 ;
114112
115113 [ BooleanProperty ( "Prediction" , "" ) ]
116114 public bool PredictionEnabled { set ; get ; }
0 commit comments