Skip to content
Snippets Groups Projects
Commit 0557c37d authored by simon's avatar simon
Browse files

simplify joysticks.PositionFromVelocity

parent 41305524
No related branches found
No related tags found
No related merge requests found
...@@ -276,22 +276,17 @@ func PositionFromVelocity(c chan Event) chan Event{ ...@@ -276,22 +276,17 @@ func PositionFromVelocity(c chan Event) chan Event{
extra := make(chan Event) extra := make(chan Event)
go func(){ go func(){
var x,y float32 var x,y float32
var lt time.Duration e:= <-c
for e:=range c{ lm:=e.Moment()
if ce,ok:= e.(CoordsEvent);ok{
lt=ce.Moment()
break
}
}
for e:=range c{ for e:=range c{
m:=e.Moment()
if ce,ok:=e.(CoordsEvent);ok{ if ce,ok:=e.(CoordsEvent);ok{
dt:=(ce.Moment()-lt).Seconds() dt:=(m-lm).Seconds()
if dt>0 { if dt>0 {
x+=float32(float64(ce.X)/dt) x+=float32(float64(ce.X)/dt)
y+=float32(float64(ce.Y)/dt) y+=float32(float64(ce.Y)/dt)
lt= ce.Moment() extra <-CoordsEvent{when{m},x,y}
extra <-CoordsEvent{when{e.Moment()},x,y} lm= m
lt= ce.Moment()
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment