Hi guys
I've come to a halt, i can't seem to figure out an efficient method of implementing a triangle scan line algorithm or even a messy one that works. So far my function can take 3 points and obtain coordinates needed to connect the points, these coordinates are used for my triangle's edges. Now to use these edges in the scan line algorithm i need to figure out which edge coordinates belong on the left and right. I've managed to get a flat base triangle filled but any other triangle cases just have me stumped for logic :-(
One idea i had was to concatenate the edge lists of 2 smaller sides of a triangle and somehow find which side it belongs to.
Code:void Core::drawTriangle(Point a, Point b, Point c) { vector<Point> AB; vector<Point> AC; vector<Point> BC; vector<Point> lEdge; vector<Point> rEdge; makeLine(a, b, &AB); makeLine(a, c, &AC); makeLine(b, c, &BC); //this works for an equilateral triangle int i = 0; for (int y = a.y; y < b.y; y++) { for (int x = AC[i].x; x < AB[i].x; x++) { putpixel(x, y, 0, 200, 0, 0); } i++; } }



LinkBack URL
About LinkBacks


