Skip to content

Commit

Permalink
smoothen view direction in compass mode more (fixes #2465)
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Jan 8, 2021
1 parent 006ce44 commit 5df2040
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class Compass(
companion object {
private const val MAX_DISPATCH_FPS = 30
private const val SMOOTHEN_FACTOR = 0.1f
private const val MIN_DIFFERENCE = 0.005f
private const val MIN_DIFFERENCE = 0.001f
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ open class LocationAwareMapFragment : MapFragment() {
}
}
}
private var viewDirection: Float? = null

interface Listener {
/** Called after the map fragment updated its displayed location */
Expand Down Expand Up @@ -279,10 +280,21 @@ open class LocationAwareMapFragment : MapFragment() {
}

if (isCompassMode) {
controller?.updateCameraPosition { rotation = -rot }
viewDirection =
if (viewDirection == null) -rot
else smoothenAngle(-rot, viewDirection ?: 0f, 0.05f)

controller?.updateCameraPosition { rotation = viewDirection }
}
}

private fun smoothenAngle( newValue: Float, oldValue: Float, factor: Float): Float {
var delta = newValue - oldValue
while (delta > +PI) delta -= 2 * PI.toFloat()
while (delta < -PI) delta += 2 * PI.toFloat()
return oldValue + factor * delta
}

/* -------------------------------- Save and Restore State ---------------------------------- */

private fun restoreMapState() {
Expand Down

0 comments on commit 5df2040

Please sign in to comment.