Preparing a scaling matrix
The third transformation that can be performed on a 3D model is scaling. This allows us to change an object's size.
How to do it...
- Prepare three variables of type
float
namedx
,y,
andz
that will hold the scaling factor applied to a model in x (width), y (height), and z (depth) dimensions, respectively. - Create a variable of type
std::array<float, 16>
namedscaling_matrix
, in which a matrix representing the desired operation will be stored. Initialize elements of thescaling_matrix
array with the following values:- All elements initialize with a
0.0f
value - 0th element with a value stored in the
x
variable - 5th element with a value stored in the
y
variable - 10th element with a value stored in the
z
variable - 15th element with a
1.0f
value
- All elements initialize with a
- Provide values of all elements of the
scaling_matrix
variable to shaders (possibly via a uniform buffer or a push constant) or multiply it by another matrix to accumulate multiple operations in one matrix.
How it works...
Sometimes we...