summaryrefslogtreecommitdiff
path: root/src/mbgl/map/transform_state.cpp
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2016-12-14 15:17:01 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-12-21 15:46:36 -0800
commit38b5cb0c7766152f7e49cce8bd6c5d3e04dd0663 (patch)
tree9f64568fbe56a17a0c1fcd5396bf6c9e80992843 /src/mbgl/map/transform_state.cpp
parentebd241363d5c926d471559208f391190666febb9 (diff)
downloadqtlocation-mapboxgl-38b5cb0c7766152f7e49cce8bd6c5d3e04dd0663.tar.gz
[core, ios] replace `altitude` with `fov`
ported from -js: eb6c6596c6a7a61363d30356674e0002153b1d19 `altitude` was a terribly-named variable that was used to indirectly control the fov. This should eliminate some confusion. `altitude` was equivalent to `cameraToCenterDistance / height`
Diffstat (limited to 'src/mbgl/map/transform_state.cpp')
-rw-r--r--src/mbgl/map/transform_state.cpp34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index 59ae129518..51ecf52e40 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -27,22 +27,24 @@ void TransformState::matrixFor(mat4& matrix, const UnwrappedTileID& tileID) cons
}
void TransformState::getProjMatrix(mat4& projMatrix) const {
- double halfFov = std::atan(0.5 / getAltitude());
- double topHalfSurfaceDistance = std::sin(halfFov) * getAltitude() /
- std::sin(M_PI / 2.0f - getPitch() - halfFov);
- // Calculate z value of the farthest fragment that should be rendered.
- double farZ = std::cos(M_PI / 2.0f - getPitch()) * topHalfSurfaceDistance + getAltitude();
- matrix::perspective(projMatrix, 2.0f * std::atan((size.height / 2.0f) / getAltitude()),
- double(size.width) / size.height, 0.1, farZ);
+ // Find the distance from the center point [width/2, height/2] to the
+ // center top point [width/2, 0] in Z units, using the law of sines.
+ // 1 Z unit is equivalent to 1 horizontal px at the center of the map
+ // (the distance between[width/2, height/2] and [width/2 + 1, height/2])
+ const double halfFov = getFieldOfView() / 2.0;
+ const double groundAngle = M_PI / 2.0 + getPitch();
+ const double topHalfSurfaceDistance = std::sin(halfFov) * getCameraToCenterDistance() / std::sin(M_PI - groundAngle - halfFov);
+
+ // Calculate z value of the farthest fragment that should be rendered.
+ const double farZ = std::cos(M_PI / 2.0 - getPitch()) * topHalfSurfaceDistance + getCameraToCenterDistance();
- matrix::translate(projMatrix, projMatrix, 0, 0, -getAltitude());
+ matrix::perspective(projMatrix, getFieldOfView(), double(size.width) / size.height, 0.1, farZ);
- // After the rotateX, z values are in pixel units. Convert them to
- // altitude unites. 1 altitude unit = the screen height.
const bool flippedY = viewportMode == ViewportMode::FlippedY;
- matrix::scale(projMatrix, projMatrix, 1, flippedY ? 1 : -1,
- 1.0f / (rotatedNorth() ? size.width : size.height));
+ matrix::scale(projMatrix, projMatrix, 1, flippedY ? 1 : -1, 1);
+
+ matrix::translate(projMatrix, projMatrix, 0, 0, -getCameraToCenterDistance());
using NO = NorthOrientation;
switch (getNorthOrientation()) {
@@ -164,8 +166,12 @@ float TransformState::getAngle() const {
return angle;
}
-float TransformState::getAltitude() const {
- return altitude;
+float TransformState::getFieldOfView() const {
+ return fov;
+}
+
+float TransformState::getCameraToCenterDistance() const {
+ return 0.5 * size.height / std::tan(fov / 2.0);
}
float TransformState::getPitch() const {