Preparing a translation matrix
Basic operations that can be performed on 3D models include moving the objects in a desired direction for a selected distance (number of units).
How to do it...
- Prepare three variables of type
float
namedx
,y
, andz
, and initialize them with the amount of translation (movement distance) applied to the object along thex
(right/left),y
(up/down), andz
(near/far) directions respectively. - Create a variable of type
std::array<float, 16>
namedtranslation_matrix
that will hold a matrix representing the desired operation. Initialize elements of thetranslation_matrix
array with the following values:- All elements initialize with a
0.0f
value - 0th, 5th, 10th, and 15th elements (main diagonal) with a
1.0f
value - 12th element with a value stored in the
x
variable - 13th element with a value stored in the
y
variable - 14th element with a value stored in the
z
variable
- All elements initialize with a
- Provide values of all elements of the
translation_matrix
variable to shaders (possibly via a uniform buffer...