@@ -12,29 +12,30 @@ public class TabletFilterSmoothing : IFilter
1212 {
1313 private DateTime ? _lastFilterTime ;
1414 private Point _lastPos ;
15-
15+ private float _timerInterval ;
16+ public float _threshold = 0.63f ;
1617 public Point Filter ( Point point )
1718 {
1819 var timeDelta = DateTime . Now - _lastFilterTime ;
1920 // If a time difference hasn't been established or it has been 100 milliseconds since the last filter
20- if ( timeDelta == null || timeDelta . Value . TotalMilliseconds > 100 )
21+ if ( timeDelta == null || timeDelta . Value . TotalMilliseconds > 100 || _lastPos == null )
2122 {
2223 SetPreviousState ( point ) ;
2324 return point ;
2425 }
2526 else
2627 {
27- Point pos = new Point ( point . X , point . Y ) ;
28+ Point pos = new Point ( _lastPos . X , _lastPos . Y ) ;
2829 float deltaX = point . X - _lastPos . X ;
2930 float deltaY = point . Y - _lastPos . Y ;
3031
31- float stepCount = Latency / TimerInterval ;
32- float target = 1 - Threshold ;
33- float weight = 1f - ( 1f / ( float ) Pow ( 1 / target , 1 / stepCount ) ) ;
32+ double stepCount = Latency / TimerInterval ;
33+ double target = 1 - _threshold ;
34+ double weight = 1.0 - ( 1.0 / Pow ( 1.0 / target , 1.0 / stepCount ) ) ;
3435
35- pos . X += deltaX * weight ;
36- pos . Y += deltaY * weight ;
37- SetPreviousState ( point ) ;
36+ pos . X += ( float ) ( deltaX * weight ) ;
37+ pos . Y += ( float ) ( deltaY * weight ) ;
38+ SetPreviousState ( pos ) ;
3839 return pos ;
3940 }
4041 }
@@ -45,18 +46,16 @@ private void SetPreviousState(Point lastPosition)
4546 _lastFilterTime = DateTime . Now ;
4647 }
4748
48- public FilterStage FilterStage => FilterStage . PreTranspose ;
49+ public FilterStage FilterStage => FilterStage . PostTranspose ;
4950
5051 [ SliderProperty ( "Latency" , 0f , 5f , 2f ) ]
5152 public float Latency { set ; get ; }
5253
53- [ SliderProperty ( "Weight" , 0f , 1f , 1f ) ]
54- public float Weight { set ; get ; }
55-
56- [ SliderProperty ( "Threshold" , 0f , 1f , 0.9f ) ]
57- public float Threshold { set ; get ; }
58-
5954 [ UnitProperty ( "Timer Interval" , "hz" ) ]
60- public float TimerInterval { set ; get ; }
55+ public float TimerInterval
56+ {
57+ set => _timerInterval = 1000f / value ;
58+ get => _timerInterval ;
59+ }
6160 }
6261}
0 commit comments