lkang2 / glmatrix

Automatically exported from code.google.com/p/glmatrix
0 stars 0 forks source link

mat4.multiplyVec4 is wrong #33

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
dest[4] should be dest[3] in this method and mat[4] should be mat[3]

mat4.multiplyVec4 = function(mat, vec, dest) {
        if(!dest) { dest = vec }

        var x = vec[0], y = vec[1], z = vec[2], w = vec[3];

        dest[0] = mat[0]*x + mat[4]*y + mat[8]*z + mat[12]*w;
        dest[1] = mat[1]*x + mat[5]*y + mat[9]*z + mat[13]*w;
        dest[2] = mat[2]*x + mat[6]*y + mat[10]*z + mat[14]*w;
/* Here is the error: dest[4] should be dest[3] and mat[4] should be mat[3]*/
        dest[4] = mat[4]*x + mat[7]*y + mat[11]*z + mat[15]*w;

        return dest;
};

Original issue reported on code.google.com by jeremyMl...@gmail.com on 18 Dec 2010 at 4:46

GoogleCodeExporter commented 8 years ago
Thanks for catching that. Stupid mistake on my part.

Original comment by Tojiro@gmail.com on 27 Feb 2011 at 4:41

GoogleCodeExporter commented 8 years ago

Original comment by Tojiro@gmail.com on 27 Feb 2011 at 6:18

GoogleCodeExporter commented 8 years ago
I think it's wrong...
A matrix multiplicated by a vector is a line by col multiplication :
dest[0] = mat[0]*x + mat[1]*y + mat[2]*z + mat[3]*w;
dest[1] = mat[4]*x + mat[5]*y + mat[6]*z + mat[7]*w;
dest[2] = mat[8]*x + mat[9]*y + mat[10]*z + mat[11]*w;
dest[3] = mat[12]*x + mat[13]*y + mat[14]*z + mat[15]*w;

Original comment by jg.germ...@gmail.com on 4 Aug 2011 at 8:50