Preparing a rotation matrix
When we create a 3D scene and manipulate its objects, we usually need to rotate them in order to properly place and orient them among other objects. Rotating an object is achieved with a rotation matrix. For it, we need to specify a vector, around which rotation will be performed, and an angle--how much rotation we want to apply.
How to do it...
- Prepare three variables of type
float
namedx
,y
, andz
. Initialize them with values that define an arbitrary vector, around which rotation should be performed. Make sure the vector is normalized (has a length equal to1.0f
). - Prepare a variable of type
float
namedangle
and store an angle of the rotation (in radians) in it. - Create a variable of type
float
namedc
. Store a cosine of the angle in it. - Create a variable of type
float
nameds
. Store a sine of the angle in it. - Create a variable of type
std::array<float, 16>
namedrotation_matrix
that will hold a matrix representing the desired operation. Initialize elements...