diff --git a/include/vector/vec.h b/include/vector/vec.h index b0c8299..09f9633 100644 --- a/include/vector/vec.h +++ b/include/vector/vec.h @@ -128,6 +128,7 @@ mat4x4f_t get_scaling_matrix(vec3f_t scale); mat3x3f_t get_rotation_mat3x3f(vec3f_t rotation); vec3f_t mul_mat3x4f_by_vec4f(mat3x4f_t mat, vec4f_t vec); mat3x4f_t mul_mat3x4f_by_mat4x4f(mat3x4f_t mat1, mat4x4f_t mat2); +vec4f_t mul_mat4x4f_by_vec4f(mat4x4f_t mat, vec4f_t vec); mat4x4f_t mul_mat4x4f(mat4x4f_t mat1, mat4x4f_t mat2); #endif // !VEC_H diff --git a/src/vector/vec.c b/src/vector/vec.c index 133d7e4..66ca772 100644 --- a/src/vector/vec.c +++ b/src/vector/vec.c @@ -342,6 +342,19 @@ mat3x4f_t mul_mat3x4f_by_mat4x4f(mat3x4f_t mat1, mat4x4f_t mat2) { }; } +vec4f_t mul_mat4x4f_by_vec4f(mat4x4f_t mat, vec4f_t vec) { + f32 x = mat.row0.x * vec.x + mat.row0.y * vec.y + mat.row0.z * vec.z + + mat.row0.w * vec.w; + f32 y = mat.row1.x * vec.x + mat.row1.y * vec.y + mat.row1.z * vec.z + + mat.row1.w * vec.w; + f32 z = mat.row2.x * vec.x + mat.row2.y * vec.y + mat.row2.z * vec.z + + mat.row2.w * vec.w; + f32 w = mat.row3.x * vec.x + mat.row3.y * vec.y + mat.row3.z * vec.z + + mat.row3.w * vec.w; + + return (vec4f_t){x, y, z, w}; +} + mat4x4f_t mul_mat4x4f(mat4x4f_t mat1, mat4x4f_t mat2) { f32 row0_col0 = mat1.row0.x * mat2.row0.x + mat1.row0.y * mat2.row1.x + mat1.row0.z * mat2.row2.x + mat1.row0.w * mat2.row3.x;