In this post we shall understand affine transformations interactively the three kinds of affine transformations: Scale, Translate and Rotation on X, Y and Z axes as discussed in the previous post.
The GUI has two windows - Console Window with OpenGL context. This renders a Cube with a texture having each of the 6 faces labeled as below.
Launch Lessons\Lesson06.exe. Use the input dialog to change values. The cube also be rotated using X,Y, Z keys and using Mouse inputs.
Input Dialog
Provides an user interface to experiment interactively - scaling, translation and rotation. First input is provided in the input text boxes. It's submitted for rendering the cube when Apply button is clicked. The cumulative value is updated in the caption. Reset button resets values. Both + and -ve values can be submitted. Note:- The values are applied when the associated checkboxes are checked.
Camera
As we are still passing Identity matrix for view and projection matrices, the camera is sitting at the origin (0,0,0) looking down on -Z axis. In this scenario, the back face is visible with x=0, y=0, z=-0.5.
Scale
First rotate cube by 30 degree pitch and 30 degree yaw. Enter different values for scaling in x, y and z axes.
Translate
First rotate cube by 30 degree pitch and 30 degree yaw. Enter different values for translation in x, y and z axes.
Rotate
As noted earlier, the rotation happens in counter clockwise direction along the axis. The diagram below maps faces to numbers.
Rotate the cube by 90 degrees increments. The sequences of faces that should display are as below.
Rotation around Y axis
Rotate the cube by 90 degrees increments. The sequences of faces that should display are as below.Rotation around Z axis
Rotate the cube by 90 degrees increments. The sequences of faces that should display are as below.
Order of Transformation
Following order is used:
- Scale
- Rotate by Z,X,Y
- Translate
Note in code, the matrix would be computed in reverse order as below.
M = mat4(1);
M = translate(M, translateby);
M = rotate(M, radians((float)(yaw)), vec3(0.0f, 1.0f, 0.0f));
M = rotate(M, radians((float)(pitch)), vec3(1.0f, 0.0f, 0.0f));
M = rotate(M, radians((float)(roll)), vec3(0.0f, 0.0f, 1.0f));
M = scale(M, scaleby);
No comments:
Post a Comment