Skip to content

Commit

Permalink
Optimized Engine
Browse files Browse the repository at this point in the history
Engine no longer bothers moving the mouse if the vector is nothing
  • Loading branch information
chaorace committed Aug 4, 2015
1 parent 422bed5 commit 2411ea7
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/main/java/Engine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@ class Engine(pollingRate: Option[Double], startupThreshold: Option[Double], give
}
//If last polled mouse movement was insignificant
}else{
//Move the mouse according to the last trackball speed
robot.mouseMove((endPos.x + lastVector.x).toInt, (endPos.y + lastVector.y).toInt)
//Apply friction to trackball
lastVector = new Vector2D(lastVector.x * drag.getOrElse(.98), lastVector.y * drag.getOrElse(.98))
//If the trackball is almost stopped, stop it
if(lastVector.almostEquals(noVector, 2)){
lastVector = noVector
//Only bother if there's a vector to move the mouse along
if(lastVector != noVector){
//Move the mouse according to the last trackball speed
robot.mouseMove((endPos.x + lastVector.x).toInt, (endPos.y + lastVector.y).toInt)
//Apply friction to trackball
lastVector = new Vector2D(lastVector.x * drag.getOrElse(.98), lastVector.y * drag.getOrElse(.98))
//If the trackball is almost stopped, stop it
if(lastVector.almostEquals(noVector, 2)){
lastVector = noVector
}
}
}
}
Expand Down

0 comments on commit 2411ea7

Please sign in to comment.