Good job!
The last example on that page can also be handy:
If you change that a bit, to this:
You will be able to create matrices based on position and rotation without the need of elements.
function createMatrix(x, y, z, rx, ry, rz)
rx, ry, rz = math.rad(rx), math.rad(ry), math.rad(rz)
local matrix = {}
matrix[1] = {}
matrix[1][1] = math.cos(rz)*math.cos(ry) - math.sin(rz)*math.sin(rx)*math.sin(ry)
matrix[1][2] = math.cos(ry)*math.sin(rz) + math.cos(rz)*math.sin(rx)*math.sin(ry)
matrix[1][3] = -math.cos(rx)*math.sin(ry)
matrix[1][4] = 1
matrix[2] = {}
matrix[2][1] = -math.cos(rx)*math.sin(rz)
matrix[2][2] = math.cos(rz)*math.cos(rx)
matrix[2][3] = math.sin(rx)
matrix[2][4] = 1
matrix[3] = {}
matrix[3][1] = math.cos(rz)*math.sin(ry) + math.cos(ry)*math.sin(rz)*math.sin(rx)
matrix[3][2] = math.sin(rz)*math.sin(ry) - math.cos(rz)*math.cos(ry)*math.sin(rx)
matrix[3][3] = math.cos(rx)*math.cos(ry)
matrix[3][4] = 1
matrix[4] = {}
matrix[4][1], matrix[4][2], matrix[4][3] = x, y, z
matrix[4][4] = 1
return matrix
end
function getPositionFromMatrixOffset(m, offX, offY, offZ)
local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]
local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2]
local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3]
return x, y, z
end
And with that you can make the most crazy stuff, for example: 3D (rotated) dx effects that are not attached to an element.
local m = createMatrix(x1, y1, z1, rx, ry, rz)
local x2, y2, z2 = getPositionFromMatrixOffset(m, offX, offY, offZ)