Turn matrix_4x4_multiply into macro

This commit is contained in:
twinaphex 2017-04-16 07:55:02 +02:00
parent b7aefa71f8
commit 257410d058
7 changed files with 91 additions and 35 deletions

View File

@ -297,7 +297,7 @@ static void fft_render(glfft_t *fft, GLuint backbuffer, unsigned width, unsigned
MAT_ELEM_4X4(mvp_lookat, 3, 3)
);
#endif
matrix_4x4_multiply(&mvp, &mvp_persp, &mvp_lookat);
matrix_4x4_multiply(mvp, &mvp_persp, &mvp_lookat);
#ifdef GLM_USE_DEBUG
printf("mvp: \n %.2f, %.2f, %.2f, %.2f \n %.2f, %.2f, %.2f, %.2f \n %.2f, %.2f, %.2f, %.2f \n %.2f, %.2f, %.2f, %.2f \n\n",
MAT_ELEM_4X4(mvp, 0, 0),

View File

@ -291,7 +291,7 @@ static void gl_set_projection(gl_t *gl,
}
matrix_4x4_rotate_z(rot, M_PI * gl->rotation / 180.0f);
matrix_4x4_multiply(&gl->mvp, &rot, &gl->mvp_no_rot);
matrix_4x4_multiply(gl->mvp, rot, gl->mvp_no_rot);
}
static void gl_set_viewport_wrapper(void *data, unsigned viewport_width,

View File

@ -342,7 +342,7 @@ static void vita2d_set_projection(vita_video_t *vita,
}
matrix_4x4_rotate_z(rot, M_PI * vita->rotation / 180.0f);
matrix_4x4_multiply(&vita->mvp, &rot, &vita->mvp_no_rot);
matrix_4x4_multiply(vita->mvp, rot, vita->mvp_no_rot);
}
static void vita2d_gfx_update_viewport(vita_video_t* vita)

View File

@ -1325,7 +1325,7 @@ static void vulkan_set_projection(vk_t *vk,
}
matrix_4x4_rotate_z(rot, M_PI * vk->rotation / 180.0f);
matrix_4x4_multiply(&vk->mvp, &rot, &vk->mvp_no_rot);
matrix_4x4_multiply(vk->mvp, rot, vk->mvp_no_rot);
}
static void vulkan_set_rotation(void *data, unsigned rotation)

View File

@ -63,31 +63,3 @@ void matrix_4x4_lookat(math_matrix_4x4 *out,
MAT_ELEM_4X4(*out, 3, 2) = -(zaxis[0] * eye[0] + zaxis[1] * eye[1] + zaxis[2] * eye[2]);
MAT_ELEM_4X4(*out, 3, 3) = 1.f;
}
/*
* Multiplies a with b, stores the result in out
*/
void matrix_4x4_multiply(
math_matrix_4x4 *out,
const math_matrix_4x4 *a,
const math_matrix_4x4 *b)
{
unsigned r, c, k;
math_matrix_4x4 mat;
if (!out || !a || !b)
return;
for (r = 0; r < 4; r++)
{
for (c = 0; c < 4; c++)
{
float dot = 0.0f;
for (k = 0; k < 4; k++)
dot += MAT_ELEM_4X4(*a, r, k) * MAT_ELEM_4X4(*b, k, c);
MAT_ELEM_4X4(mat, r, c) = dot;
}
}
*out = mat;
}

View File

