GDL objects are built from basic shapes placed in a right-handed coordinate system managed by transformation commands.
An object always has 2 coordinate system:
- a global coordinate system (G): this is not modifiable, and it defines the main directions of the whole object, like a reference,
- and a local coordinate system (L): this can be moved, rotated and scaled with the transformation commands
The local system is moved incrementally: every transformation command previously defined stays in effect, until deleted.
When a trafo command is used, it goes into the transformation stack. The next transformation starts from the position and direction defined by the previous effective transformation, and so on. A transformation can be deleted any time, but by default, only in reversed order: the latest will be removed from the stack first, and the first will be removed last, as it’s at the bottom of the stack (LIFO: last in, first out system).
Use the DEL command to remove transformations from the stack. The number of transformations removed is set by the command’s parameter, and you can override the default LIFO system using additional parameters.
The placed basic shapes are always aligned with the actual position of the local system.
To stay on the elegant side, always empty the stack at the end of your script.
To move the coordinate system to a different position, use the following commands:
- 2D: ADD2
- 3D: ADD, ADDX, ADDY, ADDZ
Move coordinate system along the vector starting from origo, ending in the point (3, 2, 1):
add 3, 2, 1
The ADD command requires 3 parameters (for the 3 dimensions), while the other 3D commands move the system along the nominated axis. The “grouped” add command gets only one entry in the stack, so it can be deleted in one step. It can be substituted with the 3 single commands as well, but that means 3 places in the stack (the result will be the same, though).
To rotate the coordinate system around one of its axes (3D) or rotate the x-y plane related to global x axis (2D), use the following commands:
- 2D: ROT2
- 3D: ROTX, ROTY, ROTZ
The rotation is always defined in degrees, counter-clockwise.
- 2D: MUL2
- 3D: MUL, MULX, MULY, MULZ
Scaling means a distortion of the local coordinate system, when the input number for the command is not 1 unit.
Mirroring along one of the axes is possible when the input number is -1 in the parameter position of the chosen axis.
Read on in the GDL Manual’s section about transformation commands.
Lets see it in practice:
fill fillPoly1 gosub "drawPolygon" add2 1, 2 mul2 0.5, 1 fill fillPoly2 gosub "drawPolygon" del 2 add2 2, 0.5 rot2 30 fill fillPoly3 gosub "drawPolygon" del 2 end "drawPolygon": poly2_b 5, 1+2+4, penFg, penBg, 0, 0, 1, A, 0, 1, A, B, 1, 0, B, 1, 0, 0, -1 return