Matrix3D multiplication operator bug

I believe multiplication operator in Matrix3D  has a bug.

mat and m2 are swapped. It should be like this:


        return Matrix3D(
            mat[0] * m2[0] + mat[1] * m2[4] + mat[2] * m2[8] + mat[3] * m2[12],
            mat[0] * m2[1] + mat[1] * m2[5] + mat[2] * m2[9] + mat[3] * m2[13],
            mat[0] * m2[2] + mat[1] * m2[6] + mat[2] * m2[10] + mat[3] * m2[14],
            mat[0] * m2[3] + mat[1] * m2[7] + mat[2] * m2[11] + mat[3] * m2[15],
            mat[4] * m2[0] + mat[5] * m2[4] + mat[6] * m2[8] + mat[7] * m2[12],
            mat[4] * m2[1] + mat[5] * m2[5] + mat[6] * m2[9] + mat[7] * m2[13],
            mat[4] * m2[2] + mat[5] * m2[6] + mat[6] * m2[10] + mat[7] * m2[14],
            mat[4] * m2[3] + mat[5] * m2[7] + mat[6] * m2[11] + mat[7] * m2[15],
            mat[8] * m2[0] + mat[9] * m2[4] + mat[10] * m2[8] + mat[11] * m2[12],
            mat[8] * m2[1] + mat[9] * m2[5] + mat[10] * m2[9] + mat[11] * m2[13],
            mat[8] * m2[2] + mat[9] * m2[6] + mat[10] * m2[10] + mat[11] * m2[14],
            mat[8] * m2[3] + mat[9] * m2[7] + mat[10] * m2[11] + mat[11] * m2[15],
            mat[12] * m2[0] + mat[13] * m2[4] + mat[14] * m2[8] + mat[15] * m2[12],
            mat[12] * m2[1] + mat[13] * m2[5] + mat[14] * m2[9] + mat[15] * m2[13],
            mat[12] * m2[2] + mat[13] * m2[6] + mat[14] * m2[10] + mat[15] * m2[14],
            mat[12] * m2[3] + mat[13] * m2[7] + mat[14] * m2[11] + mat[15] * m2[15]);
 

So, if this were just an ordinary 4x4 matrix, then yes, I would agree -- the version you wrote down is the one found in math textbooks and the one I know.

However, I hesitate to just go ahead and fix this. The Matrix3D class is a 4x4 matrix but representing 3D space. Apparently this is how you represent 3D graphics in homogeneous coordinates / projective geometry for computer graphics. Unfortunately I am not really familiar with the topic, but this seems to be different from the classic cartesian cordinates / euclidean space. I can imagine that in this realm, maybe special conventions apply, which is why it is implemented the way it is?

Any graphics expert here who knows this?

Using "homogeneous coordinates" is a trick, which allows the translation to be handled like the other transforms, i.e. as a matric multiplication. The multiplication however follows the normal rules, hence the formular above should be performing a 4x4 matrix multiplication.

 

Transformation matrix is usually calculated like this:

matrix = projection * view * model;

Unfortunately due to this bug one can not use multiplication operator to calculate matrix.

 

 

If all else fails, use GLM (http://glm.g-truc.net/0.9.6/index.html)

Thanks all for your comments, they are consistent with other things I have found today on the topic.

So yes, this operator* should be just a normal matrix multiplication, like the one we are all familiar with, and therefore was implemented the wrong way around.

I fixed it on the newest tip.