@ -212,7 +212,91 @@ void matrix_4x4_lookat(math_matrix_4x4 *out,
vec3_t center,
vec3_t up);
void matrix_4x4_multiply(math_matrix_4x4 *out, const math_matrix_4x4 *a, const math_matrix_4x4 *b);
/*
* Multiplies a with b, stores the result in out
*/
#define matrix_4x4_multiply(out, a, b) \
MAT_ELEM_4X4(out, 0, 0) = \
MAT_ELEM_4X4(a, 0, 0) * MAT_ELEM_4X4(b, 0, 0) + \
MAT_ELEM_4X4(a, 0, 1) * MAT_ELEM_4X4(b, 1, 0) + \
MAT_ELEM_4X4(a, 0, 2) * MAT_ELEM_4X4(b, 2, 0) + \
MAT_ELEM_4X4(a, 0, 3) * MAT_ELEM_4X4(b, 3, 0); \
MAT_ELEM_4X4(out, 0, 1) = \
MAT_ELEM_4X4(a, 0, 0) * MAT_ELEM_4X4(b, 0, 1) + \
MAT_ELEM_4X4(a, 0, 1) * MAT_ELEM_4X4(b, 1, 1) + \
MAT_ELEM_4X4(a, 0, 2) * MAT_ELEM_4X4(b, 2, 1) + \
MAT_ELEM_4X4(a, 0, 3) * MAT_ELEM_4X4(b, 3, 1); \
MAT_ELEM_4X4(out, 0, 2) = \
MAT_ELEM_4X4(a, 0, 0) * MAT_ELEM_4X4(b, 0, 2) + \
MAT_ELEM_4X4(a, 0, 1) * MAT_ELEM_4X4(b, 1, 2) + \
MAT_ELEM_4X4(a,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, 0) + \
MAT_ELEM_4X4(a, 3, 2) * MAT_ELEM_4X4(b, 2, 0) + \
MAT_ELEM_4X4(a, 3, 3) * MAT_ELEM_4X4(b, 3, 0); \
MAT_ELEM_4X4(out, 3, 1) = \
MAT_ELEM_4X4(a, 3, 0) * MAT_ELEM_4X4(b, 0, 1) + \
MAT_ELEM_4X4(a, 3, 1) * MAT_ELEM_4X4(b, 1, 1) + \
MAT_ELEM_4X4(a, 3, 2) * MAT_ELEM_4X4(b, 2, 1) + \
MAT_ELEM_4X4(a, 3, 3) * MAT_ELEM_4X4(b, 3, 1); \
MAT_ELEM_4X4(out, 3, 2) = \
MAT_ELEM_4X4(a, 3, 0) * MAT_ELEM_4X4(b, 0, 2) + \
MAT_ELEM_4X4(a, 3, 1) * MAT_ELEM_4X4(b, 1, 2) + \
MAT_ELEM_4X4(a, 3, 2) * MAT_ELEM_4X4(b, 2, 2) + \
MAT_ELEM_4X4(a, 3, 3) * MAT_ELEM_4X4(b, 3, 2); \
MAT_ELEM_4X4(out, 3, 3) = \
MAT_ELEM_4X4(a, 3, 0) * MAT_ELEM_4X4(b, 0, 3) + \
MAT_ELEM_4X4(a, 3, 1) * MAT_ELEM_4X4(b, 1, 3) + \
MAT_ELEM_4X4(a, 3, 2) * MAT_ELEM_4X4(b, 2, 3) + \
MAT_ELEM_4X4(a, 3, 3) * MAT_ELEM_4X4(b, 3, 3)
#define matrix_4x4_scale(mat, x, y, z) \
MAT_ELEM_4X4(mat, 0, 0) = x; \

View File

@ -909,14 +909,14 @@ void menu_display_rotate_z(menu_display_ctx_rotate_draw_t *draw)
b = (math_matrix_4x4*)menu_disp->get_default_mvp();
matrix_4x4_rotate_z(matrix_rotated, draw->rotation);
matrix_4x4_multiply(draw->matrix, &matrix_rotated, b);
matrix_4x4_multiply(*draw->matrix, matrix_rotated, *b);
if (!draw->scale_enable)
return;
matrix_4x4_scale(matrix_scaled,
draw->scale_x, draw->scale_y, draw->scale_z);
matrix_4x4_multiply(draw->matrix, &matrix_scaled, draw->matrix);
matrix_4x4_multiply(*draw->matrix, matrix_scaled, *draw->matrix);
#endif
}