• Welcome to Dark Bit Factory & Gravity.
 

Use your imagination here..

Started by Shockwave, August 17, 2006

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Shockwave

The routine was quite easy to code for me, but that is because I already had something to base it upon. It's not unlike coding an affine texture map. Don't be scared, it's pretty easy.

First of all you need to look at the information you have on the face you are about to draw.
All you know are where the 4 corners are, so you have 4 pairs of X+Y co-ordinates.

To make it very simple, class two of them as the top and two as the bottom.
From these we can calculate the top and bottom edges.
In the program a constant is set for the amount of subdivisions, it works something like this.

This pseudo code would calculate one of the edges;

x_top = X1
y_top = X1

Reciprocal_ X        = (X1 - X2 ) / Subdivisions
Reciprocal_ Y        = (Y1 -Y2 ) / Subdivisions

for loop = 1 to subdivisions
TOP_X_EDGE_STORE (LOOP) = x_top
TOP_Y_EDGE_STORE (LOOP) = y_top
  ytop = ytop+Reciprocal_Y
  xtop = ytop+Reciprocal_X >:D
next


Do the same for the bottom, these are the only points we need to physically store for the face, they can be plotted while they are being calculated.
Then another process to interpolate between the edges happens to draw the middle of the face and voila.
See it's not too bad.
Shockwave ^ Codigos
Challenge Trophies Won: