benches, optimizations for sin and cos

This commit is contained in:
veclavtlica
2026-09-13 17:59:20 +03:00
parent 6d7fe7392a
commit 739237575a
8 changed files with 218 additions and 65 deletions
+13 -10
View File
@@ -170,18 +170,21 @@ static inline com_mat_t com_mat_perspective(uint16_t rwidth, uint16_t rheight,
com_fixed_t fov) {
com_mat_t result = {0};
// com_fixed_t const aspect = com_fixed_div(rwidth, rheight);
com_fixed_t const aspect =
com_fixed_div(rwidth * COM_FIXED_FRACUNIT, rheight * COM_FIXED_FRACUNIT);
com_fixed_t const f =
com_fixed_div(COM_FIXED_FRACUNIT,
com_fixed_tan(com_fixed_mul(fov, COM_FIXED_FRACHALF)));
com_fixed_t const fn = com_fixed_div(COM_FIXED_FRACUNIT, (nearz - farz));
// const float f = 1.0f / tanf(camera->fov * 0.5f);
// const float fn = 1.0f / (CAMERA_NEAR_Z - camera->far_z);
result.a[0 * 4 + 0] = com_fixed_div(f, aspect);
result.a[1 * 4 + 1] = f;
result.a[2 * 4 + 2] = (nearz + farz) * fn;
result.a[2 * 4 + 3] = -COM_FIXED_FRACUNIT;
result.a[3 * 4 + 2] =
(COM_FIXED_FRACUNIT * 2) * com_fixed_mul(com_fixed_mul(nearz, farz), fn);
// result.row[0].x = f / aspect;
// result.row[1].y = f;
// result.row[2].z = (CAMERA_NEAR_Z + camera->far_z) * fn;
// result.row[2].w = -1.0f;
// result.row[3].z = 2.0f * CAMERA_NEAR_Z * camera->far_z * fn;
// return result;
return result;
}
#endif