diff options
| author | Savely Skresanov <savask@yandex.ru> | 2012-08-04 11:39:40 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-04 12:52:22 (GMT) |
| commit | e06d8e4d15d957250079b7744784f0d2af883662 (patch) | |
| tree | 66564b6f3dcab932c88e907b30ad9fe1b53a9a7d /src/game/GameView.cpp | |
| parent | 929d99f80c7913677195e69235d99c0e954cf07d (diff) | |
| download | powder-e06d8e4d15d957250079b7744784f0d2af883662.zip powder-e06d8e4d15d957250079b7744784f0d2af883662.tar.gz | |
Rectangle snapping.
Diffstat (limited to 'src/game/GameView.cpp')
| -rw-r--r-- | src/game/GameView.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 838f733..f58b145 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -1553,5 +1553,10 @@ ui::Point GameView::lineSnapCoords(ui::Point point1, ui::Point point2) ui::Point GameView::rectSnapCoords(ui::Point point1, ui::Point point2) { - return point2; -}
\ No newline at end of file + ui::Point newPoint(0, 0); + float snapAngle = floor((atan2(point2.Y-point1.Y, point2.X-point1.X)+M_PI*0.25)/(M_PI*0.5)+0.5)*M_PI*0.5 - M_PI*0.25; + float lineMag = sqrtf(pow((float)(point2.X-point1.X),2)+pow((float)(point2.Y-point1.Y),2)); + newPoint.X = (int)(lineMag*cos(snapAngle)+point1.X+0.5f); + newPoint.Y = (int)(lineMag*sin(snapAngle)+point1.Y+0.5f); + return newPoint; +} |
