From c2d2737ca6c2d50737731ccf3331f1b9c42ee9cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 18 Jul 2016 23:36:24 +0200 Subject: [PATCH] Math: test and document Matrix4::*projection() harder. --- src/Magnum/Math/Matrix4.h | 8 ++++---- src/Magnum/Math/Test/Matrix4Test.cpp | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Magnum/Math/Matrix4.h b/src/Magnum/Math/Matrix4.h index 65dc49a60..9f391399e 100644 --- a/src/Magnum/Math/Matrix4.h +++ b/src/Magnum/Math/Matrix4.h @@ -193,8 +193,8 @@ template class Matrix4: public Matrix4x4 { /** * @brief 3D orthographic projection matrix * @param size Size of the view - * @param near Near clipping plane - * @param far Far clipping plane + * @param near Distance to near clipping plane, positive is ahead + * @param far Distance to far clipping plane, positive is ahead * * @see @ref perspectiveProjection(), @ref Matrix3::projection() */ @@ -203,8 +203,8 @@ template class Matrix4: public Matrix4x4 { /** * @brief 3D perspective projection matrix * @param size Size of near clipping plane - * @param near Near clipping plane - * @param far Far clipping plane + * @param near Distance to near clipping plane, positive is ahead + * @param far Distance to far clipping plane, positive is ahead * * @see @ref orthographicProjection(), @ref Matrix3::projection() */ diff --git a/src/Magnum/Math/Test/Matrix4Test.cpp b/src/Magnum/Math/Test/Matrix4Test.cpp index 3eac6154e..9bc4b44a2 100644 --- a/src/Magnum/Math/Test/Matrix4Test.cpp +++ b/src/Magnum/Math/Test/Matrix4Test.cpp @@ -384,7 +384,12 @@ void Matrix4Test::orthographicProjection() { {0.0f, 0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, -0.25f, 0.0f}, {0.0f, 0.0f, -1.25f, 1.0f}); - CORRADE_COMPARE(Matrix4::orthographicProjection({5.0f, 4.0f}, 1, 9), expected); + Matrix4 actual = Matrix4::orthographicProjection({5.0f, 4.0f}, 1.0f, 9.0f); + CORRADE_COMPARE(actual, expected); + + /* NDC is left-handed, so point on near plane should be -1, far +1 */ + CORRADE_COMPARE(actual.transformPoint({0.0f, 0.0f, -1.0f}), Vector3(0.0f, 0.0f, -1.0f)); + CORRADE_COMPARE(actual.transformPoint({0.0f, 0.0f, -9.0f}), Vector3(0.0f, 0.0f, +1.0f)); } void Matrix4Test::perspectiveProjection() { @@ -392,7 +397,12 @@ void Matrix4Test::perspectiveProjection() { {0.0f, 7.111111f, 0.0f, 0.0f}, {0.0f, 0.0f, -1.9411764f, -1.0f}, {0.0f, 0.0f, -94.1176452f, 0.0f}); - CORRADE_COMPARE(Matrix4::perspectiveProjection({16.0f, 9.0f}, 32.0f, 100), expected); + Matrix4 actual = Matrix4::perspectiveProjection({16.0f, 9.0f}, 32.0f, 100.0f); + CORRADE_COMPARE(actual, expected); + + /* NDC is left-handed, so point on near plane should be -1, far +1 */ + CORRADE_COMPARE(actual.transformPoint({0.0f, 0.0f, -32.0f}), Vector3(0.0f, 0.0f, -1.0f)); + CORRADE_COMPARE(actual.transformPoint({0.0f, 0.0f, -100.0f}), Vector3(0.0f, 0.0f, +1.0f)); } void Matrix4Test::perspectiveProjectionFov() {