SmallBASIC GuideThe language | Programming Tips | Commands | System | Graphics & Sound | Miscellaneous | File system | Mathematics | 2D Algebra | Strings | Console | Glossary |
2D & 3D graphics transformations
2D & 3D graphics transformations can represented as matrices.
(c=cosč, s=sinč)
Command:
M3IDENT BYREF
m3x3
Resets matrix (Identity)
| 1 0 0 |
| 0 1 0 |
| 0 0 1 |
Command:
M3ROTATE
BYREF m3x3, angle [, x, y]
Rotate by angle with center x,y
| c s 0 |
| -s c 0 |
| * * 1 |
Command:
M3SCALE
BYREF m3x3, x, y, Sx, Sy
Scaling
| Sx 0 0 |
| 0 Sy 0 |
| * * 1 |
Command:
M3TRANS
BYREF m3x3, Tx, Ty
Translation
| 1 0 0 |
| 0 1 0 |
| Tx Ty 1 |
Command:
M3APPLY
m3x3, BYREF poly
Apply matrice to poly-line
Additional information:
| 1 0 0 |
| 0 -1 0 | = reflection on x
| 0 0 1 |
| -1 0 0 |
| 0 1 0 | = reflection on y
| 0 0 1 |
3D-Graphics Matrices:
| 1 0 0 Tx |
| 0 1 0 Ty | = translation
| 0 0 1 Tz |
| 0 0 0 1 |
| Sx 0 0 0 |
| 0 Sy 0 0 | = scaling
| 0 0 Sz 0 |
| 0 0 0 1 |
| 1 0 0 0 |
| 0 c -s 0 | = rotation on x
| 0 s c 0 |
| 0 0 0 1 |
| c 0 s 0 |
| 0 1 0 0 | = rotation on y
| -s 0 c 0 |
| 0 0 0 1 |
| c -s 0 0 |
| s c 0 0 | = rotation on z
| 0 0 1 0 |
| 0 0 0 1 |
Any change to matrix will combined with its previous value.
DIM poly(24)
DIM M(2,2)
...
M3IDENT M
M3ROTATE M, pi/2, 0, 0
M3SCALE M, 0, 0, 1.24, 1.24
...
' Draw the original polyline
DRAWPOLY poly
...
' Draw the polyline
' rotated by pi/2 from 0,0 and scaled by 1.24
M3APPLY M, poly
DRAWPOLY poly
[Prev] [Next]