I was curious about this piece of code
vec2 scale;
scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );
scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );
Specifically, what is the meaning behind getting the length of a matrix row/column? What does that number represent?
Thanks!
A model matrix contains information about rotation translation and scale of the model.
In simple 2D case, it looks like this:
scaleX * cos(rot), -scaleY * sin(rot), translationX,
scaleX * sin(rot), scaleY * cos(rot), translationY
calculating length of columns of this matrix extracts the value of scale from it, for example, for the first column:
length = sqrt( (scaleX * cos(rot))^2 + (scaleX * sin(rot))^2 ) = scaleX
makc3d
3
matrix columns are essentially basis vectors of the frame that this matrix transforms vectors to when multiplied by them.