diff --git a/include/cglm-affine.h b/include/cglm-affine.h index 213894c..8e21d82 100644 --- a/include/cglm-affine.h +++ b/include/cglm-affine.h @@ -205,43 +205,32 @@ void glm_rotate_ndc_make(mat4 m, float angle, vec3 axis_ndc) { /* https://www.opengl.org/sdk/docs/man2/xhtml/glRotate.xml */ - float c, s, x1c, y1c, z1c, t; - -#define x axis_ndc[0] -#define y axis_ndc[1] -#define z axis_ndc[2] + vec3 v, vs; + float c; c = cosf(angle); - s = sinf(angle); - t = 1 - c; - x1c = t * x; - y1c = t * y; - z1c = t * z; + glm_vec_scale(axis_ndc, 1.0f - c, v); + glm_vec_scale(axis_ndc, sinf(angle), vs); - m[0][0] = x1c * x + c; - m[0][1] = x1c * y + z * s; - m[0][2] = x1c * z - y * s; - m[0][3] = 0.0f; + glm_vec_scale(axis_ndc, v[0], m[0]); + glm_vec_scale(axis_ndc, v[1], m[1]); + glm_vec_scale(axis_ndc, v[1], m[2]); - m[1][0] = y1c * x - z * s; - m[1][1] = y1c * y + c; - m[1][2] = y1c * z + x * s; - m[1][3] = 0.0f; + m[0][0] += c; + m[0][1] += vs[2]; + m[0][2] -= vs[1]; - m[2][0] = z1c * x + y * s; - m[2][1] = z1c * y - x * s; - m[2][2] = z1c * z + c; - m[2][3] = 0.0f; + m[1][0] -= vs[2]; + m[1][1] += c; + m[1][2] += vs[0]; - m[3][0] = 0.0f; - m[3][1] = 0.0f; - m[3][2] = 0.0f; + m[2][0] += vs[1]; + m[2][1] -= vs[0]; + m[2][2] += c; + + m[0][3] = m[1][3] = m[2][3] = m[3][0] = m[3][1] = m[3][2] = 0.0f; m[3][3] = 1.0f; - -#undef x -#undef y -#undef z } CGLM_INLINE