Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
fix matrix z range and remove hack
Browse files Browse the repository at this point in the history
ported from -js: 0b5520fa5ab2a4659d80dcffa8b035a0d84fe1ca

This should fix the issue behind #2270 and remove the need for the hack
added in #3740.
  • Loading branch information
ansis committed Dec 15, 2016
1 parent b88fbe7 commit c2047c0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/mbgl/map/transform_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ void TransformState::getProjMatrix(mat4& projMatrix) const {
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::perspective(projMatrix, getFieldOfView(), double(size.width) / size.height, 0.1, farZ);
// Calculate z distance of the farthest fragment that should be rendered.
const double furthestDistance = std::cos(M_PI / 2 - getPitch()) * topHalfSurfaceDistance + getCameraToCenterDistance();
// Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`
const double farZ = furthestDistance * 1.01;

matrix::perspective(projMatrix, getFieldOfView(), double(size.width) / size.height, 1, farZ);

const bool flippedY = viewportMode == ViewportMode::FlippedY;
matrix::scale(projMatrix, projMatrix, 1, flippedY ? 1 : -1, 1);
Expand Down

0 comments on commit c2047c0

Please sign in to comment.