1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
typedef struct _points{
double x, y;
}Points;
static void Casteljau(double t,Points* tab,int nbpoints,double *rx,double *ry)
{
if (nbpoints == 1)
{
*rx = tab[0].x;
*ry = tab[0].y;
return;
}
Points subtab[nbpoints];
int i;
for(i=0;i<nbpoints-1;i++)
{
subtab[i].x = t*tab[i].x + (1-t)*tab[i+1].x;
subtab[i].y = t*tab[i].y + (1-t)*tab[i+1].y;
}
Casteljau(t, subtab, nbpoints-1, rx, ry);
}
void ShowBezier(SDL_Surface* screen, Points* tab, double tstep, int nbPoints, Uint32 couleur)
{
double t = 0.0;
Points p, plast;
plast.x=plast.y=0;
double rx = 0.0;
double ry = 0.0;
int i = 0;
while(t<=1.0)
{
Casteljau(t,tab,nbPoints,&rx,&ry);
p.x = (int)rx;
p.y = (int)ry;
if (i!=0)
ligne_Bresenham(screen,p,plast,couleur);
plast.x = p.x;
plast.y = p.y;
t+=tstep;
i++;
}
} |
Partager