<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Check if mouse is on rotated sprite?</title>
		<link>http://www.allegro.cc/forums/view/601818</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 11 Oct 2009 02:05:21 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m new to Allegro. I have an array of 13 playing cards that I display. Each card is at an angle to make an arc. Basically, if I iterate through the cards, how can I check if the mouse is touching a card so i can do an action? I would use bounding box, but I dont feel it is precise enough.</p><p>Thanks
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Sat, 10 Oct 2009 18:41:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Two algorithms spring to mind that are easy enough to implement.</p><p>Your first (obvious) option is to use rotated bounding boxes. Since you are only comparing a point against a rotated box, you can simplify the problem by applying the same transform to both the box and the point, so that the box isn&#39;t rotated anymore. Once you have that, the collision check is trivial.</p><p>The second option is to render the cards to an invisible buffer; but instead of using the actual graphics, render each card in a distinct solid color, say, RGB(0, 0, 1) for the first card, RGB(0, 0, 2) for the second, and so on. When you&#39;re done rendering, read the pixel at the mouse position and find the card that belongs to the color.</p><p>The first option is probably faster, but limited to rotated rectangles, plus you need to work out the drawing order (if one card obscures another, some pixels will give you a collision for both cards, and you need to pick the one on top).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Sun, 11 Oct 2009 02:02:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><b>EDIT</b>: beaten</p><p>Create an off-screen bitmap.  In the same location where you&#39;d draw your card to the screen that the player sees, you would draw (to this off-screen bitmap) a rotated rectangle with some solid pre-determined color.</p><p>Your mouse, then, calculates which color it&#39;s over.  The color drawn tells you which card it&#39;s over.  Where there is no color (transparent), the mouse isn&#39;t over anything.</p><p>Essentially, what the &quot;player&quot; sees and what the &quot;mouse&quot; sees are two different bitmaps.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Sun, 11 Oct 2009 02:05:21 +0000</pubDate>
	</item>
</rss>
