
Game Physics Cookbook
By :

The scale of a matrix is stored in the main diagonal of the matrix. The scale is stored as a vec3
. Each element of the vec3
represents the scale on the corresponding axis. Row and Column major matrices store scale information in the same elements:
The interesting thing with storing scale inside a matrix is that it shares some of the same elements as the rotation part of the matrix. Because of this, extracting the scale of a matrix may not always yield the numbers you would expect.
We're going to implement three functions. One function will retrieve the scale stored inside a matrix. The other two will return a new matrix, containing only the specified scale.
Follow these steps to set and retrieve the scale of a matrix:
matrices.h
:mat4 Scale(float x, float y, float z); mat4 Scale(const vec3& vec); vec3 GetScale(const mat4& mat);