datenwolf / linmath.h

a lean linear math library, aimed at graphics programming. Supports vec3, vec4, mat4x4 and quaternions
Do What The F*ck You Want To Public License
922 stars 134 forks source link

Reusing variables in quat_mul_vec3 for vector operations produces bad results #23

Closed t-mw closed 9 years ago

t-mw commented 9 years ago

The new implementation of quat_mul_vec3 introduced in commit 06b68f6caa214d9f98ada28db837c21e08ed2927 incorrectly calculates 't' and 'u'. The problem's caused by the variables being used as both input and output to vec3_mul_cross, which causes the variables to be corrupted as the cross product is taken. Unlike with the simple vector operations, input variables to vec3_mul_cross must be distinct from the output variable.

I've suggested a fix for it in PR #22.

static inline void vec3_mul_cross(vec3 r, vec3 const a, vec3 const b) {
    r[0] = a[1]*b[2] - a[2]*b[1];
    r[1] = a[2]*b[0] - a[0]*b[2];
    r[2] = a[0]*b[1] - a[1]*b[0];
}
datenwolf commented 9 years ago

Will add it.