fixed cos sin

This commit is contained in:
veclavtlica
2026-09-11 15:09:47 +03:00
parent adfae10938
commit 6d7fe7392a
10 changed files with 345 additions and 6 deletions
+50
View File
@@ -134,4 +134,54 @@ static inline com_mat_t com_mat_reoder(com_mat_t a) {
return result;
}
/* TODO: move to .c file */
/* Produces a view matrix needed for camera work. */
static inline com_mat_t com_mat_look_at(com_vec_t pos, com_vec_t up,
com_vec_t target) {
com_vec_t const r = com_vec_nrm(com_vec_crs(target, up));
com_vec_t const u = com_vec_crs(r, target);
com_mat_t result;
result.a[0] = r.s.x;
result.a[1] = u.s.x;
result.a[2] = -target.s.x;
result.a[3] = 0;
result.a[4] = r.s.y;
result.a[5] = u.s.y;
result.a[6] = -target.s.y;
result.a[7] = 0;
result.a[8] = r.s.z;
result.a[9] = u.s.z;
result.a[10] = -target.s.z;
result.a[11] = 0;
result.a[12] = -com_vec_dot(r, pos);
result.a[13] = -com_vec_dot(u, pos);
result.a[14] = com_vec_dot(target, pos);
result.a[15] = COM_FIXED_FRACUNIT;
return result;
}
/* TODO: move to .c file */
/* Produces a projection matrix needed for camera work. */
static inline com_mat_t com_mat_perspective(uint16_t rwidth, uint16_t rheight,
com_fixed_t nearz, com_fixed_t farz,
com_fixed_t fov) {
com_mat_t result = {0};
// com_fixed_t const aspect = com_fixed_div(rwidth, rheight);
// const float f = 1.0f / tanf(camera->fov * 0.5f);
// const float fn = 1.0f / (CAMERA_NEAR_Z - camera->far_z);
// 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;
}
#endif