Allegro.cc Forums » Programming Questions » Filled circular sector

 Filled circular sector
 Polybios Member #12,293 October 2010 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!
 Arthur Kalliokoski Second in Command February 2005 Draw a line from center of circle to each end of the arc and floodfill? They all watch too much MSNBC... they get ideas.
 Polybios Member #12,293 October 2010 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!
 SiegeLord Member #7,827 October 2006 Polybios said: 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):#SelectExpand 1void al_draw_filled_pieslice(float cx, float cy, float r, float start_theta, 2 float delta_theta, ALLEGRO_COLOR color) 3{ 4 ALLEGRO_VERTEX vertex_cache[ALLEGRO_VERTEX_CACHE_SIZE]; 5 int num_segments, ii; 6 7 num_segments = fabs(delta_theta / (2 * ALLEGRO_PI) * ALLEGRO_PRIM_QUALITY * sqrtf(r)); 8 9 if (num_segments < 2) 10 return; 11 12 if (num_segments >= ALLEGRO_VERTEX_CACHE_SIZE) { 13 num_segments = ALLEGRO_VERTEX_CACHE_SIZE - 1; 14 } 15 16 al_calculate_arc(&(vertex_cache[1].x), sizeof(ALLEGRO_VERTEX), cx, cy, r, r, start_theta, delta_theta, 0, num_segments); 17 vertex_cache[0].x = cx; vertex_cache[0].y = cy; 18 19 for (ii = 0; ii < num_segments + 1; ii++) { 20 vertex_cache[ii].color = color; 21 vertex_cache[ii].z = 0; 22 } 23 24 al_draw_prim(vertex_cache, 0, 0, 0, num_segments + 1, ALLEGRO_PRIM_TRIANGLE_FAN); 25} You can also hack around it by using a thick outlined arc.EDIT: Fixed the code a bit... still untested though. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]
 Polybios Member #12,293 October 2010 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?
 SiegeLord Member #7,827 October 2006 Yes. Fixed now. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]
 Kibiz0r Member #6,203 September 2005 I recall there was a request for this forever.5 ago, people started talking about what to call it, then the thread died. ---https://www.allegro.cc/account/agreement <-- Read it, newbies.
 jmasterx Member #11,410 October 2009 al_draw_sectoral_draw_pie_sectoral_draw_circle_sectorare these good names? Agui GUI API -> https://github.com/jmasterx/Agui Agui 0.2 Release Thread -> https://www.allegro.cc/forums/thread/612830
 Arthur Kalliokoski Second in Command February 2005 I'd call it al_pie_slice(). They all watch too much MSNBC... they get ideas.
 SiegeLord Member #7,827 October 2006 Kibiz0r said: 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. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]
 Steve Terry Member #1,989 March 2002 mmmmmmmmmmmmmmmmmm pie ___________________________________[ Facebook ]Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.deBill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems
 Polybios Member #12,293 October 2010 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?
 SiegeLord Member #7,827 October 2006 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. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]
 Kibiz0r Member #6,203 September 2005 I'd call it al_pacman(). ---https://www.allegro.cc/account/agreement <-- Read it, newbies.
 Go to: Allegro Development Installation, Setup & Configuration Allegro.cc Comments Off-Topic Ordeals The Depot Game Design & Concepts Programming Questions Recent Threads