Mail Archives: djgpp/1999/05/24/03:44:04
On Sun, 23 May 1999 14:09:11 +0100, "Justin Blackwell"
<jx AT elysiumdco DOT freeserve DOT co DOT uk> wrote:
>Anyone got any good code on how to draw triangles - not polygons or any
>other shapes - just triangles :)
>
>C++ code is good, but any nice documents would be greatly appreciated.
Sort the triangle so that the y increases with each point. Now there
are two triangles to draw. The hypotenuse (The side that goes from
the highest to the lowest point) is the edge for each triangle.
Now take the x ratio of each side (as float). Start the first
triangle; add onto x the ratio each y for the hypotenuse and the
favoured edge. Swap the sides if necessary and draw the segment;
continue up to the middle point. Do the same for the second triangle
to the end point.
There are many ways to enhance this, but that's the basic algorithm.
The PCGPE (Available at x2ftp.oulu.fi) has a file "tut9.txt", which
explains a better way, although I think he uses quads instead. tut3
has a lines algorithm that can be applied to triangles.
- Burton Radons, loth AT cow-net DOT com
Vancouver Island, British Columbia, Canada
(main) http://csoft.net/~loth/index.shtml
- Raw text -