From 9f280a41c0f0509bf970019d40889c5f7f6f1008 Mon Sep 17 00:00:00 2001 From: Stephan Brandt Date: Mon, 27 Jan 2020 12:02:34 +0100 Subject: [PATCH] ViewController: allow rotation around map view center, fix drift (#764) --- vtm/src/org/oscim/map/ViewController.java | 27 +++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/vtm/src/org/oscim/map/ViewController.java b/vtm/src/org/oscim/map/ViewController.java index beddc15f..ac7ae9f5 100644 --- a/vtm/src/org/oscim/map/ViewController.java +++ b/vtm/src/org/oscim/map/ViewController.java @@ -1,9 +1,10 @@ /* * Copyright 2014 Hannes Janetzek - * Copyright 2016-2019 devemux86 + * Copyright 2016-2020 devemux86 * Copyright 2017 Luca Osten * Copyright 2018 Izumi Kawashima * Copyright 2018 Mathieu De Brito + * Copyright 2020 Stephan Brandt * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -225,18 +226,20 @@ public class ViewController extends Viewport { public void rotateMap(double radians, float pivotX, float pivotY) { ThreadUtils.assertMainThread(); - double rsin = Math.sin(radians); - double rcos = Math.cos(radians); - - pivotX -= mWidth * mPivotX; - pivotY -= mHeight * mPivotY; - - float x = (float) (pivotX - pivotX * rcos + pivotY * rsin); - float y = (float) (pivotY - pivotX * rsin - pivotY * rcos); - - moveMap(x, y); - setRotation(mPos.bearing + Math.toDegrees(radians)); + + if (pivotX != 0 && pivotY != 0) { + double rsin = Math.sin(radians); + double rcos = Math.cos(radians); + + pivotX -= mWidth * mPivotX; + pivotY -= mHeight * mPivotY; + + float x = (float) (pivotX - pivotX * rcos + pivotY * rsin); + float y = (float) (pivotY - pivotX * rsin - pivotY * rcos); + + moveMap(x, y); + } } public void setRotation(double degree) {