![]() |
|
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): 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 |
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 |
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. --- |
jmasterx
Member #11,410
October 2009
|
al_draw_sector are these good names? Agui GUI API -> https://github.com/jmasterx/Agui |
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 |
Steve Terry
Member #1,989
March 2002
![]() |
mmmmmmmmmmmmmmmmmm pie ___________________________________ |
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: "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Kibiz0r
Member #6,203
September 2005
![]() |
I'd call it al_pacman(). --- |
|