Mail Archives: djgpp/2003/01/29/08:00:12
Hi all,
my problem is, that I want to draw a something like a pie (circle
segment) to some bitmap, but the current code doesn't work. Can
somebody please tell me how to handle the fixed class correctly?
This is extraction of the current code:
typedef struct tagPOINT
{
int x;
int y;
}POINT;
:
typedef struct tagPIE
{ POINT ptCenter; // center of drawing the arc (pie)
int nRadius; // inner radius
int nDiameter; // width of arc (pie)
float rBeginAngle; // start angle of pie
float rEndAngle; // end angle of pie
}PIE;
:
#define FACTOR_ANGLE_TO_ALLEGRO_ANGLE 0.7111111111 // 256/360 =
0.71111...
:
:
somewhere in the code:
:
PIE pie; // this struct is filled with valid data somewhere else
and
//rBeginAngle < rEndAngle !
:
fix fixBegin, fixEnd, fixAngle;
fixBegin = ::ftofix(pie.rBeginAngle * FACTOR_ANGLE_TO_ALLEGRO_ANGLE);
fixEnd = ::ftofix(pie.rEndAngle * FACTOR_ANGLE_TO_ALLEGRO_ANGLE);
int nCntr = 0;
nCoord[14400];
// draw contours of pie / circle segment only
for(int nRadius=pie.nRadius;
nRadius <= (pie.nRadius + pie.nDiameter);
nRadius += pie.nDiameter)
{
// the following never starts to run - why??
for(fixAngle=fixBegin; fixAngle != fixEnd; fixAngle += ftofix(0.1))
{
fix fixSIN = sin(fixAngle);
fix fixCOS = cos(fixAngle);
fix fixX = fixCOS * fix(nRadius);
fix fixY = fixSIN * fix(nRadius);
nCoord[nCntr++] = (int)pie.ptCenter.x + (int)fixX;
nCoord[nCntr++] = (int)pie.ptCenter.y + (int)fixY;
}
}
// use allegro's polygon function to draw the segment...
polygon(bmpTarget, nCntr/2, nCoord, clColor);
Maybe I'm too stupid, but I'm really interested in what's going wrong
here.
Please help!
Thanks in advance,
Martin
- Raw text -