1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Use matrix4::getRotationRadians

This commit is contained in:
Lars Mueller 2025-01-30 14:11:16 +01:00 committed by sfan5
parent b6c71b2379
commit d74af2f1a7
10 changed files with 34 additions and 28 deletions

View file

@ -84,20 +84,20 @@ SECTION("getScale") {
}
}
SECTION("getRotationDegrees") {
auto test_rotation_degrees = [](v3f deg, v3f scale) {
SECTION("getRotationRadians") {
auto test_rotation_degrees = [](v3f rad, v3f scale) {
matrix4 S;
S.setScale(scale);
matrix4 R;
R.setRotationDegrees(deg);
v3f rot = (R * S).getRotationDegrees();
R.setRotationRadians(rad);
v3f rot = (R * S).getRotationRadians();
matrix4 B;
B.setRotationDegrees(rot);
B.setRotationRadians(rot);
CHECK(matrix_equals(R, B));
};
SECTION("returns a rotation equivalent to the original rotation") {
test_rotation_degrees({100, 200, 300}, v3f(1));
Catch::Generators::RandomFloatingGenerator<f32> gen_angle(0, 360, Catch::getSeed());
test_rotation_degrees({1.0f, 2.0f, 3.0f}, v3f(1));
Catch::Generators::RandomFloatingGenerator<f32> gen_angle(0.0f, 2 * core::PI, Catch::getSeed());
Catch::Generators::RandomFloatingGenerator<f32> gen_scale(0.1f, 10, Catch::getSeed());
auto draw = [](auto gen) {
f32 f = gen.get();
@ -109,11 +109,12 @@ SECTION("getRotationDegrees") {
};
for (int i = 0; i < 1000; ++i)
test_rotation_degrees(draw_v3f(gen_angle), draw_v3f(gen_scale));
for (f32 i = 0; i < 360; i += 90)
for (f32 j = 0; j < 360; j += 90)
for (f32 k = 0; k < 360; k += 90) {
for (f32 i = 0; i < 4; ++i)
for (f32 j = 0; j < 4; ++j)
for (f32 k = 0; k < 4; ++k) {
v3f rad = core::PI / 4.0f * v3f(i, j, k);
for (int l = 0; l < 100; ++l) {
test_rotation_degrees({i, j, k}, draw_v3f(gen_scale));
test_rotation_degrees(rad, draw_v3f(gen_scale));
}
}
}

View file

@ -100,7 +100,7 @@ SECTION("matrix-euler roundtrip") {
test_euler_angles_rad([](v3f rad) {
matrix4 mat, mat2;
mat.setRotationRadians(rad);
v3f rad2 = mat.getRotationDegrees() * core::DEGTORAD;
v3f rad2 = mat.getRotationRadians();
mat2.setRotationRadians(rad2);
CHECK(matrix_equals(mat, mat2));
});