2

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

Everton
  • 12,589
  • 9
  • 47
  • 59

1 Answers1

4

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.

Community
  • 1
  • 1
Ani
  • 10,826
  • 3
  • 27
  • 46