#include "criterion/criterion.h" #include "graphics/src/rse_math.h" #include #include /*-----------------RSE MATH TEST------------------------*/ TestSuite(rse_math); Test(rse_math, normalize) { float res_x = 0.8017f; float res_y = 0.2672f; float res_z = 0.5345f; struct vec3_t test_vec = {3.0f, 1.0f, 2.0f}; struct vec3_t result = rse_math_normalize_vec3(&test_vec); cr_expect_float_eq(result.x, res_x, 0.0001, "Expected %f, got %f", res_x, result.x); cr_expect_float_eq(result.y, res_y, 0.0001, "Expected %f, got %f", res_y, result.y); cr_expect_float_eq(result.z, res_z, 0.0001, "Expected %f, got %f", res_z, result.z); } Test(rse_math, cross) { float res_x = -3.0f; float res_y = 6.0f; float res_z = -3.0f; struct vec3_t test_vec1 = {2.0f, 3.0f, 4.0f}; struct vec3_t test_vec2 = {5.0f, 6.0f, 7.0f}; struct vec3_t result = rse_math_cross_vec3(&test_vec1, &test_vec2); cr_expect_float_eq(result.x, res_x, 0.0001, "Expected %f, got %f", res_x, result.x); cr_expect_float_eq(result.y, res_y, 0.0001, "Expected %f, got %f", res_y, result.y); cr_expect_float_eq(result.z, res_z, 0.0001, "Expected %f, got %f", res_z, result.z); } Test(rse_math, look_at) { struct vec3_t eye; struct vec3_t center; struct vec3_t up; struct mat4_t result; struct mat4_t expected; eye.x = 0.0f; eye.y = 0.0f; eye.z = 5.0f; center.x = 0.0f; center.y = 0.0f; center.z = 0.0f; up.x = 0.0f; up.y = 0.1f; up.z = 0.0f; expected.x_1 = 1.0f; expected.y_1 = 0.0f; expected.z_1 = 0.0f; expected.w_1 = 0.0f; expected.x_2 = 0.0f; expected.y_2 = 1.0f; expected.z_2 = 0.0f; expected.w_2 = 0.0f; expected.x_3 = 0.0f; expected.y_3 = 0.0f; expected.z_3 = 1.0f; expected.w_3 = 0.0f; expected.x_4 = 0.0f; expected.y_4 = 0.0f; expected.z_4 = -5.0f; expected.w_4 = 1.0f; result = rse_math_look_at(&eye, ¢er, &up); cr_expect_float_eq(result.x_1, expected.x_1, 0.0001, "Expected x_1 %f, got %f", expected.x_1, result.x_1); cr_expect_float_eq(result.y_1, expected.y_1, 0.0001, "Expected y_1 %f, got %f", expected.y_1, result.y_1); cr_expect_float_eq(result.z_1, expected.z_1, 0.0001, "Expected z_1 %f, got %f", expected.z_1, result.z_1); cr_expect_float_eq(result.w_1, expected.w_1, 0.0001, "Expected w_1 %f, got %f", expected.w_1, result.w_1); cr_expect_float_eq(result.x_2, expected.x_2, 0.0001, "Expected x_2 %f, got %f", expected.x_2, result.x_2); cr_expect_float_eq(result.y_2, expected.y_2, 0.0001, "Expected y_2 %f, got %f", expected.y_2, result.y_2); cr_expect_float_eq(result.z_2, expected.z_2, 0.0001, "Expected z_2 %f, got %f", expected.z_2, result.z_2); cr_expect_float_eq(result.w_2, expected.w_2, 0.0001, "Expected w_2 %f, got %f", expected.w_2, result.w_2); cr_expect_float_eq(result.x_3, expected.x_3, 0.0001, "Expected x_3 %f, got %f", expected.x_3, result.x_3); cr_expect_float_eq(result.y_3, expected.y_3, 0.0001, "Expected y_3 %f, got %f", expected.y_3, result.y_3); cr_expect_float_eq(result.z_3, expected.z_3, 0.0001, "Expected z_3 %f, got %f", expected.z_3, result.z_3); cr_expect_float_eq(result.w_3, expected.w_3, 0.0001, "Expected w_3 %f, got %f", expected.w_3, result.w_3); cr_expect_float_eq(result.x_4, expected.x_4, 0.0001, "Expected x_4 %f, got %f", expected.x_4, result.x_4); cr_expect_float_eq(result.y_4, expected.y_4, 0.0001, "Expected y_4 %f, got %f", expected.y_4, result.y_4); cr_expect_float_eq(result.z_4, expected.z_4, 0.0001, "Expected z_4 %f, got %f", expected.z_4, result.z_4); cr_expect_float_eq(result.w_4, expected.w_4, 0.0001, "Expected w_4 %f, got %f", expected.w_4, result.w_4); } Test(rse_math, radians) { float degrees; float radians; float expected_radians; degrees = 45.0f; expected_radians = 0.7853; radians = rse_math_deg_to_radians(degrees); cr_expect_float_eq(radians, expected_radians, 0.0001, "Expected %f, got %f", expected_radians, radians); } Test(rse_math, perspective) { float fovy; float width; float height; float z_near; float z_far; struct mat4_t result; struct mat4_t expected; fovy = rse_math_deg_to_radians(45.0f); width = 640.0f; height = 480.0f; z_near = 0.1f; z_far = 20.0f; expected.x_1 = -1.81066012; expected.y_1 = 0; expected.z_1 = 0; expected.w_1 = 0; expected.x_2 = 0; expected.y_2 = 2.41421342; expected.z_2 = 0; expected.w_2 = 0; expected.x_3 = 0; expected.y_3 = 0; expected.z_3 = -1.0100503; expected.w_3 = -1; expected.x_4 = 0; expected.y_4 = 0; expected.z_4 = -0.201005027; expected.w_4 = 0; result = rse_math_perspective(fovy, width / height, z_near, z_far); cr_expect_float_eq(result.x_1, expected.x_1, 0.0001, "Expected x_1 %f, got %f", expected.x_1, result.x_1); cr_expect_float_eq(result.y_1, expected.y_1, 0.0001, "Expected y_1 %f, got %f", expected.y_1, result.y_1); cr_expect_float_eq(result.z_1, expected.z_1, 0.0001, "Expected z_1 %f, got %f", expected.z_1, result.z_1); cr_expect_float_eq(result.w_1, expected.w_1, 0.0001, "Expected w_1 %f, got %f", expected.w_1, result.w_1); cr_expect_float_eq(result.x_2, expected.x_2, 0.0001, "Expected x_2 %f, got %f", expected.x_2, result.x_2); cr_expect_float_eq(result.y_2, expected.y_2, 0.0001, "Expected y_2 %f, got %f", expected.y_2, result.y_2); cr_expect_float_eq(result.z_2, expected.z_2, 0.0001, "Expected z_2 %f, got %f", expected.z_2, result.z_2); cr_expect_float_eq(result.w_2, expected.w_2, 0.0001, "Expected w_2 %f, got %f", expected.w_2, result.w_2); cr_expect_float_eq(result.x_3, expected.x_3, 0.0001, "Expected x_3 %f, got %f", expected.x_3, result.x_3); cr_expect_float_eq(result.y_3, expected.y_3, 0.0001, "Expected y_3 %f, got %f", expected.y_3, result.y_3); cr_expect_float_eq(result.z_3, expected.z_3, 0.0001, "Expected z_3 %f, got %f", expected.z_3, result.z_3); cr_expect_float_eq(result.w_3, expected.w_3, 0.0001, "Expected w_3 %f, got %f", expected.w_3, result.w_3); cr_expect_float_eq(result.x_4, expected.x_4, 0.0001, "Expected x_4 %f, got %f", expected.x_4, result.x_4); cr_expect_float_eq(result.y_4, expected.y_4, 0.0001, "Expected y_4 %f, got %f", expected.y_4, result.y_4); cr_expect_float_eq(result.z_4, expected.z_4, 0.0001, "Expected z_4 %f, got %f", expected.z_4, result.z_4); cr_expect_float_eq(result.w_4, expected.w_4, 0.0001, "Expected w_4 %f, got %f", expected.w_4, result.w_4); } /*-----------------RSE TEXTURES TEST------------------------*/ #include "graphics/src/rse_texture.h" TestSuite(rse_textures); Test(rse_textures, load_png_image) { rse_load_texture("../../miotacz_piorunów.png"); }