| Lesson #4
This lesson will show you the simplicity of matrix handling
Although there are several mathematical methods of performing matrix modifications, you will not need to struggle with this !
TBGL has several commands to handle this topic:
TBGL_Scale can scale the current matrix by defined factor
The default value for X, Y and Z is 1.
If you want deform matrix in X axis by factor of two, you should use this:
Just keep in mind that this affects not only the size of rendered objects, but even the operations with translation.
TBGL_Translate serves to translate or move the matrix. For example, if you want to draw two objects, one at the beginning of the coordinate system, and other moved by 5 in X, you should do:
The last marix modifier is TBGL_Rotate. It allows you to rotate matrix by angle in degrees around axis defined by flag.
To rotate object by 10 degrees in X, 20 degrees in Y and 30 degrees in Z axis you will use this code:
It's also very important to know, that the order of performed operations matters. It is not the same to do this:
... and this:
The first one will move the object to position 5, 0, 0 and here the object will be rotated by 90 degrees around Y axis.
The second one will first rotate the current matrix by 90 degrees and then translate the object.
Attention ! This means the object will be finally located at position 0, 0, -5. Why ? Because we rotated the matrix by 90 degrees counterclock wise and then translated by the vector 5, 0, 0.
The last problem to solve is, how to isolate particular transformations for wished parts of code. The answer are TBGL_PushMatrix / TBGL_PopMatrix statements.
Look at this piece of code:
Will we have the same "axis confusion" problem like in the last code ?
No ! Because we isolated two matrixes from each other.
First object will be just rotated by 45° around Y axis, and the second one will be just translated.
TBGL_Push / PopMatrix is very powerful tool for robot-like animations.
You can nest the TBGL_PushMatrix up to the 32 levels.
It helps you to design simple animation skeleton.
For example like this:
So that's all I can tell you about matrix handling in TBGL for this time. Hope you like it, don't forget to explore the bundled source codes below !