cglm
cglm copied to clipboard
Standard behavior for functions
Docs about dest param : "You can pass all parameter same (this is similar to m1 *= m1), you can pass dest as m1 or m2 (this is similar to m1 *= m2)" (c)
But some functions behave differently. For example:
vec3 A = {0,0,2};
vec3 B = {2,0,0};
glm_vec3_cross(A, B, A); // A = {0, 4, -8} was expected A = {0, 4, 0}
Maybe replace the implementation of some functions under the standard. For example;
glm_vec3_cross(vec3 a, vec3 b, vec3 dest) {
/* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */
dest[0] = a[1] * b[2] - a[2] * b[1];
dest[1] = a[2] * b[0] - a[0] * b[2];
dest[2] = a[0] * b[1] - a[1] * b[0];
}
to:
glm_vec3_cross(vec3 a, vec3 b, vec3 dest) {
/* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */
vec3 res;
res[0] = a[1] * b[2] - a[2] * b[1];
res[1] = a[2] * b[0] - a[0] * b[2];
res[2] = a[0] * b[1] - a[1] * b[0];
glm_vec3_copy(res, dest);
}
Hi @gduenden ,
Thanks for your feedbacks, sorry for the late response 😔
Maybe replace the implementation of some functions under the standard
This seems to be good idea, however not all functions must behave like this. For instance glm_vec3_ortho(v, dest), it finds a[n] orthogonal/perpendicular for given vector. So it would be weird to allow to store destination vector in source vector, right?
If you like to change the behavior of glm_vec3_cross() or similar functions (I may reject some of them), a PR would be awesome, otherwise I will update them later.