Skip to content

Instantly share code, notes, and snippets.

@mharju
Last active December 11, 2015 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mharju/4538988 to your computer and use it in GitHub Desktop.
Save mharju/4538988 to your computer and use it in GitHub Desktop.
what the....
double direction_x = 0.0, direction_y = 0.0, direction = 0.0;
CGPoint d = CGPointMake(current.x - previous.x, current.y - previous.y);
if(d.x != 0) {
if(current.y <= kCenterY) {
if(d.x > 0.0) {
direction_x = 1.0;
} else {
direction_x = -1.0;
}
} else {
if(d.x > 0.0) {
direction_x = -1.0;
} else {
direction_x = 1.0;
}
}
}
if(d.y != 0) {
if(current.x <= kCenterX) {
if(d.y > 0.0) {
direction_y = -1.0;
} else {
direction_y = 1.0;
}
} else {
if(d.y > 0.0) {
direction_y = 1.0;
} else {
direction_y = -1.0;
}
}
}
direction = abs(current.y - kCenterY) > abs(current.x - kCenterX) ? direction_x : direction_y;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment