You have to decide the orientation (left/right), define Top, middle and bottom
point of triangle and compute deltas between top-bottom, top-middle,
bottom-middle. So you know about the height (y1-y2) of triangle, and that;s all
you need to know
I wrote the following:
typedef struct {
Int16 x;
Int16 y;
} polyPoint;
void gfxDrawFilledTriangle(polyPoint *points) {
int num = 3;
int i;
polyPoint *TOP = NULL;
polyPoint *DOWN = NULL;
polyPoint *MID = NULL;
float xstart, xend;
Int16 y;
float ktopdown, ktopmid, kmiddown;
for(i = num; i--;)
{
if(!TOP || TOP->y > points[i].y) TOP = &points[i];
if(!DOWN || DOWN->y < points[i].y) DOWN = &points[i];
}
for(i = num; i--;)
{
if(TOP == &points[i] || DOWN == &points[i])
continue;
MID = &points[i];
}
ktopdown = (float)(DOWN->x-TOP->x)/(float)(DOWN->y-TOP->y);
ktopmid = (float)(MID->x-TOP->x)/(float)(MID->y-TOP->y);
kmiddown = (float)(DOWN->x-MID->x)/(float)(DOWN->y-MID->y);
for(i = (int)TOP->y; i<=(int)DOWN->y; i++)
{
y = (i-TOP->y);
xstart = TOP->x+ktopdown*y;
if(i < MID->y) {
xend = TOP->x+ktopmid*y;
} else {
xend = MID->x+kmiddown*(i-MID->y);
}
WinDrawLine((Int16)xstart, i, (Int16)xend, i);
}
}
WinDrawLine should be replaced with something faster (direct memory access etc)
tom
On Thu, Aug 26, 2004 at 01:46:34PM -0000 Luc Le Blanc [EMAIL PROTECTED] wrote:
> On Wed, Aug 25, 2004 at 03:27:08AM -0400 Luc Le Blanc [EMAIL PROTECTED] wrote:
> > > I need to fill a trapezoidal area. i.e. a rectangle with unequal
> > > sides.
> > > I see no API for that, nor something like "WinFillArea" that
> > > would color
> > > every pixel around the given start location until hitting a
> > > different
> > color (like a paint tool in basic paint programs). Are there
> > > suitable
> > > APIs for that, or is there a graphics shared library freely
> > > available to do that?
>
>
> > the best way is to tesselate the polygon (you don't care about
> > covex/concave),
> > and fill all the triangles you created. Filling a triangle is
> > simple.
>
>
> Forgive my ignorance, but how do you fill a triangle. WinDrawTriangle???
>
>
> --
> Luc Le Blanc
> --
> For information on using the Palm Developer Forums, or to unsubscribe, please see
> http://www.palmos.com/dev/support/forums/
--
===============================================================================
Tomas Meinlschmidt, SBN3, MCT, MCP, MCP+I, MCSE, NetApp Filer & NetCache
gPG fp: CB78 76D9 210F 256A ADF4 0B02 BECA D462 66AB 6F56 / $ID: 66AB6F56
GCS d-(?) s: a- C++ ULHISC*++++$ P+++>++++ L+++$>++++ E--- W+++$ N++(+) !o
!K w(---) !O !M V PS+ PE Y+ PGP++ t+@ !5 X? R tv b+ !DI D+ G e>+++
h---- r+++ z+++@
===============================================================================
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/