﻿<?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>Keith Hair &#187; Matrix</title>
	<atom:link href="http://keith-hair.net/blog/tag/matrix/feed/" rel="self" type="application/rss+xml" />
	<link>http://keith-hair.net/blog</link>
	<description>Scripting is fun like any other hobby</description>
	<lastBuildDate>Sat, 28 Jan 2012 05:04:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Matrix transforms based on an arbitrary registration point</title>
		<link>http://keith-hair.net/blog/2009/01/24/matrix-transforms-based-on-an-arbitrary-registration-point/</link>
		<comments>http://keith-hair.net/blog/2009/01/24/matrix-transforms-based-on-an-arbitrary-registration-point/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 06:05:23 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flash 9]]></category>
		<category><![CDATA[Arbitrary]]></category>
		<category><![CDATA[Matrix]]></category>
		<category><![CDATA[Registration Point]]></category>
		<category><![CDATA[Skew]]></category>
		<category><![CDATA[Transform]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=28</guid>
		<description><![CDATA[I was wanting a lightweight function to resize, rotate, and skew DisplayObjects based on a dynamic registration point so I made a function to apply my desired matrix settings. One thing that bothers me is that I could not figure out how to skew along the X and Y axis at the same time. When [...]]]></description>
			<content:encoded><![CDATA[<p>I was wanting a lightweight function to resize, rotate, and skew DisplayObjects based on a dynamic registration point so I made a function to apply my desired matrix settings.</p>
<p>One thing that bothers me is that I could not figure out how to skew along the X and Y axis at the same time. When I do set "c" and "b" Matrix properties, one of the skewed axis does not skew parallel like it should. And if I concatenate separate skew Matrices, the last concatenated skew Matrix transforms correctly but not the one before it. I'm trying to avoid using nested DisplayObjects to perform the separate X and Y skews, but that looks like an option I will have to use.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_matrix_example_1400876241"
			class="flashmovie"
			width="550"
			height="600">
	<param name="movie" value="/blog/examples/matrix/matrix_example.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/blog/examples/matrix/matrix_example.swf"
			name="fm_matrix_example_1400876241"
			width="550"
			height="600">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
<span id="more-28"></span></p>
<pre class="actionscript">&nbsp;
<span style="color: #808080; font-style: italic;">/*---------------------------------------------------------------------------
Sets the transform property of DisplayObject with a customized Matrix.
&nbsp;
display			-An ActionScript DisplayObject.
tx					-Translation x.
ty					-Translation y.
reg				-Registation point from which all transform effects orient from.
ang				-Rotation in in degrees.
scalex				-X scale percentage.
scaley				-Y scale percentage.
skew				-Skew percentage of the DisplayObjects width or height.
axis				-String indicating which axis to skew on.
&nbsp;
Note:	-The &quot;skew&quot; argument only works one axis at a time, If anyone knows
		 how to skew on both X and Y axis at the same time accurately please help me.
&nbsp;
		-The &quot;reg&quot; Registration point get scaled by scalex and scaley.		 
&nbsp;
----------------------------------------------------------------------------*/</span>
<span style="color: #000000; font-weight: bold;">function</span> setDisplayMatrix<span style="color: #66cc66;">&#40;</span>display:DisplayObject,
						  tx:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>,
						  ty:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>,
						  reg:Point=<span style="color: #000000; font-weight: bold;">null</span>,
						  ang:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>,
						  scalex:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">1</span>,
						  scaley:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">1</span>,
						  skew:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>,
						  axis:<span style="color: #0066CC;">String</span>=<span style="color: #ff0000;">&quot;x&quot;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	reg=reg||new Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> curM:Matrix=<span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> skewM:Matrix=<span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> rotM:Matrix=<span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> scaleM:Matrix=<span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> rp:Point;
	<span style="color: #000000; font-weight: bold;">var</span> r:<span style="color: #0066CC;">Number</span>=ang*<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span>/<span style="color: #cc66cc;">180</span>;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>axis == <span style="color: #ff0000;">&quot;y&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		skewM.<span style="color: #006600;">c</span>=<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">tan</span><span style="color: #66cc66;">&#40;</span>skew<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span>
		skewM.<span style="color: #006600;">b</span>=<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">tan</span><span style="color: #66cc66;">&#40;</span>skew<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	scaleM.<span style="color: #006600;">scale</span><span style="color: #66cc66;">&#40;</span>scalex,scaley<span style="color: #66cc66;">&#41;</span>;
	rotM.<span style="color: #006600;">rotate</span><span style="color: #66cc66;">&#40;</span>r<span style="color: #66cc66;">&#41;</span>;
	curM.<span style="color: #0066CC;">concat</span><span style="color: #66cc66;">&#40;</span>scaleM<span style="color: #66cc66;">&#41;</span>;
	curM.<span style="color: #0066CC;">concat</span><span style="color: #66cc66;">&#40;</span>skewM<span style="color: #66cc66;">&#41;</span>;
	curM.<span style="color: #0066CC;">concat</span><span style="color: #66cc66;">&#40;</span>rotM<span style="color: #66cc66;">&#41;</span>;
	rp=curM.<span style="color: #006600;">transformPoint</span><span style="color: #66cc66;">&#40;</span>reg<span style="color: #66cc66;">&#41;</span>;
	curM.<span style="color: #006600;">tx</span>=-rp.<span style="color: #006600;">x</span>;
	curM.<span style="color: #006600;">ty</span>=-rp.<span style="color: #006600;">y</span>;
	curM.<span style="color: #006600;">tx</span>+=tx;
	curM.<span style="color: #006600;">ty</span>+=ty;
	display.<span style="color: #006600;">transform</span>.<span style="color: #006600;">matrix</span>=curM;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>Here is a diagram I made to show what kind of skew I wanted to achieve instead of only skewing one axis at a time:<br />
<img src="/blog/examples/matrix/skew_diagram.gif" alt="The type of skews I want to achieve." /></p>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2009/01/24/matrix-transforms-based-on-an-arbitrary-registration-point/&ztz=Matrix transforms based on an arbitrary registration point'><img src='http://keith-hair.net/blog/wp-content/plugins/hexosearch-button/logo16x16.png' width='16' height='16' border='0' style='vertical-align:middle' alt='Vote in HexoSearch' title='Vote in HexoSearch' /></a>]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2009/01/24/matrix-transforms-based-on-an-arbitrary-registration-point/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

