Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
fixes #33: rotate around arbitrary point
Browse files Browse the repository at this point in the history
  • Loading branch information
incanus committed Feb 4, 2014
1 parent e00efd5 commit dbea793
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/llmr/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Map {

/* rotation */
void rotateBy(double cx, double cy, double sx, double sy, double ex, double ey);
void setAngle(double angle);
void setAngle(double angle, double cx = -1, double cy = -1);
double getAngle() const;
void resetNorth();

Expand Down
2 changes: 1 addition & 1 deletion ios/MBXViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ - (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate
}
else if (rotate.state == UIGestureRecognizerStateChanged)
{
mapView->map.setAngle(self.angle + rotate.rotation);
mapView->map.setAngle(self.angle + rotate.rotation, [rotate locationInView:rotate.view].x, [rotate locationInView:rotate.view].y);
}
}

Expand Down
16 changes: 15 additions & 1 deletion src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,24 @@ void Map::setScale(double scale) {
settings.save();
}

void Map::setAngle(double angle) {
void Map::setAngle(double angle, double x, double y) {
double dx, dy;

if (x >= 0 && y >= 0) {
dx = (transform.width / 2) - x;
dy = (transform.height / 2) - y;
transform.moveBy(dx, dy);
}

transform.setAngle(angle);

if (x >= 0 && y >= 0) {
transform.moveBy(-dx, -dy);
}

update();

transform.getLonLat(settings.longitude, settings.latitude);
settings.angle = transform.getAngle();
settings.save();
}
Expand Down

0 comments on commit dbea793

Please sign in to comment.