Browse Source

Math: make Matrix3 and Matrix4 projection() APIs constexpr on C++14.

Except for the FoV-taking overload, which calls tan() inside, and which
is constexpr only on C++26, so likely not in all STL implementations
just yet. (And I don't have a CORRADE_CONSTEXPR26 macro yet either.)
next
Vladimír Vondruš 3 weeks ago
parent
commit
5a7424643b
  1. 4
      doc/changelog.dox
  2. 6
      src/Magnum/Math/Matrix3.h
  3. 26
      src/Magnum/Math/Matrix4.h
  4. 4
      src/Magnum/Math/Test/CMakeLists.txt
  5. 77
      src/Magnum/Math/Test/Matrix3Cpp14Test.cpp
  6. 4
      src/Magnum/Math/Test/Matrix3Test.cpp
  7. 157
      src/Magnum/Math/Test/Matrix4Cpp14Test.cpp
  8. 12
      src/Magnum/Math/Test/Matrix4Test.cpp

4
doc/changelog.dox

@ -822,6 +822,10 @@ See also:
8 digits for @ref Math::Color4) at compile time to prevent common errors
- All mutable getters in @ref Math classes are now marked as @cpp constexpr @ce
if compiling for C++14 and later. See also [mosra/magnum#597](https://github.com/mosra/magnum/pull/597).
- @ref Matrix3::projection(), @ref Matrix4::orthographicProjection() and
@ref Matrix4::perspectiveProjection() except for the FoV overload (which
calls a trig function inside) are now marked as @cpp constexpr @ce if
compiling for C++14 and later
@subsubsection changelog-latest-changes-meshtools MeshTools library

6
src/Magnum/Math/Matrix3.h

@ -229,7 +229,7 @@ template<class T> class Matrix3: public Matrix3x3<T> {
* @see @ref Matrix4::orthographicProjection(),
* @ref Matrix4::perspectiveProjection()
*/
static Matrix3<T> projection(const Vector2<T>& size) {
CORRADE_CONSTEXPR14 static Matrix3<T> projection(const Vector2<T>& size) {
return scaling(T(2.0)/size);
}
@ -256,7 +256,7 @@ template<class T> class Matrix3: public Matrix3x3<T> {
* @ref Matrix4::perspectiveProjection(const Vector2<T>&, const Vector2<T>&, T, T)
* @m_keywords{gluOrtho2D()}
*/
static Matrix3<T> projection(const Vector2<T>& bottomLeft, const Vector2<T>& topRight);
CORRADE_CONSTEXPR14 static Matrix3<T> projection(const Vector2<T>& bottomLeft, const Vector2<T>& topRight);
/**
* @brief Create a matrix from a rotation/scaling part and a translation part
@ -764,7 +764,7 @@ template<class T> Matrix3<T> Matrix3<T>::rotation(const Rad<T> angle) {
{ T(0), T(0), T(1)}};
}
template<class T> Matrix3<T> Matrix3<T>::projection(const Vector2<T>& bottomLeft, const Vector2<T>& topRight) {
template<class T> CORRADE_CONSTEXPR14 Matrix3<T> Matrix3<T>::projection(const Vector2<T>& bottomLeft, const Vector2<T>& topRight) {
const Vector2<T> difference = topRight - bottomLeft;
const Vector2<T> scale = T(2.0)/difference;
const Vector2<T> offset = (topRight + bottomLeft)/difference;

26
src/Magnum/Math/Matrix4.h

@ -356,7 +356,7 @@ template<class T> class Matrix4: public Matrix4x4<T> {
* @ref orthographicProjectionFar() const,
* @ref Matrix3::projection()
*/
static Matrix4<T> orthographicProjection(const Vector2<T>& size, T near, T far);
CORRADE_CONSTEXPR14 static Matrix4<T> orthographicProjection(const Vector2<T>& size, T near, T far);
/**
* @brief 3D off-center orthographic projection matrix
@ -388,7 +388,7 @@ template<class T> class Matrix4: public Matrix4x4<T> {
* @ref Matrix3::projection(const Vector2<T>&, const Vector2<T>&)
* @m_keywords{glOrtho()}
*/
static Matrix4<T> orthographicProjection(const Vector2<T>& bottomLeft, const Vector2<T>& topRight, T near, T far);
CORRADE_CONSTEXPR14 static Matrix4<T> orthographicProjection(const Vector2<T>& bottomLeft, const Vector2<T>& topRight, T near, T far);
/**
* @brief 3D perspective projection matrix
@ -423,7 +423,7 @@ template<class T> class Matrix4: public Matrix4x4<T> {
* @ref perspectiveProjectionFar() const,
* @ref Matrix3::projection(), @ref Constants::inf()
*/
static Matrix4<T> perspectiveProjection(const Vector2<T>& size, T near, T far);
CORRADE_CONSTEXPR14 static Matrix4<T> perspectiveProjection(const Vector2<T>& size, T near, T far);
/**
* @brief 3D perspective projection matrix
@ -515,7 +515,7 @@ template<class T> class Matrix4: public Matrix4x4<T> {
* @ref Matrix3::projection(), @ref Constants::inf()
* @m_keywords{glFrustum()}
*/
static Matrix4<T> perspectiveProjection(const Vector2<T>& bottomLeft, const Vector2<T>& topRight, T near, T far);
CORRADE_CONSTEXPR14 static Matrix4<T> perspectiveProjection(const Vector2<T>& bottomLeft, const Vector2<T>& topRight, T near, T far);
/**
* @brief Matrix oriented towards a specific point
@ -1278,7 +1278,7 @@ template<class T> Matrix4<T> Matrix4<T>::reflection(const Vector3<T>& normal) {
return from(Matrix3x3<T>() - T(2)*normal*RectangularMatrix<1, 3, T>(normal).transposed(), {});
}
template<class T> Matrix4<T> Matrix4<T>::orthographicProjection(const Vector2<T>& size, const T near, const T far) {
template<class T> CORRADE_CONSTEXPR14 Matrix4<T> Matrix4<T>::orthographicProjection(const Vector2<T>& size, const T near, const T far) {
const Vector2<T> xyScale = T(2.0)/size;
const T zScale = T(2.0)/(near-far);
@ -1288,7 +1288,7 @@ template<class T> Matrix4<T> Matrix4<T>::orthographicProjection(const Vector2<T>
{ T(0), T(0), near*zScale-T(1), T(1)}};
}
template<class T> Matrix4<T> Matrix4<T>::orthographicProjection(const Vector2<T>& bottomLeft, const Vector2<T>& topRight, const T near, const T far) {
template<class T> CORRADE_CONSTEXPR14 Matrix4<T> Matrix4<T>::orthographicProjection(const Vector2<T>& bottomLeft, const Vector2<T>& topRight, const T near, const T far) {
const Vector3<T> difference{topRight - bottomLeft, near - far};
const Vector3<T> scale = T(2.0)/difference;
const Vector3<T> offset = Vector3<T>{topRight + bottomLeft, near + far}/difference;
@ -1299,10 +1299,13 @@ template<class T> Matrix4<T> Matrix4<T>::orthographicProjection(const Vector2<T>
{-offset.x(), -offset.y(), offset.z(), T(1)}};
}
template<class T> Matrix4<T> Matrix4<T>::perspectiveProjection(const Vector2<T>& size, const T near, const T far) {
template<class T> CORRADE_CONSTEXPR14 Matrix4<T> Matrix4<T>::perspectiveProjection(const Vector2<T>& size, const T near, const T far) {
const Vector2<T> xyScale = 2*near/size;
T m22, m32;
/* These two have to be initialized on C++14 because otherwise GCC says
"error: uninitialized variable ‘m22’ in ‘constexpr’ context". Lol come
on... */
T m22{}, m32{};
if(far == Constants<T>::inf()) {
m22 = T(-1);
m32 = T(-2)*near;
@ -1318,12 +1321,15 @@ template<class T> Matrix4<T> Matrix4<T>::perspectiveProjection(const Vector2<T>&
{ T(0), T(0), m32, T(0)}};
}
template<class T> Matrix4<T> Matrix4<T>::perspectiveProjection(const Vector2<T>& bottomLeft, const Vector2<T>& topRight, const T near, const T far) {
template<class T> CORRADE_CONSTEXPR14 Matrix4<T> Matrix4<T>::perspectiveProjection(const Vector2<T>& bottomLeft, const Vector2<T>& topRight, const T near, const T far) {
const Vector2<T> xyDifference = topRight - bottomLeft;
const Vector2<T> xyScale = 2*near/xyDifference;
const Vector2<T> xyOffset = (topRight + bottomLeft)/xyDifference;
T m22, m32;
/* These two have to be initialized on C++14 because otherwise GCC says
"error: uninitialized variable ‘m22’ in ‘constexpr’ context". Lol come
on... */
T m22{}, m32{};
if(far == Constants<T>::inf()) {
m22 = T(-1);
m32 = T(-2)*near;

4
src/Magnum/Math/Test/CMakeLists.txt

@ -124,6 +124,8 @@ if(NOT CMAKE_CXX_FLAGS MATCHES "-std=")
corrade_add_test(MathCubicHermiteCpp14Test CubicHermiteCpp14Test.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathDualCpp14Test DualCpp14Test.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathFrustumCpp14Test FrustumCpp14Test.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathMatrix3Cpp14Test Matrix3Cpp14Test.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathMatrix4Cpp14Test Matrix4Cpp14Test.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathQuaternionCpp14Test QuaternionCpp14Test.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathRangeCpp14Test RangeCpp14Test.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathRectangularMatrixCpp14Test RectangularMatrixCpp14Test.cpp LIBRARIES MagnumMathTestLib)
@ -139,6 +141,8 @@ if(NOT CMAKE_CXX_FLAGS MATCHES "-std=")
MathCubicHermiteCpp14Test
MathDualCpp14Test
MathFrustumCpp14Test
MathMatrix3Cpp14Test
MathMatrix4Cpp14Test
MathQuaternionCpp14Test
MathRangeCpp14Test
MathRectangularMatrixCpp14Test

77
src/Magnum/Math/Test/Matrix3Cpp14Test.cpp

@ -0,0 +1,77 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020, 2021, 2022, 2023, 2024, 2025, 2026
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <Corrade/TestSuite/Tester.h>
#include "Magnum/Math/Matrix3.h"
namespace Magnum { namespace Math { namespace Test { namespace {
struct Matrix3Cpp14Test: TestSuite::Tester {
explicit Matrix3Cpp14Test();
void projectionConstexpr();
void projectionOffCenterConstexpr();
};
/* What's a typedef and not a using differs from the typedefs in root Magnum
namespace, or is not present there at all */
using Magnum::Matrix3;
using Magnum::Vector2;
Matrix3Cpp14Test::Matrix3Cpp14Test() {
addTests({&Matrix3Cpp14Test::projectionConstexpr,
&Matrix3Cpp14Test::projectionOffCenterConstexpr});
}
void Matrix3Cpp14Test::projectionConstexpr() {
/* Like Matrix3Test::projection(), but testing usability in a constexpr
context */
constexpr Matrix3 projection = Matrix3::projection({5.0f, 4.0f});
CORRADE_COMPARE(projection, (Matrix3{
{2.0f/5.0f, 0.0f, 0.0f},
{ 0.0f, 2.0f/4.0f, 0.0f},
{ 0.0f, 0.0f, 1.0f}}));
}
void Matrix3Cpp14Test::projectionOffCenterConstexpr() {
/* Like Matrix3Test::projectionOffCenter(), but testing usability in a
constexpr context */
constexpr Matrix3 projection = Matrix3::projection({-3.5f, -2.5f}, {1.5f, 1.5f});
CORRADE_COMPARE(projection, (Matrix3{
{0.4f, 0.0f, 0.0f},
{0.0f, 0.5f, 0.0f},
{0.4f, 0.25f, 1.0f}}));
CORRADE_COMPARE(projection.transformPoint({1.5f, 1.5f}), (Vector2{1.0f, 1.0f}));
CORRADE_COMPARE(projection.transformPoint({-3.5f, -2.5f}), (Vector2{-1.0f, -1.0f}));
}
}}}}
CORRADE_TEST_MAIN(Magnum::Math::Test::Matrix3Cpp14Test)

4
src/Magnum/Math/Test/Matrix3Test.cpp

@ -511,6 +511,8 @@ void Matrix3Test::shearingY() {
}
void Matrix3Test::projection() {
/* C++14 constexpr verified in Matrix3Cpp14Test, keep in sync */
CORRADE_COMPARE(Matrix3::projection({5.0f, 4.0f}), (Matrix3{
{2.0f/5.0f, 0.0f, 0.0f},
{ 0.0f, 2.0f/4.0f, 0.0f},
@ -518,6 +520,8 @@ void Matrix3Test::projection() {
}
void Matrix3Test::projectionOffCenter() {
/* C++14 constexpr verified in Matrix3Cpp14Test, keep in sync */
/* Shifted by (-1, -0.5) compared to the projection() test */
Matrix3 projection = Matrix3::projection({-3.5f, -2.5f}, {1.5f, 1.5f});
CORRADE_COMPARE(projection, (Matrix3{

157
src/Magnum/Math/Test/Matrix4Cpp14Test.cpp

@ -0,0 +1,157 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020, 2021, 2022, 2023, 2024, 2025, 2026
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <Corrade/TestSuite/Tester.h>
#include "Magnum/Math/Matrix4.h"
namespace Magnum { namespace Math { namespace Test { namespace {
struct Matrix4Cpp14Test: TestSuite::Tester {
explicit Matrix4Cpp14Test();
void orthographicProjectionConstexpr();
void orthographicProjectionOffCenterConstexpr();
void perspectiveProjectionConstexpr();
void perspectiveProjectionInfiniteFarConstexpr();
void perspectiveProjectionOffCenterConstexpr();
void perspectiveProjectionOffCenterInfiniteFarConstexpr();
/* The FoV variant of perspectiveProjection() uses trig functions that are
only constexpr since C++26, don't want to bother with that yet */
};
/* What's a typedef and not a using differs from the typedefs in root Magnum
namespace, or is not present there at all */
using Magnum::Constants;
using Magnum::Matrix4;
using Magnum::Vector3;
Matrix4Cpp14Test::Matrix4Cpp14Test() {
addTests({&Matrix4Cpp14Test::orthographicProjectionConstexpr,
&Matrix4Cpp14Test::orthographicProjectionOffCenterConstexpr,
&Matrix4Cpp14Test::perspectiveProjectionConstexpr,
&Matrix4Cpp14Test::perspectiveProjectionInfiniteFarConstexpr,
&Matrix4Cpp14Test::perspectiveProjectionOffCenterConstexpr,
&Matrix4Cpp14Test::perspectiveProjectionOffCenterInfiniteFarConstexpr});
}
void Matrix4Cpp14Test::orthographicProjectionConstexpr() {
/* Like Matrix4Test::orthographicProjection(), but testing usability in a
constexpr context */
constexpr Matrix4 actual = Matrix4::orthographicProjection({5.0f, 4.0f}, 1.0f, 9.0f);
CORRADE_COMPARE(actual, (Matrix4{
{0.4f, 0.0f, 0.0f, 0.0f},
{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(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 Matrix4Cpp14Test::orthographicProjectionOffCenterConstexpr() {
/* Like Matrix4Test::orthographicProjectionOffCenter(), but testing
usability in a constexpr context */
constexpr Matrix4 actual = Matrix4::orthographicProjection({-3.5f, -2.5f}, {1.5f, 1.5f}, 1.0f, 9.0f);
CORRADE_COMPARE(actual, (Matrix4{
{0.4f, 0.0f, 0.0f, 0.0f},
{0.0f, 0.5f, 0.0f, 0.0f},
{0.0f, 0.0f, -0.25f, 0.0f},
{0.4f, 0.25f, -1.25f, 1.0f}}));
CORRADE_COMPARE(actual.transformPoint({1.5f, 1.5f, -1.0f}), (Vector3{1.0f, 1.0f, -1.0f}));
CORRADE_COMPARE(actual.transformPoint({-3.5f, -2.5f, -9.0f}), (Vector3{-1.0f, -1.0f, +1.0f}));
}
void Matrix4Cpp14Test::perspectiveProjectionConstexpr() {
/* Like Matrix4Test::perspectiveProjection(), but testing usability in a
constexpr context */
Matrix4 expected{{4.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 7.111111f, 0.0f, 0.0f},
{0.0f, 0.0f, -1.9411764f, -1.0f},
{0.0f, 0.0f, -94.1176452f, 0.0f}};
constexpr Matrix4 actual = Matrix4::perspectiveProjection({16.0f, 9.0f}, 32.0f, 100.0f);
CORRADE_COMPARE(actual, expected);
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));
CORRADE_COMPARE(Matrix4::perspectiveProjection({-8.0f, -4.5f}, {8.0f, 4.5f}, 32.0f, 100.0f), expected);
}
void Matrix4Cpp14Test::perspectiveProjectionInfiniteFarConstexpr() {
/* Like Matrix4Test::perspectiveProjectionInfiniteFar(), but testing
usability in a constexpr context */
Matrix4 expected{{4.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 7.111111f, 0.0f, 0.0f},
{0.0f, 0.0f, -1.0f, -1.0f},
{0.0f, 0.0f, -64.0f, 0.0f}};
constexpr Matrix4 actual = Matrix4::perspectiveProjection({16.0f, 9.0f}, 32.0f, Constants::inf());
CORRADE_COMPARE(actual, expected);
CORRADE_COMPARE(actual.transformPoint({0.0f, 0.0f, -32.0f}), Vector3(0.0f, 0.0f, -1.0f));
CORRADE_COMPARE(actual.transformVector({0.0f, 0.0f, -1.0f}), Vector3(0.0f, 0.0f, +1.0f));
CORRADE_COMPARE(Matrix4::perspectiveProjection({-8.0f, -4.5f}, {8.0f, 4.5f}, 32.0f, Constants::inf()), expected);
}
void Matrix4Cpp14Test::perspectiveProjectionOffCenterConstexpr() {
/* Like Matrix4Test::perspectiveProjectionOffCenter(), but testing
usability in a constexpr context */
constexpr Matrix4 projection = Matrix4::perspectiveProjection({-9.0f, -5.0f}, {7.0f, 4.0f}, 32.0f, 100.0f);
CORRADE_COMPARE(projection, (Matrix4{
{ 4.0f, 0.0f, 0.0f, 0.0f},
{ 0.0f, 7.111111f, 0.0f, 0.0f},
{-0.125f, -0.1111111f, -1.9411764f, -1.0f},
{ 0.0f, 0.0f, -94.1176452f, 0.0f}}));
CORRADE_COMPARE(projection.transformPoint({7.0f, 4.0f, -32.0f}), Vector3(1.0f, 1.0f, -1.0f));
CORRADE_COMPARE(projection.transformPoint({0.0f, 0.0f, -100.0f}), Vector3(0.125f, 0.1111111f, +1.0f));
}
void Matrix4Cpp14Test::perspectiveProjectionOffCenterInfiniteFarConstexpr() {
/* Like Matrix4Test::perspectiveProjectionOffCenterInfiniteFar(), but
testing usability in a constexpr context */
constexpr Matrix4 projection = Matrix4::perspectiveProjection({-9.0f, -5.0f}, {7.0f, 4.0f}, 32.0f, Constants::inf());
CORRADE_COMPARE(projection, (Matrix4{
{ 4.0f, 0.0f, 0.0f, 0.0f},
{ 0.0f, 7.111111f, 0.0f, 0.0f},
{-0.125f, -0.1111111f, -1.0f, -1.0f},
{ 0.0f, 0.0f, -64.0f, 0.0f}}));
CORRADE_COMPARE(projection.transformPoint({-9.0f, -5.0f, -32.0f}), Vector3(-1.0f, -1.0f, -1.0f));
CORRADE_COMPARE(projection.transformVector({0.0f, 0.0f, -1.0f}), Vector3(0.125f, 0.1111111f, +1.0f));
}
}}}}
CORRADE_TEST_MAIN(Magnum::Math::Test::Matrix4Cpp14Test)

12
src/Magnum/Math/Test/Matrix4Test.cpp

@ -641,6 +641,8 @@ void Matrix4Test::shearingYZ() {
}
void Matrix4Test::orthographicProjection() {
/* C++14 constexpr verified in Matrix4Cpp14Test, keep in sync */
Matrix4 actual = Matrix4::orthographicProjection({5.0f, 4.0f}, 1.0f, 9.0f);
CORRADE_COMPARE(actual, (Matrix4{
{0.4f, 0.0f, 0.0f, 0.0f},
@ -654,6 +656,8 @@ void Matrix4Test::orthographicProjection() {
}
void Matrix4Test::orthographicProjectionOffCenter() {
/* C++14 constexpr verified in Matrix4Cpp14Test, keep in sync */
/* Shifted by (-1, -0.5) compared to the orthographicProjection() test */
Matrix4 actual = Matrix4::orthographicProjection({-3.5f, -2.5f}, {1.5f, 1.5f}, 1.0f, 9.0f);
CORRADE_COMPARE(actual, (Matrix4{
@ -670,6 +674,8 @@ void Matrix4Test::orthographicProjectionOffCenter() {
}
void Matrix4Test::perspectiveProjection() {
/* C++14 constexpr verified in Matrix4Cpp14Test, keep in sync */
Matrix4 expected{{4.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 7.111111f, 0.0f, 0.0f},
{0.0f, 0.0f, -1.9411764f, -1.0f},
@ -687,6 +693,8 @@ void Matrix4Test::perspectiveProjection() {
}
void Matrix4Test::perspectiveProjectionInfiniteFar() {
/* C++14 constexpr verified in Matrix4Cpp14Test, keep in sync */
Matrix4 expected{{4.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 7.111111f, 0.0f, 0.0f},
{0.0f, 0.0f, -1.0f, -1.0f},
@ -721,6 +729,8 @@ void Matrix4Test::perspectiveProjectionFovInfiniteFar() {
}
void Matrix4Test::perspectiveProjectionOffCenter() {
/* C++14 constexpr verified in Matrix4Cpp14Test, keep in sync */
/* Shifted by (-1, -0.5) compared to the perspectiveProjection() test */
Matrix4 projection = Matrix4::perspectiveProjection({-9.0f, -5.0f}, {7.0f, 4.0f}, 32.0f, 100.0f);
CORRADE_COMPARE(projection, (Matrix4{
@ -737,6 +747,8 @@ void Matrix4Test::perspectiveProjectionOffCenter() {
}
void Matrix4Test::perspectiveProjectionOffCenterInfiniteFar() {
/* C++14 constexpr verified in Matrix4Cpp14Test, keep in sync */
/* Shifted by (-1, -0.5) compared to perspectiveProjectionInfiniteFar() */
Matrix4 projection = Matrix4::perspectiveProjection({-9.0f, -5.0f}, {7.0f, 4.0f}, 32.0f, Constants::inf());
CORRADE_COMPARE(projection, (Matrix4{

Loading…
Cancel
Save