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 48 49 50 51 52 53 54 55
|
void Line(SDL_Surface* surf,int x1,int y1, int x2,int y2,Uint32 couleur) // Bresenham
{
int x,y;
int Dx,Dy;
int xincr,yincr;
int erreur;
int i;
Dx = abs(x2-x1);
Dy = abs(y2-y1);
if(x1<x2)
xincr = 1;
else
xincr = -1;
if(y1<y2)
yincr = 1;
else
yincr = -1;
x = x1;
y = y1;
if(Dx>Dy)
{
erreur = Dx/2;
for(i=0;i<Dx;i++)
{
x += xincr;
erreur += Dy;
if(erreur>Dx)
{
erreur -= Dx;
y += yincr;
}
SDL_PutPixel32(surf,x, y,couleur);
}
}
else
{
erreur = Dy/2;
for(i=0;i<Dy;i++)
{
y += yincr;
erreur += Dx;
if(erreur>Dy)
{
erreur -= Dy;
x += xincr;
}
SDL_PutPixel32(surf,x, y,couleur);
}
}
SDL_PutPixel32(surf,x1,y1,couleur);
SDL_PutPixel32(surf,x2,y2,couleur);
} |
Partager