
3D
The cube we drawed earlier has not onley 2 but 3 coordinates for each
point. This third coord is the depth coord (z). And the those three
coords has to be calculated into 2 coords for displaying on screen. The
way to do this is in the formula:
XP=(x*zmax)/(zmax-z)
where:
XP is the x or y coord to put on screen x is the x or y coord of the point z is the z coord(depth) of the point zmax is the z depthThis calculation has to be done for both x and y coords. But this formula is quite slow (because of many divs) but there are several ways to optimize it.
Movement
This is the absolute easiest effect of them all to move an object simply
add the movement in the X-direction to all X-coords of the points and the
movement in Y-dirction to all Y-coords of the points and the same with Z.
I don't think I have to put out this formula but here it is any way:
Xnew=Xold+Xmv
where:
Xnew is the new X(or Y or Z) coord Xold is the old X(or Y or Z) coord Xmv is the movement (X, Y or Z)Rotation
a2=a*Cos(P)-b*Sin(P)
b2=b*Cos(P)-a*Sin(P)
So to rotate the object round the x-axis (horisontal line) you use
a=z coord b=y coord p=angle round x-axisand this have to be done for each point in the object.
Hidden faces
When you do filled vectors you don't want the computer to draw all the
faces wich don't are seen. The sectret in doing this is to make all the
faces in a clokwise order, when they are closest to the screen. E.g:

Now before you draw the face you just have to check if the first three
points still are clockwise. If not they are facing away from you then
don't draw it (if the vector isn't transparent). The math for this is:
((Cx-Bx)*(Cy-By))-((Bx-Ax)*(By-Ay))
if this is positive then don't draw that face.
Fading
To make a face fade when it goes in to the depth, you can use the
number gotten from the hiden faces formula and use it to choose the
color of the face. To get the maximum value put one face straight
away from the screen (anti clockwise) then calculate the number for
that face (using the formula) and then you can use that number to
calculate diffrent shades or inks.
Scaling
This is used to make an object bigger or smaller but keeping the same
form. Doing this it quite easy, you just multiply each of the X and Y
coords with a scaling factor like this:
Xnew=Xold*Xsc
where:
Xsc is the scaling factor.
A factor greater than 1 strech the object and a factor between 0 and
1 shrinks it. You can also use negative numbers to produce a varety of
reflections, try some diffrent values for some cool fx.
Copyright (c) 1998 Martin Håkansson aka Mr Belfit.