Files
comaps/drape/utils/projection.cpp
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

35 lines
971 B
C++

#include "drape/utils/projection.hpp"
namespace dp
{
std::array<float, 16> MakeProjection(dp::ApiVersion apiVersion, float left, float right,
float bottom, float top)
{
std::array<float, 16> result = {};
// Projection matrix is calculated for [-1;1] depth-space, in some APIs (e.g. Metal)
// depth-space is [0;1], so we have to remap projection matrix.
float depthScale = 1.0f;
float depthOffset = 0.0f;
if (apiVersion == dp::ApiVersion::Metal)
{
depthScale = 0.5f;
depthOffset = 0.5f;
}
float const width = right - left;
float const height = top - bottom;
float const depth = kMaxDepth - kMinDepth;
result[0] = 2.0f / width;
result[3] = -(right + left) / width;
result[5] = 2.0f / height;
result[7] = -(top + bottom) / height;
result[10] = -2.0f * depthScale / depth;
result[11] = depthOffset - (kMaxDepth + kMinDepth) / depth;
result[15] = 1.0;
return result;
}
} // namespace dp