|
|
|
@ -93,6 +93,8 @@ struct Matrix4Test: Corrade::TestSuite::Tester { |
|
|
|
void perspectiveProjectionInfiniteFar(); |
|
|
|
void perspectiveProjectionInfiniteFar(); |
|
|
|
void perspectiveProjectionFov(); |
|
|
|
void perspectiveProjectionFov(); |
|
|
|
void perspectiveProjectionFovInfiniteFar(); |
|
|
|
void perspectiveProjectionFovInfiniteFar(); |
|
|
|
|
|
|
|
void perspectiveProjectionOffCenter(); |
|
|
|
|
|
|
|
void perspectiveProjectionOffCenterInfiniteFar(); |
|
|
|
void lookAt(); |
|
|
|
void lookAt(); |
|
|
|
|
|
|
|
|
|
|
|
void fromParts(); |
|
|
|
void fromParts(); |
|
|
|
@ -158,6 +160,8 @@ Matrix4Test::Matrix4Test() { |
|
|
|
&Matrix4Test::perspectiveProjectionInfiniteFar, |
|
|
|
&Matrix4Test::perspectiveProjectionInfiniteFar, |
|
|
|
&Matrix4Test::perspectiveProjectionFov, |
|
|
|
&Matrix4Test::perspectiveProjectionFov, |
|
|
|
&Matrix4Test::perspectiveProjectionFovInfiniteFar, |
|
|
|
&Matrix4Test::perspectiveProjectionFovInfiniteFar, |
|
|
|
|
|
|
|
&Matrix4Test::perspectiveProjectionOffCenter, |
|
|
|
|
|
|
|
&Matrix4Test::perspectiveProjectionOffCenterInfiniteFar, |
|
|
|
&Matrix4Test::lookAt, |
|
|
|
&Matrix4Test::lookAt, |
|
|
|
|
|
|
|
|
|
|
|
&Matrix4Test::fromParts, |
|
|
|
&Matrix4Test::fromParts, |
|
|
|
@ -501,6 +505,10 @@ void Matrix4Test::perspectiveProjection() { |
|
|
|
/* NDC is left-handed, so point on near plane should be -1, far +1 */ |
|
|
|
/* 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, -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(actual.transformPoint({0.0f, 0.0f, -100.0f}), Vector3(0.0f, 0.0f, +1.0f)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* The version with bottom/left/top/right should give the same result if
|
|
|
|
|
|
|
|
it's centered */ |
|
|
|
|
|
|
|
CORRADE_COMPARE(Matrix4::perspectiveProjection({-8.0f, -4.5f}, {8.0f, 4.5f}, 32.0f, 100.0f), expected); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Matrix4Test::perspectiveProjectionInfiniteFar() { |
|
|
|
void Matrix4Test::perspectiveProjectionInfiniteFar() { |
|
|
|
@ -515,6 +523,10 @@ void Matrix4Test::perspectiveProjectionInfiniteFar() { |
|
|
|
in direction of far plane +1 */ |
|
|
|
in direction of far plane +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, -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(actual.transformVector({0.0f, 0.0f, -1.0f}), Vector3(0.0f, 0.0f, +1.0f)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* The version with bottom/left/top/right should give the same result if
|
|
|
|
|
|
|
|
it's centered */ |
|
|
|
|
|
|
|
CORRADE_COMPARE(Matrix4::perspectiveProjection({-8.0f, -4.5f}, {8.0f, 4.5f}, 32.0f, Constants::inf()), expected); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Matrix4Test::perspectiveProjectionFov() { |
|
|
|
void Matrix4Test::perspectiveProjectionFov() { |
|
|
|
@ -533,6 +545,38 @@ void Matrix4Test::perspectiveProjectionFovInfiniteFar() { |
|
|
|
CORRADE_COMPARE(Matrix4::perspectiveProjection(Deg(27.0f), 2.35f, 32.0f, Constants::inf()), expected); |
|
|
|
CORRADE_COMPARE(Matrix4::perspectiveProjection(Deg(27.0f), 2.35f, 32.0f, Constants::inf()), expected); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Matrix4Test::perspectiveProjectionOffCenter() { |
|
|
|
|
|
|
|
Matrix4 expected({ 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}); |
|
|
|
|
|
|
|
/* Shifted by (-1, -0.5) compared to the perspectiveProjection() test */ |
|
|
|
|
|
|
|
Matrix4 actual = Matrix4::perspectiveProjection({-9.0f, -5.0f}, {7.0f, 4.0f}, 32.0f, 100.0f); |
|
|
|
|
|
|
|
CORRADE_COMPARE(actual, expected); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* NDC is left-handed, so point on the near plane top right corner should
|
|
|
|
|
|
|
|
be (1, 1, -1), and a point in the center on the far plane roughly (0, 0, |
|
|
|
|
|
|
|
+1) due to the "off-centerness" */ |
|
|
|
|
|
|
|
CORRADE_COMPARE(actual.transformPoint({7.0f, 4.0f, -32.0f}), Vector3(1.0f, 1.0f, -1.0f)); |
|
|
|
|
|
|
|
CORRADE_COMPARE(actual.transformPoint({0.0f, 0.0f, -100.0f}), Vector3(0.125f, 0.1111111f, +1.0f)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Matrix4Test::perspectiveProjectionOffCenterInfiniteFar() { |
|
|
|
|
|
|
|
Matrix4 expected({ 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}); |
|
|
|
|
|
|
|
/* Shifted by (-1, -0.5) compared to perspectiveProjectionInfiniteFar() */ |
|
|
|
|
|
|
|
Matrix4 actual = Matrix4::perspectiveProjection({-9.0f, -5.0f}, {7.0f, 4.0f}, 32.0f, Constants::inf()); |
|
|
|
|
|
|
|
CORRADE_COMPARE(actual, expected); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* NDC is left-handed, so point on the near plane bottom left corner should
|
|
|
|
|
|
|
|
be (1, 1, -1) and a *vector* in the direction of the far plane roughly |
|
|
|
|
|
|
|
(0, 0, +1) due to the "off-centerness" */ |
|
|
|
|
|
|
|
CORRADE_COMPARE(actual.transformPoint({-9.0f, -5.0f, -32.0f}), Vector3(-1.0f, -1.0f, -1.0f)); |
|
|
|
|
|
|
|
CORRADE_COMPARE(actual.transformVector({0.0f, 0.0f, -1.0f}), Vector3(0.125f, 0.1111111f, +1.0f)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Matrix4Test::lookAt() { |
|
|
|
void Matrix4Test::lookAt() { |
|
|
|
Vector3 translation{5.3f, -8.9f, -10.0f}; |
|
|
|
Vector3 translation{5.3f, -8.9f, -10.0f}; |
|
|
|
Vector3 target{19.0f, 29.3f, 0.0f}; |
|
|
|
Vector3 target{19.0f, 29.3f, 0.0f}; |
|
|
|
|