Graphics/AbstractViewer: Add ProjectDepth method

This commit is contained in:
Lynix
2018-05-29 23:55:51 +02:00
parent e46aa6772e
commit db0e3267da
3 changed files with 12 additions and 0 deletions

View File

@@ -34,6 +34,15 @@ namespace Nz
return screenPosition;
}
float AbstractViewer::ProjectDepth(float depth)
{
const Matrix4f& projectionMatrix = GetProjectionMatrix();
float a = projectionMatrix(2, 2);
float b = projectionMatrix(2, 3);
return (0.5f * (-a * depth + b) / depth + 0.5f);
}
Vector3f AbstractViewer::Unproject(const Nz::Vector3f& screenPos) const
{
Rectf viewport = Rectf(GetViewport());