K its been a while but heres what i did in qbasic:
first things first:
to set up a simple view port with an origin you need do create the following variables
X_origin = screen resolution x / 2
y_origin = screen resolution y / 2
The reason you do this is because your 2d display surface has the x and y "0" as the upper most left most pixel on your screen (top left is 0,0) for a perspective 3d view the focus point or the origin needs to be the center of the view.
now for the perspective math (Its really easy.)
screenx = (x/z) + X_origin
screeny = (y/z) + Y_origin
thats the bare bones essential of how a 3 coord vertex is transformed to a 2d view port... mind boggling huh?
now you could make that more interesting by adding variables to control camera location:
well add in
vx vy vz
to locate viewer location
screenx = (x - vx)/(z - vz) + X_origin
screeny = (y - vy)/(z - vz) + Y_origin
basically all you are doing is teaching the computer how to "draw" 3d images on a 2d surface. Thats all any system does because that all that can be accomplished with a flat surface is a 2d image made to look 3d.
were the math gets tricky is rotation... basically you have to have a formula that can rotate vertexes in a manner that they dont get deformed and mangled... trust me it took me a while to get it right since math isnt one of my strongest points... especially now.
to traslate (move) verts one direction or another is simple... add the translate value to the vert data then update the vert
x = x + translate_x to move on the x axis
z = z + translate_z to move on the z axis
y = y + translate_y to move on the y axis...
simple....
heres rotation:
save the original coords to a different vairable. because youll need them as you rotate on each axis
old x,y,z
set the rotation values "how much to rotate for x/y/z"
rotx, rotz, roty (in degrees)
oldx = z
oldy = y
oldz = z
to rotate on x axis
y = (sin(rotx) * oldz) + (cos(rotx) * oldy)
z = (cos(rotx) * oldz) - (sin(rotx) * oldy)
to rotate on the y axis:
x = (cos(roty) * oldx) - (sin(roty) * oldz)
z = (sin(roty) * oldx) + (cos(roty) * oldz)
and the z axis:
x = (cos(rotz) * oldx) + (sin(rotz) * oldy)
y = (cos(rotz) * oldy) - (sin(rotz) * oldx)
not so simple... Im not really sure of the breakdown of them myself... if your better at math then me then youll have an easier time with it.
When i wrote my 3d drawing program way back when i found the formulas and basically plugged them in... im in no way a math wiz nor an expert at any of the above math...
anyway hopefully that gives you something to ponder or playwith...