Hi guys,
how do I draw a filled circular sector aka pieslice with Allegro 4.9/5.0?
I suppose, I need some combination of al_calculate_arc and the low level primitives routines... But how exactly should I do this?
Any help is highly appreciated!
Draw a line from center of circle to each end of the arc and floodfill?
That was my first thought, too, but there is no floodfill in Allegro 4.9...!
All the pixel-reading, which a floodfill would have to do, would be really slow on textures, I guess.
I should add, I need it to be quite ... fast!
I suppose, I need some combination of al_calculate_arc and the low level primitives routines... But how exactly should I do this?
That is the proper way... it'd be something like this (created by mushing al_draw_filled_ellipse and al_draw_arc)(untested):
You can also hack around it by using a thick outlined arc.
EDIT: Fixed the code a bit... still untested though.
Oh thank you so much!
It seems that there is always a vertex drawn which is at 0,0; that means the pieslice is crudely extended to the left-upper corner of the screen.
Maybe you meant to pass "&(vertex_cache[1].x)" to al_calculate_arc?
Yes. Fixed now.
I recall there was a request for this forever.5 ago, people started talking about what to call it, then the thread died.
al_draw_sector
al_draw_pie_sector
al_draw_circle_sector
are these good names?
I'd call it al_pie_slice().
I recall there was a request for this forever.5 ago, people started talking about what to call it, then the thread died.
The implementation for the outlined pieslice/sector/w/e is very non-trivial, so I haven't had the time to implement it.
mmmmmmmmmmmmmmmmmm pie
Thanks again, SiegeLord!
One question though: Could you (or anyone else) explain why you take the square root of the radius there in order to calculate the number of segments?
It's... complicated. I don't remember exactly how I came up with it. The last thing I remember is that it is an approximation to this formula:
Which calculates the number of segments by limiting the length of the KB segment in the diagram on this page.
I'd call it al_pacman().