<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iestyn.net &#187; hittest</title>
	<atom:link href="http://www.iestyn.net/wp/category/hittest/feed" rel="self" type="application/rss+xml" />
	<link>http://www.iestyn.net/wp</link>
	<description>"the concrete world is starting to get ya."</description>
	<lastBuildDate>Fri, 21 Oct 2011 16:27:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>AS3 BitmapData.hitTest() with rotation</title>
		<link>http://www.iestyn.net/wp/2009/06/23/as3-bitmapdata-hittest-with-rotation-matrix</link>
		<comments>http://www.iestyn.net/wp/2009/06/23/as3-bitmapdata-hittest-with-rotation-matrix#comments</comments>
		<pubDate>Tue, 23 Jun 2009 09:59:26 +0000</pubDate>
		<dc:creator>Iestyn</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[bitmapdata]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[hittest]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.iestyn.net/wp/?p=436</guid>
		<description><![CDATA[I saw a tweet from @mesh today, asking about hitTest when one object is rotated. A bit of horrible hackery, and here&#8217;s the result. Warning, nasty thrown-together code!  
var red:Sprite = new Sprite();
red.graphics.beginFill(0xFF0000);
red.graphics.lineTo(40, 0);
red.graphics.lineTo(40, 150);
red.graphics.lineTo(0,150);
red.graphics.lineTo(0,0);

red.x = 40;
red.y = 40;

addChild(red);

var green:Sprite = new Sprite();

green.graphics.beginFill(0x00FF00);
green.graphics.lineTo(40, 0);
green.graphics.lineTo(40, 150);
green.graphics.lineTo(0,150);
green.graphics.lineTo(0,0);

green.x = 300;
green.y = 40;

addChild(green);

var useRotation:Number=10;

var redBmpData = new BitmapData(red.width, [...]]]></description>
			<content:encoded><![CDATA[<p>I saw a tweet from <a href="http://twitter.com/mesh/statuses/2291551870" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://twitter.com/mesh/statuses/2291551870');">@mesh</a> today, asking about hitTest when one object is rotated. A bit of horrible hackery, and here&#8217;s the result. Warning, nasty thrown-together code! <img src='http://www.iestyn.net/wp/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<pre name="code" class="js">var red:Sprite = new Sprite();
red.graphics.beginFill(0xFF0000);
red.graphics.lineTo(40, 0);
red.graphics.lineTo(40, 150);
red.graphics.lineTo(0,150);
red.graphics.lineTo(0,0);

red.x = 40;
red.y = 40;

addChild(red);

var green:Sprite = new Sprite();

green.graphics.beginFill(0x00FF00);
green.graphics.lineTo(40, 0);
green.graphics.lineTo(40, 150);
green.graphics.lineTo(0,150);
green.graphics.lineTo(0,0);

green.x = 300;
green.y = 40;

addChild(green);

var useRotation:Number=10;

var redBmpData = new BitmapData(red.width, red.height, true, 0);
redBmpData.draw(red);

var useDimension:int = Math.ceil(Math.sqrt((green.width * green.width) + (green.height * green.height)));
var diffWidth:int = useDimension - green.width;
var diffHeight:int = useDimension - green.height;
var newBD:BitmapData = new BitmapData(useDimension,useDimension,true,0);
var angle_in_radians:Number = Math.PI * 2 * (useRotation / 360);
var m:Matrix = new Matrix();
m.translate((green.width / 2) * -1, (green.height / 2) * -1);
m.rotate(angle_in_radians);
m.translate(green.width / 2, green.height / 2);
m.translate(diffWidth / 2, diffHeight / 2);
var translatedPoint:Point = m.transformPoint(new Point(0,0));

trace(useDimension);
var greenBmpData = new BitmapData(useDimension,useDimension,true,0);
greenBmpData.draw(green,m);

/*var sampleGreen:Bitmap =new Bitmap(greenBmpData);
addChild(sampleGreen);
sampleGreen.x=200;
sampleGreen.y=200;
*/
green.rotation=useRotation;

stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);

function onMouseMove(e:MouseEvent):void {
	green.x = mouseX;
	green.y = mouseY;

	if (redBmpData.hitTest(new Point(red.x, red.y),
	255,
	greenBmpData,
	new Point(green.x-translatedPoint.x, green.y-translatedPoint.y),
	255

	  )) {
		trace("hit");
		red.filters = [new GlowFilter()];
	} else {
		red.filters = [];
	}
}</pre>
<p>I&#8217;ll blog a better example of this, with comments and an explanation of what it&#8217;s doing in the next few days. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.iestyn.net/wp/2009/06/23/as3-bitmapdata-hittest-with-rotation-matrix/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

