Skip to main content
gamedev.net
🔒 Locked

s/c-buffer spans calculation

Started by Vladimir 0 replies 750+ views
Original Post
Vladimir
Vladimir
Hi, Can anybody explain a bit how to calculate spans from given triangle. Should I transform every triangle into screen coordinates and then devide it by several horizontal planes for every scanline and find points of intersections or there is another faster way. Thank You Vladimir
Ped
Ped
- transform triangle into screen space
- now sort vertices to get the most upper one.
- do interpolation from the most upper to those 2 at bottom
i.e. having [x1,y1] at top, and [x2,y2] [x3,y3] at bottom:
ix1(y) = x1 + ((x2-x1)/(y2-y1)) * (y-y1) // this is formula to compute iterpolated x coordinate from point 1 to point 2 at line y
(x2-x1)/(y2-y1) does represent slope of line
if you are proceeding from line y1 to y2 step by step,
you don''t have to do this multiplication, but you may do

ix1 = x1; slope = (x2-x1)/(y2-y1);
for ( y = y1; y <= y2; y++ ) {
ix1 += slope;
}

the same thing with line from point 1 to point 3 ...
You probably noticed, that this is very similar to line drawing... indeed it is.

Then when you reach either y2(y3) line, you will have to change the first(second) line to line from point 2(3) to point 3(2) ...

Also there are some special case, when y1==y2, or y2==y3, etc... get paper and draw few triangles to make it clear for yourself...

Have a fun. (I actually never liked this stuff, but got trough it)

---------------------------------------------------
Ped - Peter Helcmanovsky - 7 Gods demo group
http://7gods.rulez.sk
First Sight Entertainment - http://members.xoom.com/fseteam
---------------------------------------------------
---------------------------------------------------Ped - Peter Helcmanovsky - 7 Gods demo grouphttp://7gods.rulez.skFirst Sight Entertainment - http://members.xoom.com/fseteam---------------------------------------------------

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.