diff options
Diffstat (limited to 'src/mbgl/map')
-rw-r--r-- | src/mbgl/map/map.cpp | 16 | ||||
-rw-r--r-- | src/mbgl/map/transform.cpp | 48 | ||||
-rw-r--r-- | src/mbgl/map/transform.hpp | 24 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.cpp | 16 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.hpp | 6 |
5 files changed, 58 insertions, 52 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 923421b54d..433a76e1ca 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -308,7 +308,7 @@ LatLng Map::getLatLng(const EdgeInsets& padding) const { void Map::resetPosition(const EdgeInsets& padding) { impl->cameraMutated = true; CameraOptions camera; - camera.angle = 0; + camera.bearing = 0; camera.pitch = 0; camera.center = LatLng(0, 0); camera.padding = padding; @@ -423,8 +423,8 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const Ed Transform transform(impl->transform.getState()); if (bearing) { - double angle = -*bearing * util::DEG2RAD; // Convert to radians - transform.setAngle(angle); + double bearingAsRadians = -*bearing * util::DEG2RAD; // Convert to radians + transform.setBearing(bearingAsRadians); } if (pitch) { double pitchAsRadian = *pitch * util::DEG2RAD; // Convert to radians @@ -432,7 +432,7 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const Ed } CameraOptions options = mbgl::cameraForLatLngs(latLngs, transform, padding); - options.angle = transform.getAngle(); + options.bearing = transform.getBearing(); options.pitch = transform.getPitch(); return options; @@ -545,23 +545,23 @@ void Map::setBearing(double degrees, const AnimationOptions& animation) { void Map::setBearing(double degrees, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) { impl->cameraMutated = true; - impl->transform.setAngle(-degrees * util::DEG2RAD, anchor, animation); + impl->transform.setBearing(-degrees * util::DEG2RAD, anchor, animation); impl->onUpdate(); } void Map::setBearing(double degrees, const EdgeInsets& padding, const AnimationOptions& animation) { impl->cameraMutated = true; - impl->transform.setAngle(-degrees * util::DEG2RAD, padding, animation); + impl->transform.setBearing(-degrees * util::DEG2RAD, padding, animation); impl->onUpdate(); } double Map::getBearing() const { - return -impl->transform.getAngle() * util::RAD2DEG; + return -impl->transform.getBearing() * util::RAD2DEG; } void Map::resetNorth(const AnimationOptions& animation) { impl->cameraMutated = true; - impl->transform.setAngle(0, animation); + impl->transform.setBearing(0, animation); impl->onUpdate(); } diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 99dc277882..213204e176 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -68,7 +68,7 @@ CameraOptions Transform::getCameraOptions(const EdgeInsets& padding) const { camera.center = getLatLng(padding); camera.padding = padding; camera.zoom = getZoom(); - camera.angle = getAngle(); + camera.bearing = getBearing(); camera.pitch = getPitch(); return camera; } @@ -91,7 +91,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim const LatLng unwrappedLatLng = camera.center.value_or(getLatLng()); const LatLng latLng = unwrappedLatLng.wrapped(); double zoom = camera.zoom.value_or(getZoom()); - double angle = camera.angle.value_or(getAngle()); + double bearing = camera.bearing.value_or(getBearing()); double pitch = camera.pitch.value_or(getPitch()); if (std::isnan(zoom)) { @@ -122,15 +122,15 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim pitch = util::clamp(pitch, state.min_pitch, state.max_pitch); // Minimize rotation by taking the shorter path around the circle. - angle = _normalizeAngle(angle, state.angle); - state.angle = _normalizeAngle(state.angle, angle); + bearing = _normalizeAngle(bearing, state.getBearing()); + state.setBearing(_normalizeAngle(state.getBearing(), bearing)); Duration duration = animation.duration ? *animation.duration : Duration::zero(); const double startScale = state.scale; - const double startAngle = state.angle; + const double startBearing = state.getBearing(); const double startPitch = state.pitch; - state.setTransitionInProgress(latLng != startLatLng || scale != startScale || angle != startAngle); + state.setTransitionInProgress(latLng != startLatLng || scale != startScale || bearing != startBearing); startTransition(camera, animation, [=](double t) { Point<double> framePoint = util::interpolate(startPoint, endPoint, t); @@ -138,8 +138,8 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim double frameScale = util::interpolate(startScale, scale, t); state.setLatLngZoom(frameLatLng, state.scaleZoom(frameScale)); - if (angle != startAngle) { - state.angle = util::wrap(util::interpolate(startAngle, angle, t), -M_PI, M_PI); + if (bearing != startBearing) { + state.setBearing(util::wrap(util::interpolate(startBearing, bearing, t), -M_PI, M_PI)); } if (pitch != startPitch) { state.pitch = util::interpolate(startPitch, pitch, t); @@ -162,7 +162,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &animation) { const LatLng latLng = camera.center.value_or(getLatLng()).wrapped(); double zoom = camera.zoom.value_or(getZoom()); - double angle = camera.angle.value_or(getAngle()); + double bearing = camera.bearing.value_or(getBearing()); double pitch = camera.pitch.value_or(getPitch()); if (std::isnan(zoom) || state.size.isEmpty()) { @@ -185,11 +185,11 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima pitch = util::clamp(pitch, state.min_pitch, state.max_pitch); // Minimize rotation by taking the shorter path around the circle. - angle = _normalizeAngle(angle, state.angle); - state.angle = _normalizeAngle(state.angle, angle); + bearing = _normalizeAngle(bearing, state.getBearing()); + state.setBearing(_normalizeAngle(state.getBearing(), bearing)); const double startZoom = state.scaleZoom(state.scale); - const double startAngle = state.angle; + const double startBearing= state.getBearing(); const double startPitch = state.pitch; /// w₀: Initial visible span, measured in pixels at the initial scale. @@ -297,8 +297,8 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima LatLng frameLatLng = Projection::unproject(framePoint, startScale); state.setLatLngZoom(frameLatLng, frameZoom); - if (angle != startAngle) { - state.angle = util::wrap(util::interpolate(startAngle, angle, k), -M_PI, M_PI); + if (bearing != startBearing) { + state.setBearing(util::wrap(util::interpolate(startBearing, bearing, k), -M_PI, M_PI)); } if (pitch != startPitch) { state.pitch = util::interpolate(startPitch, pitch, k); @@ -447,30 +447,30 @@ void Transform::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& } CameraOptions camera; - camera.angle = state.angle + util::angle_between(first - center, second - center); + camera.bearing = state.getBearing() + util::angle_between(first - center, second - center); easeTo(camera, animation); } -void Transform::setAngle(double angle, const AnimationOptions& animation) { - setAngle(angle, optional<ScreenCoordinate> {}, animation); +void Transform::setBearing(double bearing, const AnimationOptions& animation) { + setBearing(bearing, optional<ScreenCoordinate> {}, animation); } -void Transform::setAngle(double angle, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) { - if (std::isnan(angle)) return; +void Transform::setBearing(double bearing, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) { + if (std::isnan(bearing)) return; CameraOptions camera; - camera.angle = angle; + camera.bearing = bearing; camera.anchor = anchor; easeTo(camera, animation); } -void Transform::setAngle(double angle, const EdgeInsets& padding, const AnimationOptions& animation) { +void Transform::setBearing(double bearing, const EdgeInsets& padding, const AnimationOptions& animation) { optional<ScreenCoordinate> anchor; if (!padding.isFlush()) anchor = getScreenCoordinate(padding); - setAngle(angle, anchor, animation); + setBearing(bearing, anchor, animation); } -double Transform::getAngle() const { - return state.angle; +double Transform::getBearing() const { + return state.getBearing(); } #pragma mark - Pitch diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp index 145fc541d0..8155b628e2 100644 --- a/src/mbgl/map/transform.hpp +++ b/src/mbgl/map/transform.hpp @@ -82,24 +82,24 @@ public: // Angle void rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const AnimationOptions& = {}); - /** Sets the angle of rotation. - @param angle The new angle of rotation, measured in radians + /** Sets the bearing angle. + @param angle The new bearing angle, measured in radians counterclockwise from true north. */ - void setAngle(double angle, const AnimationOptions& = {}); - /** Sets the angle of rotation, keeping the given point fixed within the view. - @param angle The new angle of rotation, measured in radians + void setBearing(double angle, const AnimationOptions& = {}); + /** Sets the bearing angle, keeping the given point fixed within the view. + @param angle The new bearing angle, measured in radians counterclockwise from true north. @param anchor A point relative to the top-left corner of the view. */ - void setAngle(double angle, optional<ScreenCoordinate> anchor, const AnimationOptions& = {}); - /** Sets the angle of rotation, keeping the center point fixed within the inset view. - @param angle The new angle of rotation, measured in radians + void setBearing(double bearing, optional<ScreenCoordinate> anchor, const AnimationOptions& = {}); + /** Sets the bearing angle, keeping the center point fixed within the inset view. + @param angle The new bearing angle, measured in radians counterclockwise from true north. @param padding The viewport padding that affects the fixed center point. */ - void setAngle(double angle, const EdgeInsets& padding, const AnimationOptions& = {}); - /** Returns the angle of rotation. - @return The angle of rotation, measured in radians counterclockwise from + void setBearing(double bearing, const EdgeInsets& padding, const AnimationOptions& = {}); + /** Returns the bearing angle. + @return The bearing angle, measured in radians counterclockwise from true north. */ - double getAngle() const; + double getBearing() const; // Pitch /** Sets the pitch angle. diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index ff9bcb05e5..360658fa71 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -61,7 +61,7 @@ void TransformState::getProjMatrix(mat4& projMatrix, uint16_t nearZ, bool aligne default: matrix::rotate_x(projMatrix, projMatrix, getPitch()); break; } - matrix::rotate_z(projMatrix, projMatrix, getAngle() + getNorthOrientationAngle()); + matrix::rotate_z(projMatrix, projMatrix, getBearing() + getNorthOrientationAngle()); const double dx = pixel_x() - size.width / 2.0f, dy = pixel_y() - size.height / 2.0f; matrix::translate(projMatrix, projMatrix, dx, dy, 0); @@ -86,10 +86,10 @@ void TransformState::getProjMatrix(mat4& projMatrix, uint16_t nearZ, bool aligne // it is always <= 0.5 pixels. if (aligned) { const float xShift = float(size.width % 2) / 2, yShift = float(size.height % 2) / 2; - const double angleCos = std::cos(angle), angleSin = std::sin(angle); + const double bearingCos = std::cos(bearing), bearingSin = std::sin(bearing); double devNull; - const float dxa = -std::modf(dx, &devNull) + angleCos * xShift + angleSin * yShift; - const float dya = -std::modf(dy, &devNull) + angleCos * yShift + angleSin * xShift; + const float dxa = -std::modf(dx, &devNull) + bearingCos * xShift + bearingSin * yShift; + const float dya = -std::modf(dy, &devNull) + bearingCos * yShift + bearingSin * xShift; matrix::translate(projMatrix, projMatrix, dxa > 0.5 ? dxa - 1 : dxa, dya > 0.5 ? dya - 1 : dya, 0); } } @@ -224,8 +224,12 @@ double TransformState::getMaxPitch() const { #pragma mark - Rotation -float TransformState::getAngle() const { - return angle; +float TransformState::getBearing() const { + return bearing; +} + +void TransformState::setBearing(double bearing_) { + bearing = bearing_; } float TransformState::getFieldOfView() const { diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp index a65363523d..c052aaa468 100644 --- a/src/mbgl/map/transform_state.hpp +++ b/src/mbgl/map/transform_state.hpp @@ -63,7 +63,9 @@ public: double getMaxPitch() const; // Rotation - float getAngle() const; + float getBearing() const; + void setBearing(double bearing); + float getFieldOfView() const; float getCameraToCenterDistance() const; float getPitch() const; @@ -127,7 +129,7 @@ private: // map position double x = 0, y = 0; - double angle = 0; + double bearing = 0; double scale = 1; // This fov value is somewhat arbitrary. The altitude of the camera used // to be defined as 1.5 screen heights above the ground, which was an |