affine: add perspective matrix test cases
This commit is contained in:
parent
561925b201
commit
d7b36b0ee3
@ -5,6 +5,7 @@
|
|||||||
#include "quaternion.hpp"
|
#include "quaternion.hpp"
|
||||||
|
|
||||||
#include "coord/iostream.hpp"
|
#include "coord/iostream.hpp"
|
||||||
|
#include "matrix.hpp"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
@ -53,6 +54,97 @@ test_matrix_identities (util::TAP::logger &tap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
void
|
||||||
|
test_perspective (util::TAP::logger &tap)
|
||||||
|
{
|
||||||
|
static const struct {
|
||||||
|
float w, h;
|
||||||
|
float near, far;
|
||||||
|
float fov;
|
||||||
|
float a, b, c, d;
|
||||||
|
} TESTS[] = {
|
||||||
|
{ 1.f, 1.f, 1.f, 100.f, 45.f, 2.414213419f, 2.414213419f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 1.f, 1.f, 1.f, 100.f, 60.f, 1.732050776f, 1.732050776f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 1.f, 1.f, 1.f, 100.f, 90.f, 1.000000000f, 1.000000000f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 1.f, 1.f, 1.f, 100.f, 120.f, 0.577350199f, 0.577350199f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 1.f, 1.f, 1e-08f, 1e+08f, 45.f, 2.414213419f, 2.414213419f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 1.f, 1.f, 1e-08f, 1e+08f, 60.f, 1.732050776f, 1.732050776f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 1.f, 1.f, 1e-08f, 1e+08f, 90.f, 1.000000000f, 1.000000000f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 1.f, 1.f, 1e-08f, 1e+08f, 120.f, 0.577350199f, 0.577350199f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 1.f, 1.f, 0.01f, 1000.f, 45.f, 2.414213419f, 2.414213419f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 1.f, 1.f, 0.01f, 1000.f, 60.f, 1.732050776f, 1.732050776f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 1.f, 1.f, 0.01f, 1000.f, 90.f, 1.000000000f, 1.000000000f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 1.f, 1.f, 0.01f, 1000.f, 120.f, 0.577350199f, 0.577350199f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 4.f, 3.f, 1.f, 100.f, 45.f, 1.810660124f, 2.414213419f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 4.f, 3.f, 1.f, 100.f, 60.f, 1.299038053f, 1.732050776f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 4.f, 3.f, 1.f, 100.f, 90.f, 0.750000000f, 1.000000000f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 4.f, 3.f, 1.f, 100.f, 120.f, 0.433012664f, 0.577350199f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 4.f, 3.f, 1e-08f, 1e+08f, 45.f, 1.810660124f, 2.414213419f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 4.f, 3.f, 1e-08f, 1e+08f, 60.f, 1.299038053f, 1.732050776f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 4.f, 3.f, 1e-08f, 1e+08f, 90.f, 0.750000000f, 1.000000000f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 4.f, 3.f, 1e-08f, 1e+08f, 120.f, 0.433012664f, 0.577350199f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 4.f, 3.f, 0.01f, 1000.f, 45.f, 1.810660124f, 2.414213419f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 4.f, 3.f, 0.01f, 1000.f, 60.f, 1.299038053f, 1.732050776f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 4.f, 3.f, 0.01f, 1000.f, 90.f, 0.750000000f, 1.000000000f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 4.f, 3.f, 0.01f, 1000.f, 120.f, 0.433012664f, 0.577350199f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 16.f, 9.f, 1.f, 100.f, 45.f, 1.357995033f, 2.414213419f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 16.f, 9.f, 1.f, 100.f, 60.f, 0.974278569f, 1.732050776f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 16.f, 9.f, 1.f, 100.f, 90.f, 0.562500000f, 1.000000000f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 16.f, 9.f, 1.f, 100.f, 120.f, 0.324759483f, 0.577350199f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 16.f, 9.f, 1e-08f, 1e+08f, 45.f, 1.357995033f, 2.414213419f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 16.f, 9.f, 1e-08f, 1e+08f, 60.f, 0.974278569f, 1.732050776f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 16.f, 9.f, 1e-08f, 1e+08f, 90.f, 0.562500000f, 1.000000000f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 16.f, 9.f, 1e-08f, 1e+08f, 120.f, 0.324759483f, 0.577350199f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 16.f, 9.f, 0.01f, 1000.f, 45.f, 1.357995033f, 2.414213419f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 16.f, 9.f, 0.01f, 1000.f, 60.f, 0.974278569f, 1.732050776f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 16.f, 9.f, 0.01f, 1000.f, 90.f, 0.562500000f, 1.000000000f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 16.f, 9.f, 0.01f, 1000.f, 120.f, 0.324759483f, 0.577350199f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 16.f, 10.f, 1.f, 100.f, 45.f, 1.508883357f, 2.414213419f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 16.f, 10.f, 1.f, 100.f, 60.f, 1.082531691f, 1.732050776f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 16.f, 10.f, 1.f, 100.f, 90.f, 0.625000000f, 1.000000000f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 16.f, 10.f, 1.f, 100.f, 120.f, 0.360843867f, 0.577350199f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 16.f, 10.f, 1e-08f, 1e+08f, 45.f, 1.508883357f, 2.414213419f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 16.f, 10.f, 1e-08f, 1e+08f, 60.f, 1.082531691f, 1.732050776f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 16.f, 10.f, 1e-08f, 1e+08f, 90.f, 0.625000000f, 1.000000000f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 16.f, 10.f, 1e-08f, 1e+08f, 120.f, 0.360843867f, 0.577350199f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 16.f, 10.f, 0.01f, 1000.f, 45.f, 1.508883357f, 2.414213419f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 16.f, 10.f, 0.01f, 1000.f, 60.f, 1.082531691f, 1.732050776f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 16.f, 10.f, 0.01f, 1000.f, 90.f, 0.625000000f, 1.000000000f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 16.f, 10.f, 0.01f, 1000.f, 120.f, 0.360843867f, 0.577350199f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 21.f, 9.f, 1.f, 100.f, 45.f, 1.034662843f, 2.414213419f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 21.f, 9.f, 1.f, 100.f, 60.f, 0.742307484f, 1.732050776f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 21.f, 9.f, 1.f, 100.f, 90.f, 0.428571433f, 1.000000000f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 21.f, 9.f, 1.f, 100.f, 120.f, 0.247435793f, 0.577350199f, -1.020202041f, -2.020201921f },
|
||||||
|
{ 21.f, 9.f, 1e-08f, 1e+08f, 45.f, 1.034662843f, 2.414213419f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 21.f, 9.f, 1e-08f, 1e+08f, 60.f, 0.742307484f, 1.732050776f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 21.f, 9.f, 1e-08f, 1e+08f, 90.f, 0.428571433f, 1.000000000f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 21.f, 9.f, 1e-08f, 1e+08f, 120.f, 0.247435793f, 0.577350199f, -1.000000000f, -0.000000020f },
|
||||||
|
{ 21.f, 9.f, 0.01f, 1000.f, 45.f, 1.034662843f, 2.414213419f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 21.f, 9.f, 0.01f, 1000.f, 60.f, 0.742307484f, 1.732050776f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 21.f, 9.f, 0.01f, 1000.f, 90.f, 0.428571433f, 1.000000000f, -1.000020027f, -0.020000201f },
|
||||||
|
{ 21.f, 9.f, 0.01f, 1000.f, 120.f, 0.247435793f, 0.577350199f, -1.000020027f, -0.020000201f },
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const auto &t: TESTS) {
|
||||||
|
util::matrix4f m {0};
|
||||||
|
m[0][0] = t.a;
|
||||||
|
m[1][1] = t.b;
|
||||||
|
m[2][2] = t.c;
|
||||||
|
m[2][3] = t.d;
|
||||||
|
m[3][2] = -1.f;
|
||||||
|
|
||||||
|
const auto p = util::perspective (util::to_radians (t.fov), t.w / t.h, {t.near, t.far});
|
||||||
|
|
||||||
|
tap.expect (
|
||||||
|
util::relatively_equal (m, p, 1e-7f),
|
||||||
|
"perspective %!:%!@%!",
|
||||||
|
t.w, t.h, t.fov
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
void
|
void
|
||||||
test_mq_axis (util::TAP::logger &tap)
|
test_mq_axis (util::TAP::logger &tap)
|
||||||
@ -119,6 +211,7 @@ main (int, char**)
|
|||||||
test_matrix_identities (tap);
|
test_matrix_identities (tap);
|
||||||
test_mq_axis (tap);
|
test_mq_axis (tap);
|
||||||
test_mq_euler (tap);
|
test_mq_euler (tap);
|
||||||
|
test_perspective (tap);
|
||||||
|
|
||||||
return tap.status ();
|
return tap.status ();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user