I’m trying to do scale transformation with glMatrix for WebGL.
Scale transformations work nicely when I use the following order:
mat4.identity(mvMatrix);
mat4.translate(mvMatrix, [1, 1, 1]);
mat4.rotate(mvMatrix, degToRad(zAngle), [0, 0, 1]);
mat4.scale(mvMatrix, [2, 2, 2]);
But the object is not re-scaled when scaling transformation is performed first:
mat4.identity(mvMatrix);
mat4.scale(mvMatrix, [2, 2, 2]);
mat4.translate(mvMatrix, [1, 1, 1]);
mat4.rotate(mvMatrix, degToRad(zAngle), [0, 0, 1]);
Must the scaling happen always as the last transformation command?
Thanks,
Everton
See this answer to understand about “stacking” transformations in OpenGL. And of course, matrix multiplication isn’t commutative so you will get different results based on the order.