<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Filled circular sector</title>
		<link>http://www.allegro.cc/forums/view/605684</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 03 Dec 2010 04:31:06 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi guys,</p><p>how do I draw a filled circular sector aka pieslice with Allegro 4.9/5.0?</p><p>I suppose, I need some combination of al_calculate_arc and the low level primitives routines... But how exactly should I do this? <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p>Any help is highly appreciated! <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Polybios)</author>
		<pubDate>Thu, 02 Dec 2010 03:43:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Draw a line from center of circle to each end of the arc and floodfill?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 02 Dec 2010 03:45:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That was my first thought, too, but there is no floodfill in Allegro 4.9...!</p><p>All the pixel-reading, which a floodfill would have to do, would be really slow  on textures, I guess.</p><p>I should add, I need it to be quite ... fast! <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Polybios)</author>
		<pubDate>Thu, 02 Dec 2010 03:54:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605684/892718#target">Polybios</a> said:</div><div class="quote"><p>
I suppose, I need some combination of al_calculate_arc and the low level primitives routines... But how exactly should I do this? <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div></div><p>
That is the proper way... it&#39;d be something like this (created by mushing al_draw_filled_ellipse and al_draw_arc)(untested):</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k1">void</span> al_draw_filled_pieslice<span class="k2">(</span><span class="k1">float</span> cx, <span class="k1">float</span> cy, <span class="k1">float</span> r, <span class="k1">float</span> start_theta,
<span class="number">  2</span>   <span class="k1">float</span> delta_theta, <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> color<span class="k2">)</span>
<span class="number">  3</span><span class="k2">{</span>
<span class="number">  4</span>   <a href="http://www.allegro.cc/manual/ALLEGRO_VERTEX"><span class="a">ALLEGRO_VERTEX</span></a> vertex_cache<span class="k2">[</span><a href="http://www.allegro.cc/manual/ALLEGRO_VERTEX_CACHE_SIZE"><span class="a">ALLEGRO_VERTEX_CACHE_SIZE</span></a><span class="k2">]</span><span class="k2">;</span>
<span class="number">  5</span>   <span class="k1">int</span> num_segments, ii<span class="k2">;</span>
<span class="number">  6</span>   
<span class="number">  7</span>   num_segments <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_303.html" target="_blank">fabs</a><span class="k2">(</span>delta_theta <span class="k3">/</span> <span class="k2">(</span><span class="n">2</span> <span class="k3">*</span> <a href="http://www.allegro.cc/manual/ALLEGRO_PI"><span class="a">ALLEGRO_PI</span></a><span class="k2">)</span> <span class="k3">*</span> <a href="http://www.allegro.cc/manual/ALLEGRO_PRIM_QUALITY"><span class="a">ALLEGRO_PRIM_QUALITY</span></a> <span class="k3">*</span> sqrtf<span class="k2">(</span>r<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>
<span class="number">  9</span>   <span class="k1">if</span> <span class="k2">(</span>num_segments <span class="k3">&lt;</span> <span class="n">2</span><span class="k2">)</span>
<span class="number"> 10</span>      <span class="k1">return</span><span class="k2">;</span>
<span class="number"> 11</span>   
<span class="number"> 12</span>   <span class="k1">if</span> <span class="k2">(</span>num_segments <span class="k3">&gt;</span><span class="k3">=</span> <a href="http://www.allegro.cc/manual/ALLEGRO_VERTEX_CACHE_SIZE"><span class="a">ALLEGRO_VERTEX_CACHE_SIZE</span></a><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 13</span>      num_segments <span class="k3">=</span> <a href="http://www.allegro.cc/manual/ALLEGRO_VERTEX_CACHE_SIZE"><span class="a">ALLEGRO_VERTEX_CACHE_SIZE</span></a> <span class="k3">-</span> <span class="n">1</span><span class="k2">;</span>
<span class="number"> 14</span>   <span class="k2">}</span>
<span class="number"> 15</span>      
<span class="number"> 16</span>   <a href="http://www.allegro.cc/manual/al_calculate_arc"><span class="a">al_calculate_arc</span></a><span class="k2">(</span><span class="k3">&amp;</span><span class="k2">(</span>vertex_cache<span class="k2">[</span><span class="n">1</span><span class="k2">]</span>.x<span class="k2">)</span>, <span class="k1">sizeof</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_VERTEX"><span class="a">ALLEGRO_VERTEX</span></a><span class="k2">)</span>, cx, cy, r, r, start_theta, delta_theta, <span class="n">0</span>, num_segments<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>   vertex_cache<span class="k2">[</span><span class="n">0</span><span class="k2">]</span>.x <span class="k3">=</span> cx<span class="k2">;</span> vertex_cache<span class="k2">[</span><span class="n">0</span><span class="k2">]</span>.y <span class="k3">=</span> cy<span class="k2">;</span>
<span class="number"> 18</span>   
<span class="number"> 19</span>   <span class="k1">for</span> <span class="k2">(</span>ii <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> ii <span class="k3">&lt;</span> num_segments <span class="k3">+</span> <span class="n">1</span><span class="k2">;</span> ii<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 20</span>      vertex_cache<span class="k2">[</span>ii<span class="k2">]</span>.color <span class="k3">=</span> color<span class="k2">;</span>
<span class="number"> 21</span>      vertex_cache<span class="k2">[</span>ii<span class="k2">]</span>.z <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 22</span>   <span class="k2">}</span>
<span class="number"> 23</span>   
<span class="number"> 24</span>   <a href="http://www.allegro.cc/manual/al_draw_prim"><span class="a">al_draw_prim</span></a><span class="k2">(</span>vertex_cache, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, num_segments <span class="k3">+</span> <span class="n">1</span>, ALLEGRO_PRIM_TRIANGLE_FAN<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 25</span><span class="k2">}</span>
</div></div><p>

You can also hack around it by using a thick outlined arc.</p><p>EDIT: Fixed the code a bit... still untested though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Thu, 02 Dec 2010 03:59:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh thank you so much! <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>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.</p><p>Maybe you meant to pass &quot;&amp;(vertex_cache[<b>1</b>].x)&quot; to al_calculate_arc?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Polybios)</author>
		<pubDate>Thu, 02 Dec 2010 04:22:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes. Fixed now.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Thu, 02 Dec 2010 04:23:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I recall there was a request for this forever.5 ago, people started talking about what to call it, then the thread died.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kibiz0r)</author>
		<pubDate>Thu, 02 Dec 2010 05:58:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>al_draw_sector<br />al_draw_pie_sector<br />al_draw_circle_sector</p><p>are these good names?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Thu, 02 Dec 2010 06:45:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;d call it al_pie_slice().
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 02 Dec 2010 06:49:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605684/892729#target">Kibiz0r</a> said:</div><div class="quote"><p>
I recall there was a request for this forever.5 ago, people started talking about what to call it, then the thread died.
</p></div></div><p>
The implementation for the outlined pieslice/sector/w/e is very non-trivial, so I haven&#39;t had the time to implement it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Thu, 02 Dec 2010 07:27:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>mmmmmmmmmmmmmmmmmm pie
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Steve Terry)</author>
		<pubDate>Thu, 02 Dec 2010 07:43:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks again, SiegeLord! <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>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?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Polybios)</author>
		<pubDate>Thu, 02 Dec 2010 14:22:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s... complicated. I don&#39;t remember exactly how I came up with it. The last thing I remember is that it is an approximation to this formula:<br /><img class="math" src="http://www.allegro.cc/images/tex/4/5/45d2391fdfda25054fb054d16bd64139-96.png" alt="&lt;math&gt;N = \frac{2 \pi}{\arccos (1 - 0.25 / r)}&lt;/math&gt;" /><br />Which calculates the number of segments by limiting the length of the KB segment in the diagram on <a href="http://slabode.exofire.net/circle_draw.shtml">this</a> page.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Thu, 02 Dec 2010 21:15:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;d call it al_pacman().
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kibiz0r)</author>
		<pubDate>Fri, 03 Dec 2010 04:31:06 +0000</pubDate>
	</item>
</rss>
