bresenham-line clib
Install with clib:
$ clib install jb55/bresenham-line.c
// drawing pixels
int draw_pixel(void *data, int x, int y) {
struct draw_mode *dm = (struct draw_mode*)data;
struct world *world = dm->world;
draw_pixel_at(world, x, y, dm->type);
return 0;
}
bresenham_line((void*)&draw_data, x0, y0, x1, y1, draw_pixel);
// collision detection
bresenham_line((void*)&cdata, x0, y0, x1, y1, collide_pixel);
arguments
-
data
a void pointer to data that's passed tosetPixel
-
x0
the starting x pixel -
y0
the starting y pixel -
x1
the ending x pixel -
y1
the ending y pixel -
setPixel
a function pointer that takes:data
a void pointer to data, originally passed in on the original callint
the x pixel that's setint
the y pixel that's set
if
setPixel
returnsBH_STOP_LINE
, it will stop the line drawing process. Otherwise, it will continue.