Skip to content

Commit

Permalink
interpolate fov in easeTo and flyTo, and limit FOV
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanMOlson committed Nov 13, 2024
1 parent c150fd6 commit 8d06c07
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/mbgl/map/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
startLatLng.unwrapForShortestPath(latLng);
}
}
const double startCenterAlt = state.getCenterAltitude();

const Point<double> startPoint = Projection::project(startLatLng, state.getScale());
const Point<double> endPoint = Projection::project(latLng, state.getScale());

// Constrain camera options.
zoom = util::clamp(zoom, state.getMinZoom(), state.getMaxZoom());
pitch = util::clamp(pitch, state.getMinPitch(), state.getMaxPitch());
fov = util::clamp(fov, state.getMinFieldOfView(), state.getMaxFieldOfView());

// Minimize rotation by taking the shorter path around the circle.
bearing = _normalizeAngle(bearing, state.getBearing());
Expand All @@ -139,7 +141,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
const double startZoom = state.getZoom();
const double startBearing = state.getBearing();
const double startPitch = state.getPitch();
const double startCenterAlt = state.getCenterAltitude();
const double startFov = state.getFieldOfView();
state.setProperties(TransformStateProperties()
.withPanningInProgress(unwrappedLatLng != startLatLng)
.withScalingInProgress(zoom != startZoom)
Expand Down Expand Up @@ -169,7 +171,9 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
if (pitch != startPitch) {
state.setPitch(util::interpolate(startPitch, pitch, t));
}
state.setFieldOfView(fov);
if (fov != startFov) {
state.setFieldOfView(util::interpolate(startFov, fov, t));
}
state.setRoll(roll);
},
duration);
Expand All @@ -190,6 +194,7 @@ void Transform::flyTo(const CameraOptions& camera, const AnimationOptions& anima
double zoom = camera.zoom.value_or(getZoom());
double bearing = camera.bearing ? util::deg2rad(-*camera.bearing) : getBearing();
double pitch = camera.pitch ? util::deg2rad(*camera.pitch) : getPitch();
double fov = camera.fov ? util::deg2rad(*camera.fov) : getFieldOfView();

if (std::isnan(zoom) || std::isnan(bearing) || std::isnan(pitch) || state.getSize().isEmpty()) {
if (animation.transitionFinishFn) {
Expand All @@ -209,13 +214,15 @@ void Transform::flyTo(const CameraOptions& camera, const AnimationOptions& anima
// Constrain camera options.
zoom = util::clamp(zoom, state.getMinZoom(), state.getMaxZoom());
pitch = util::clamp(pitch, state.getMinPitch(), state.getMaxPitch());
fov = util::clamp(fov, state.getMinFieldOfView(), state.getMaxFieldOfView());

// Minimize rotation by taking the shorter path around the circle.
bearing = _normalizeAngle(bearing, state.getBearing());
state.setBearing(_normalizeAngle(state.getBearing(), bearing));
const double startZoom = state.scaleZoom(state.getScale());
const double startBearing = state.getBearing();
const double startPitch = state.getPitch();
const double startFov = state.getFieldOfView();

/// w₀: Initial visible span, measured in pixels at the initial scale.
/// Known henceforth as a <i>screenful</i>.
Expand Down Expand Up @@ -345,6 +352,9 @@ void Transform::flyTo(const CameraOptions& camera, const AnimationOptions& anima
if (pitch != startPitch) {
state.setPitch(util::interpolate(startPitch, pitch, k));
}
if (fov != startFov) {
state.setFieldOfView(util::interpolate(startFov, fov, k));
}
},
duration);
}
Expand Down
8 changes: 8 additions & 0 deletions src/mbgl/map/transform_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,14 @@ double TransformState::getMaxPitch() const {
return maxPitch;
}

double TransformState::getMinFieldOfView() const {
return minFov;
}

double TransformState::getMaxFieldOfView() const {
return maxFov;
}

// MARK: - Scale
double TransformState::getScale() const {
return scale;
Expand Down
4 changes: 4 additions & 0 deletions src/mbgl/map/transform_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class TransformState {
double getMinPitch() const;
void setMaxPitch(double);
double getMaxPitch() const;
double getMinFieldOfView() const;
double getMaxFieldOfView() const;

// Rotation
double getBearing() const;
Expand Down Expand Up @@ -260,6 +262,8 @@ class TransformState {
// Limit the amount of pitch
double minPitch = util::PITCH_MIN;
double maxPitch = util::PITCH_MAX;
double minFov = util::deg2rad(0.1);
double maxFov = util::deg2rad(150.0);

NorthOrientation orientation = NorthOrientation::Upwards;

Expand Down

0 comments on commit 8d06c07

Please sign in to comment.