function rotateZ3D(alpha)
rad = alpha * math.pi/180
sin = math.sin(rad)
cos = math.cos(rad)
for a = 1, #nodes, 1 do
node = nodes[a]
x = node.x
y = node.y
node.x = (x * cos - y * sin)
node.y = (y * cos + x * sin)
end
end
node.x = (x * cos - y * sin)
node.y = (y * cos + x * sin)
is a matrix multiplication of the matrix \[\begin{pmatrix}
\cos\alpha & -\sin\alpha\\
\sin\alpha & \cos\alpha
\end{pmatrix}\] with the vector \[\begin{pmatrix}node.x \\ node.y\end{pmatrix}\].
Matrices (or rather matrix-vector-products) are just a way to write multiple equations using less characters (mathematicians are lazy people). There is nothing magical about them.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.
vrld is right, that's actually 2D matrix rotation. But since that's a rotation over a single 3D axis and you need several of these to obtain any 3D rotation, it's likely that you can obtain faster results by doing the whole 3D rotation in one go, using a 3D rotation matrix rather than a composition of 2D rotations, because you do the sines and cosines just once and apply the result to all vectors.
Tanner wrote:Since this seems to be the direction you're headed in, here's a guide on how to write a software renderer from scratch. https://github.com/ssloy/tinyrenderer/wiki