You divide by Z - or in the case of modern graphics you divide by W. This is the perspective projection.
Before matrices were widely used this was the formula used for dividing by Z.
But with matrices this can be done quite easily and it can also then be added into the graphics pipeline that already uses matrices quite heavily. The advantage is you don't have to change your projection function significantly to perspective project your vertices into screen space.
You really need to buy a book on the mathematics of 3D graphics in order to understand how it all works.
Translation is really just this:
But because of the way we multiply or concatenate matrices a 4x4 homogneous matrix works very well for this:
A simple concatenation function (and not by any means the fastest) for a 4x4 matrix. Matrix is assumed to be a 4x4 array - again not the best way.
void MatMultiply(float mat1,float mat2,float result)
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
for (int k=0;k<4;k++)
And a simple world transform function.
But thankfully in DirectX you don't need to worry about all of this because it is done for you. No more tracking of model, world, view, and screen vertexes/coordinates. But the above code is from a software 3D engine I wrote quite some time ago.
void WorldTransform(vertex *vtxs,int numvtxs,float wm)
for (int i=0;i<numvtxs;i++)