Created
September 30, 2015 08:26
-
-
Save kbinani/d3999829aad7772f4e9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void mouseBezierPath(Point<int> p0, Point<int> p1, Point<int> p2, Point<int> p3) | |
{ | |
double const length = p1.getDistanceFrom(p0) + p2.getDistanceFrom(p1) + p3.getDistanceFrom(p2); | |
double const kMouseSpeed = 2000; // pixel/second | |
double const kInterval = 0.0001; // second | |
int const numDiv = std::max(1, static_cast<int>(length / kMouseSpeed / kInterval)); | |
for (int i = 0; i <= numDiv; ++i) { | |
double const t = i / double(numDiv); | |
Point<int> p = (((-p0 + (p1 - p2) * 3 + p3) * t + (p0 - p1 * 2 + p2) * 3) * t + (p1 - p0) * 3) * t + p0; | |
Desktop::setMousePosition(p); | |
std::this_thread::sleep_for(std::chrono::nanoseconds(static_cast<int>(kInterval * 1e9))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment