|
@@ -315,9 +315,73 @@ void test_euler_conversion() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void check_test(const char *test_case_name, bool condition) {
|
|
|
|
+ if (!condition) {
|
|
|
|
+ OS::get_singleton()->print("FAILED - %s\n", test_case_name);
|
|
|
|
+ } else {
|
|
|
|
+ OS::get_singleton()->print("PASSED - %s\n", test_case_name);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void test_set_axis_angle() {
|
|
|
|
+ Vector3 axis;
|
|
|
|
+ real_t angle;
|
|
|
|
+ real_t pi = (real_t)Math_PI;
|
|
|
|
+
|
|
|
|
+ // Testing the singularity when the angle is 0°.
|
|
|
|
+ Basis identity(1, 0, 0, 0, 1, 0, 0, 0, 1);
|
|
|
|
+ identity.get_axis_angle(axis, angle);
|
|
|
|
+ check_test("Testing the singularity when the angle is 0.", angle == 0);
|
|
|
|
+
|
|
|
|
+ // Testing the singularity when the angle is 180°.
|
|
|
|
+ Basis singularityPi(-1, 0, 0, 0, 1, 0, 0, 0, -1);
|
|
|
|
+ singularityPi.get_axis_angle(axis, angle);
|
|
|
|
+ check_test("Testing the singularity when the angle is 180.", Math::is_equal_approx(angle, pi));
|
|
|
|
+
|
|
|
|
+ // Testing reversing the an axis (of an 30° angle).
|
|
|
|
+ float cos30deg = Math::cos(Math::deg2rad((real_t)30.0));
|
|
|
|
+ Basis z_positive(cos30deg, -0.5, 0, 0.5, cos30deg, 0, 0, 0, 1);
|
|
|
|
+ Basis z_negative(cos30deg, 0.5, 0, -0.5, cos30deg, 0, 0, 0, 1);
|
|
|
|
+
|
|
|
|
+ z_positive.get_axis_angle(axis, angle);
|
|
|
|
+ check_test("Testing reversing the an axis (of an 30 angle).", Math::is_equal_approx(angle, Math::deg2rad((real_t)30.0)));
|
|
|
|
+ check_test("Testing reversing the an axis (of an 30 angle).", axis == Vector3(0, 0, 1));
|
|
|
|
+
|
|
|
|
+ z_negative.get_axis_angle(axis, angle);
|
|
|
|
+ check_test("Testing reversing the an axis (of an 30 angle).", Math::is_equal_approx(angle, Math::deg2rad((real_t)30.0)));
|
|
|
|
+ check_test("Testing reversing the an axis (of an 30 angle).", axis == Vector3(0, 0, -1));
|
|
|
|
+
|
|
|
|
+ // Testing a rotation of 90° on x-y-z.
|
|
|
|
+ Basis x90deg(1, 0, 0, 0, 0, -1, 0, 1, 0);
|
|
|
|
+ x90deg.get_axis_angle(axis, angle);
|
|
|
|
+ check_test("Testing a rotation of 90 on x-y-z.", Math::is_equal_approx(angle, pi / (real_t)2));
|
|
|
|
+ check_test("Testing a rotation of 90 on x-y-z.", axis == Vector3(1, 0, 0));
|
|
|
|
+
|
|
|
|
+ Basis y90deg(0, 0, 1, 0, 1, 0, -1, 0, 0);
|
|
|
|
+ y90deg.get_axis_angle(axis, angle);
|
|
|
|
+ check_test("Testing a rotation of 90 on x-y-z.", axis == Vector3(0, 1, 0));
|
|
|
|
+
|
|
|
|
+ Basis z90deg(0, -1, 0, 1, 0, 0, 0, 0, 1);
|
|
|
|
+ z90deg.get_axis_angle(axis, angle);
|
|
|
|
+ check_test("Testing a rotation of 90 on x-y-z.", axis == Vector3(0, 0, 1));
|
|
|
|
+
|
|
|
|
+ // Regression test: checks that the method returns a small angle (not 0).
|
|
|
|
+ Basis tiny(1, 0, 0, 0, 0.9999995, -0.001, 0, 001, 0.9999995); // The min angle possible with float is 0.001rad.
|
|
|
|
+ tiny.get_axis_angle(axis, angle);
|
|
|
|
+ check_test("Regression test: checks that the method returns a small angle (not 0).", Math::is_equal_approx(angle, (real_t)0.001, (real_t)0.0001));
|
|
|
|
+
|
|
|
|
+ // Regression test: checks that the method returns an angle which is a number (not NaN)
|
|
|
|
+ Basis bugNan(1.00000024, 0, 0.000100001693, 0, 1, 0, -0.000100009143, 0, 1.00000024);
|
|
|
|
+ bugNan.get_axis_angle(axis, angle);
|
|
|
|
+ check_test("Regression test: checks that the method returns an angle which is a number (not NaN)", !Math::is_nan(angle));
|
|
|
|
+}
|
|
|
|
+
|
|
MainLoop *test() {
|
|
MainLoop *test() {
|
|
OS::get_singleton()->print("Start euler conversion checks.\n");
|
|
OS::get_singleton()->print("Start euler conversion checks.\n");
|
|
test_euler_conversion();
|
|
test_euler_conversion();
|
|
|
|
+ OS::get_singleton()->print("\n---------------\n");
|
|
|
|
+ OS::get_singleton()->print("Start set axis angle checks.\n");
|
|
|
|
+ test_set_axis_angle();
|
|
|
|
|
|
return nullptr;
|
|
return nullptr;
|
|
}
|
|
}
|