|
|
Sx = (d * Vx) / Vz
Sy = (d * Vy) / Vz
'Sx - Screen X
'Sy - Screen Y
'Vx - Virtual X
'Vy - Virtual Y
'Vz - Virtual Z
'd - Distance of your head from the monitor
WINDOW command
at the start of your program or you can just take the Sx
and the Sy and add a ZeroX and ZeroY
when you are drawing the points on the screen.
WINDOW (-320, -240)-(320, 240)
Or
pset(ZeroX + Sx, ZeroY + Sy), 1
Sx and Sy and fill at that point. This
however, does create a problem when the face goes off of the edge of
the screen because it picks a fill point that is out of bounds.Once you get this code working you might want to sort the faces so you won't get weird looking faces. To do this you have to find the mean (average) Z coordinate dor each face. and according to the distance it is from (0,0) sort them from back to front.
To speed up your meshes you'll probably want to do some back face culling.
Culling is the removal of the faces that are facing away from you. To show
you what I mean, pick up a disk. Number the corners in a clockwise
direction like this:
1-----2
| |
| |
4-----3
Now, if you rotate it like this:
4-----1
| |
| |
3-----2
You may notice that the numbers have stayed in a clockwise direction, but if you flip
the disk like this:
4-----3
| |
| |
1-----2
the numbers go counter clockwise. We can use this to our advantage when drawing the
faces because they work the same way. The only setback is that you have to make sure
that all of the faces are defined in a clockwise direction.
The equation (found in the comp.graphics.algorithms FAQ) is simple...
c = (x1-x2)*(y3-y2)-(y1-y2)*(x3-x2)
x1,y1, x2,y2, x3,y3 = the first three points of the polygon.
Thats really all there is to drawing polygons on the screen. It gets a little more
complex when you want to place a camera and/or rotate the objects.
|
|
|
|
|
|