-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Some very helpful input from Michael Fairbank (mike12f) who is involved with Matrix Brandy via stardot PM:
I see how you've done the arc/sector/segment code now at https://github.com/hoglet67/PiTubeDirect/blob/indigo-dev/src/framebuffer/primitives.c The key code there is perhaps this snippet:
void prim_fill_chord(screen_mode_t *screen, int xc, int yc, int x1, int y1, int x2, int y2, plotcol_t colour) {
// Draw the arc that bounds the chord
prim_draw_arc(screen, xc, yc, x1, y1, x2, y2, colour);
// The arc drawing sets the arc_end_x/y to the arc endpoint (in screen coordinates)
prim_draw_line(screen, x1, y1, arc_end_x, arc_end_y, colour, 0);
// Fill the interior
prim_fill_interior(screen, arc_fill_x, arc_fill_y, colour);
}
void prim_fill_sector(screen_mode_t *screen, int xc, int yc, int x1, int y1, int x2, int y2, plotcol_t colour) {
// Draw the arc that bounds the sector
prim_draw_arc(screen, xc, yc, x1, y1, x2, y2, colour);
// The arc drawing sets the arc_end_x/y to the arc endpoint (in screen coordinates)
prim_draw_line(screen, arc_end_x, arc_end_y, xc, yc, colour, 0);
prim_draw_line(screen, xc, yc, x1, y1, colour, 0);
// Fill the interior
prim_fill_interior(screen, arc_fill_x, arc_fill_y, colour);
}
I can see why there are some bugs there with slim sectors not being filled properly.
The way I've done it for MatrixBrandy is inspired by the way the graphics rom does it (documented by TobyLobster recently); however even with his documented code, I still could not understand they way they did it exactly! But I got the gist of it - they loop through filling the whole circle, but then filter each pixel as either "in the sector" or not. The way it checks whether a pixel is "in the sector" is as follows - they just check which side of the bounding straight lines of the sector that pixel is on. If it is on the correct side of both lines then you plot the point - otherwise you don't plot it. There are a couple more details to it than that, of course; but that is the gist. The elegant thing is that the same method works for an arc, and for a segment, and for a sector. Plus, you only get a subset of pixels that occurred in the original circle - otherwise when you draw an arc, it can draw slightly displaced pixels, when compared to the original circle it is attempting to trace.
So those are the benefits of the way I did it in MatrixBrandy.