<?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>Easy Flex &#187; 3D</title>
	<atom:link href="http://evtimmy.com/tag/3d/feed/" rel="self" type="application/rss+xml" />
	<link>http://evtimmy.com</link>
	<description>Evtim on Flex SDK</description>
	<lastBuildDate>Thu, 03 Nov 2011 07:18:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Two Examples of Layout Animations</title>
		<link>http://evtimmy.com/2010/04/two-examples-of-layout-animations/</link>
		<comments>http://evtimmy.com/2010/04/two-examples-of-layout-animations/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 06:42:10 +0000</pubDate>
		<dc:creator>Evtim</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[Custom Layout]]></category>
		<category><![CDATA[Spark Layouts]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Layout]]></category>
		<category><![CDATA[Move3D]]></category>
		<category><![CDATA[Rotate3D]]></category>
		<category><![CDATA[Scrolling]]></category>
		<category><![CDATA[Spark]]></category>
		<category><![CDATA[WheelLayout]]></category>

		<guid isPermaLink="false">http://evtimmy.com/?p=318</guid>
		<description><![CDATA[A few folks have been asking for the source of my Creating Custom Layouts in Flex 4 talk at the Flash Camp Boston event, and I finally found the time to post it here. My apologies for the delay. Click on the image to go to the demo, right-click and select &#8220;view source&#8221; to get [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://evtimmy.com/wordpress/wp-content/uploads/2010/04/layout-animation/FlickrRIAModified.swf"><img class="alignleft size-thumbnail wp-image-320" title="layout-animation" src="http://evtimmy.com/wordpress/wp-content/uploads/2010/04/layout-animation-150x150.png" alt="layout-animation" width="150" height="150" /></a> A few folks have been asking for the source of my <a href="http://tv.adobe.com/watch/flash-camp-boston/creating-custom-layouts-in-flex-4-">Creating Custom Layouts in Flex 4</a> talk at the Flash Camp Boston event, and I finally found the time to post it here. My apologies for the delay.  Click on the image to go to the demo, right-click and select &#8220;view source&#8221; to get to the goods. <span id="more-318"></span> This is pretty much my old WheelLayout demo, but I added a couple of animations  to make things a little bit slicker:</p>
<ol>
<li>Clicking on any image in the WheelLayout mode will rotate all the elements until the selected item is centered in front. <em>In this animation the layout runs on every frame of the animation.</em></li>
<li>Selecting different layouts from the drop-down will animate the items&#8217; transformation. <em>In this animation the layout is disabled and is not running during the animation.</em></li>
</ol>
<h3>Animating the Scroll Position</h3>
<p>In the first animation I want the selected item to come &#8220;in view&#8221;. In the <em>WheelLayout</em> I&#8217;ve already implemented the standard API that calculates the scroll distance to an item &#8211; <em>getScrollPositionDeltaToElement()</em>. Now in the item renderer of the list &#8211; <em>FlickrThumbnail.mxml</em> &#8211; I detect when the item has been clicked and then create an animation for the scroll position of the parent <em>Group</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> itemrenderer1_clickHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> g<span style="color: #000066; font-weight: bold;">:</span>GroupBase = <span style="color: #004993;">parent</span> <span style="color: #0033ff; font-weight: bold;">as</span> GroupBase<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> p<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Point</span> = g<span style="color: #000066; font-weight: bold;">.</span>layout<span style="color: #000066; font-weight: bold;">.</span>getScrollPositionDeltaToElement<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>itemIndex<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>p<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> startX<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = g<span style="color: #000066; font-weight: bold;">.</span>horizontalScrollPosition<span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> startY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = g<span style="color: #000066; font-weight: bold;">.</span>verticalScrollPosition<span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> anim<span style="color: #000066; font-weight: bold;">:</span>Animate = <span style="color: #0033ff; font-weight: bold;">new</span> Animate<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        anim<span style="color: #000066; font-weight: bold;">.</span>motionPaths = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #000000;">&#91;</span>
            <span style="color: #0033ff; font-weight: bold;">new</span> SimpleMotionPath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;horizontalScrollPosition&quot;</span><span style="color: #000066; font-weight: bold;">,</span> startX<span style="color: #000066; font-weight: bold;">,</span> startX <span style="color: #000066; font-weight: bold;">+</span> p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">500</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span>
            <span style="color: #0033ff; font-weight: bold;">new</span> SimpleMotionPath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;verticalScrollPosition&quot;</span><span style="color: #000066; font-weight: bold;">,</span> startY<span style="color: #000066; font-weight: bold;">,</span> startY <span style="color: #000066; font-weight: bold;">+</span> p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">500</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
        <span style="color: #6699cc; font-weight: bold;">var</span> interpolator<span style="color: #000066; font-weight: bold;">:</span>NumberInterpolatorWrapping =
			<span style="color: #0033ff; font-weight: bold;">new</span> NumberInterpolatorWrapping<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> g<span style="color: #000066; font-weight: bold;">.</span>contentWidth <span style="color: #000066; font-weight: bold;">-</span> g<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> scrollLength<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = interpolator<span style="color: #000066; font-weight: bold;">.</span>getLength<span style="color: #000000;">&#40;</span>startX<span style="color: #000066; font-weight: bold;">,</span> startX <span style="color: #000066; font-weight: bold;">+</span> p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        anim<span style="color: #000066; font-weight: bold;">.</span>interpolator = interpolator<span style="color: #000066; font-weight: bold;">;</span>
        anim<span style="color: #000066; font-weight: bold;">.</span>duration = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">max</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">550</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">min</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2500</span><span style="color: #000066; font-weight: bold;">,</span> scrollLength <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
        anim<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>g<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>One interesting thing to note is that because of the circular nature of the WheelLayout I wanted the animation to interpolate between the values in a wrap-around manner. For example scrolling from the last element to the first element shouldn&#8217;t scroll through any other elements since the first and last elements are visually next to each other. For that reason I implemented a custom interpolator &#8211; <em>NumberInterpolatorWrapping.as</em>.</p>
<h3>Animating Items between Different Layouts</h3>
<p>In this animation I wanted all the elements to move and rotate smoothly when I switch between various layouts. In this animation the start position is defined by the current layout and the end position is defined by the new layout. In-between, while the elements are being animated, they really don&#8217;t belong to any layout. For that reason, I disable the layout of the container for the duration of the animation using the <em>autoLayout </em>property of the parent <em>Group</em>.</p>
<p>For convenience I transition between the layouts using states:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:states</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;tile&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;wheel&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;vertical&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;horizontal&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:states</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:List</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span></span>
<span style="color: #000000;">		dataProvider=<span style="color: #ff0000;">&quot;{photoFeed}&quot;</span></span>
<span style="color: #000000;">		itemRenderer=<span style="color: #ff0000;">&quot;FlickrThumbnail&quot;</span></span>
<span style="color: #000000;">		id=<span style="color: #ff0000;">&quot;theList&quot;</span> useVirtualLayout=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span>.vertical<span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VerticalLayout</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span>.vertical<span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span>.horizontal<span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HorizontalLayout</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span>.horizontal<span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span>.tile<span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TileLayout</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;bottom&quot;</span></span>
<span style="color: #000000;">                                      columnWidth=<span style="color: #ff0000;">&quot;112&quot;</span> rowHeight=<span style="color: #ff0000;">&quot;132&quot;</span></span>
<span style="color: #000000;">				      requestedColumnCount=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span>.tile<span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span>.wheel<span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;my:WheelLayout</span> gap=<span style="color: #ff0000;">&quot;20&quot;</span> axisAngle=<span style="color: #ff0000;">&quot;{axisSlider.value}&quot;</span></span>
<span style="color: #000000;">		verticalCenterOffset=<span style="color: #ff0000;">&quot;{offsetSlider.value}&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span>.wheel<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:List</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>Because the elements could be both moved and/or rotated in 2D or 3D, I use a parallel of both effects:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Parallel</span> id=<span style="color: #ff0000;">&quot;myEffect&quot;</span> effectEnd=<span style="color: #ff0000;">&quot;myEffect_effectEndHandler(event)&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Move</span>3D applyChangesPostLayout=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Rotate</span>3D applyChangesPostLayout=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Parallel</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>And finally, when I switch from one layout state to another, I want to run the effect. Now I need to perform the following steps:</p>
<ol>
<li>Make the effect target all of the elements.</li>
<li>Capture the start values (the position and rotation defined by the old layout).</li>
<li>Switch the layout (by changing the state) and call <em>validateNow()</em> so that all elements are positioned and/or rotated by the new layout.</li>
<li>Turn off the <em>autoLayout</em> property so that the new layout doesn&#8217;t interfere with the running effect.</li>
<li>Run the effect. Note that at this point the effect is going to capture the animation end values &#8211; the position/rotation defined by the new layout. I&#8217;ve already captured the start values at step 2, so I&#8217;m all set.</li>
<li>When the effect is done, turn the layout back on.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> animateTo<span style="color: #000000;">&#40;</span>toState<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #009900; font-style: italic;">// Make sure any previous animation is stopped.</span>
    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>myEffect<span style="color: #000066; font-weight: bold;">.</span>isPlaying<span style="color: #000000;">&#41;</span>
        myEffect<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">// Add targets</span>
    myEffect<span style="color: #000066; font-weight: bold;">.</span>targets = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> theList<span style="color: #000066; font-weight: bold;">.</span>dataGroup<span style="color: #000066; font-weight: bold;">.</span>numElements<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span>
        myEffect<span style="color: #000066; font-weight: bold;">.</span>targets<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>theList<span style="color: #000066; font-weight: bold;">.</span>dataGroup<span style="color: #000066; font-weight: bold;">.</span>getElementAt<span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">// Create Transition for all elements</span>
    myEffect<span style="color: #000066; font-weight: bold;">.</span>captureStartValues<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">// Go to the end state</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> fromState<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>currentState<span style="color: #000066; font-weight: bold;">;</span>
    setCurrentState<span style="color: #000000;">&#40;</span>toState<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">// Validate everything before turning off the layout</span>
    theList<span style="color: #000066; font-weight: bold;">.</span>validateNow<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">// Turn the layout off before running the effect</span>
    theList<span style="color: #000066; font-weight: bold;">.</span>dataGroup<span style="color: #000066; font-weight: bold;">.</span>autoLayout = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">// Play the effect</span>
    myEffect<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> myEffect_effectEndHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span>EffectEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
    theList<span style="color: #000066; font-weight: bold;">.</span>dataGroup<span style="color: #000066; font-weight: bold;">.</span>autoLayout = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Note that my demo has one limitation &#8211; I needed to turn off virtual layout so that everything works fine. If I have virtual layout running, I&#8217;m not guaranteed that the old and new layouts will assign the items to the same item renderers.<br />
Click on the image at the top to go to the demo, where you can select &#8220;view source&#8221; from the right-click menu to get the code.</p>
]]></content:encoded>
			<wfw:commentRss>http://evtimmy.com/2010/04/two-examples-of-layout-animations/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Calculating the Projected Bounds using Utils3D.projectVector()</title>
		<link>http://evtimmy.com/2009/12/calculating-the-projected-bounds-using-utils3dprojectvector/</link>
		<comments>http://evtimmy.com/2009/12/calculating-the-projected-bounds-using-utils3dprojectvector/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 07:23:47 +0000</pubDate>
		<dc:creator>Evtim</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[bounds]]></category>
		<category><![CDATA[perspectiveProjection]]></category>
		<category><![CDATA[Utils3D]]></category>

		<guid isPermaLink="false">http://evtimmy.com/?p=173</guid>
		<description><![CDATA[If you are playing with objects in 3D and want their projected bounds, there&#8217;s a neat flash functionality for that &#8211; Utils3D.projectVector(). However it may not be that apparent how to use it. Here I&#8217;m showing a small helper function that does the trick. The projectVector() method actually takes a Matrix3D for a parameter. Note [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://evtimmy.com/wordpress/wp-content/uploads/2009/12/projectedbounds.swf"><img class="size-full wp-image-178 alignleft" title="projectedbounds" src="http://evtimmy.com/wordpress/wp-content/uploads/2009/12/projectedbounds.png" alt="projectedbounds" width="142" height="124" /></a>If you are playing with objects in 3D and want their projected bounds, there&#8217;s a neat flash functionality for that &#8211; Utils3D.projectVector(). However it may not be that apparent how to use it. Here I&#8217;m showing a small helper function that does the trick.<br />
<span id="more-173"></span>The projectVector() method actually takes a Matrix3D for a parameter. Note that here you should pass in the Matrix3D of the object in question combined with the perspective projection of its parent. This is not as trivial as it seems, as you&#8217;d need to also translate by the projectionCenter and the focalLength:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>16
17
18
19
20
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// Setup the matrix</span>
 <span style="color: #6699cc; font-weight: bold;">var</span> centerX<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = projection<span style="color: #000066; font-weight: bold;">.</span>projectionCenter<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #6699cc; font-weight: bold;">var</span> centerY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = projection<span style="color: #000066; font-weight: bold;">.</span>projectionCenter<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #004993;">matrix</span><span style="color: #000066; font-weight: bold;">.</span>appendTranslation<span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">-</span>centerX<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000066; font-weight: bold;">-</span>centerY<span style="color: #000066; font-weight: bold;">,</span> projection<span style="color: #000066; font-weight: bold;">.</span>focalLength<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #004993;">matrix</span><span style="color: #000066; font-weight: bold;">.</span>append<span style="color: #000000;">&#40;</span>projection<span style="color: #000066; font-weight: bold;">.</span>toMatrix3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>After that just pass in the matrix and the point to be projected to Utils3D.projectVector(). Then translate the result by centerX and centerY.<br />
Here&#8217;s the helper function source, it takes in bounds, the matrix of the object and the perspective projection and returns the projected 2D bounds:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> projectBounds<span style="color: #000000;">&#40;</span>bounds<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span><span style="color: #000066; font-weight: bold;">,</span>
 <span style="color: #004993;">matrix</span><span style="color: #000066; font-weight: bold;">:</span>Matrix3D<span style="color: #000066; font-weight: bold;">,</span>
 projection<span style="color: #000066; font-weight: bold;">:</span>PerspectiveProjection<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span>
 <span style="color: #000000;">&#123;</span>
 <span style="color: #009900; font-style: italic;">// Setup the matrix</span>
 <span style="color: #6699cc; font-weight: bold;">var</span> centerX<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = projection<span style="color: #000066; font-weight: bold;">.</span>projectionCenter<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #6699cc; font-weight: bold;">var</span> centerY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = projection<span style="color: #000066; font-weight: bold;">.</span>projectionCenter<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #004993;">matrix</span><span style="color: #000066; font-weight: bold;">.</span>appendTranslation<span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">-</span>centerX<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000066; font-weight: bold;">-</span>centerY<span style="color: #000066; font-weight: bold;">,</span> projection<span style="color: #000066; font-weight: bold;">.</span>focalLength<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #004993;">matrix</span><span style="color: #000066; font-weight: bold;">.</span>append<span style="color: #000000;">&#40;</span>projection<span style="color: #000066; font-weight: bold;">.</span>toMatrix3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// Project the corner points</span>
 <span style="color: #6699cc; font-weight: bold;">var</span> pt1<span style="color: #000066; font-weight: bold;">:</span>Vector3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vector3D<span style="color: #000000;">&#40;</span>bounds<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">left</span><span style="color: #000066; font-weight: bold;">,</span> bounds<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">top</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #6699cc; font-weight: bold;">var</span> pt2<span style="color: #000066; font-weight: bold;">:</span>Vector3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vector3D<span style="color: #000000;">&#40;</span>bounds<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">right</span><span style="color: #000066; font-weight: bold;">,</span> bounds<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">top</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>
 <span style="color: #6699cc; font-weight: bold;">var</span> pt3<span style="color: #000066; font-weight: bold;">:</span>Vector3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vector3D<span style="color: #000000;">&#40;</span>bounds<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">left</span><span style="color: #000066; font-weight: bold;">,</span> bounds<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bottom</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #6699cc; font-weight: bold;">var</span> pt4<span style="color: #000066; font-weight: bold;">:</span>Vector3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vector3D<span style="color: #000000;">&#40;</span>bounds<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">right</span><span style="color: #000066; font-weight: bold;">,</span> bounds<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bottom</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
 pt1 = Utils3D<span style="color: #000066; font-weight: bold;">.</span>projectVector<span style="color: #000000;">&#40;</span><span style="color: #004993;">matrix</span><span style="color: #000066; font-weight: bold;">,</span> pt1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
 pt2 = Utils3D<span style="color: #000066; font-weight: bold;">.</span>projectVector<span style="color: #000000;">&#40;</span><span style="color: #004993;">matrix</span><span style="color: #000066; font-weight: bold;">,</span> pt2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
 pt3 = Utils3D<span style="color: #000066; font-weight: bold;">.</span>projectVector<span style="color: #000000;">&#40;</span><span style="color: #004993;">matrix</span><span style="color: #000066; font-weight: bold;">,</span> pt3<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
 pt4 = Utils3D<span style="color: #000066; font-weight: bold;">.</span>projectVector<span style="color: #000000;">&#40;</span><span style="color: #004993;">matrix</span><span style="color: #000066; font-weight: bold;">,</span> pt4<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// Find the bounding box in 2D</span>
 <span style="color: #6699cc; font-weight: bold;">var</span> maxX<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">max</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">max</span><span style="color: #000000;">&#40;</span>pt1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span> pt2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">max</span><span style="color: #000000;">&#40;</span>pt3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span> pt4<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #6699cc; font-weight: bold;">var</span> minX<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">min</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">min</span><span style="color: #000000;">&#40;</span>pt1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span> pt2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">min</span><span style="color: #000000;">&#40;</span>pt3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span> pt4<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #6699cc; font-weight: bold;">var</span> maxY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">max</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">max</span><span style="color: #000000;">&#40;</span>pt1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> pt2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">max</span><span style="color: #000000;">&#40;</span>pt3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> pt4<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #6699cc; font-weight: bold;">var</span> minY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">min</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">min</span><span style="color: #000000;">&#40;</span>pt1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> pt2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">min</span><span style="color: #000000;">&#40;</span>pt3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> pt4<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// Add back the projection center</span>
 bounds<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = minX <span style="color: #000066; font-weight: bold;">+</span> centerX<span style="color: #000066; font-weight: bold;">;</span>
 bounds<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = minY <span style="color: #000066; font-weight: bold;">+</span> centerY<span style="color: #000066; font-weight: bold;">;</span>
 bounds<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> = maxX <span style="color: #000066; font-weight: bold;">-</span> minX<span style="color: #000066; font-weight: bold;">;</span>
 bounds<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> = maxY <span style="color: #000066; font-weight: bold;">-</span> minY<span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #0033ff; font-weight: bold;">return</span> bounds<span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The full source is here <a href='http://evtimmy.com/wordpress/wp-content/uploads/2009/12/projectedbounds.mxml'>projectedbounds.mxml</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://evtimmy.com/2009/12/calculating-the-projected-bounds-using-utils3dprojectvector/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>WheelLayout Source and Quick Mashup</title>
		<link>http://evtimmy.com/2009/06/wheellayout-source-and-quick-mashup/</link>
		<comments>http://evtimmy.com/2009/06/wheellayout-source-and-quick-mashup/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 07:38:24 +0000</pubDate>
		<dc:creator>Evtim</dc:creator>
				<category><![CDATA[Custom Layout]]></category>
		<category><![CDATA[Quick mash-up]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[Flickr]]></category>
		<category><![CDATA[WheelLayout]]></category>

		<guid isPermaLink="false">http://evtimmy.com/?p=136</guid>
		<description><![CDATA[A few folks have been asking for the source code of the WheelLayout. I created it as a proof-of-concept that our Spark layout APIs are sufficient for creation of 3D layouts. And just to showcase it in action, I decided to grab quickly the Flex3 Halo FlickrRIA, port it to Flex 4, and mash it [...]]]></description>
			<content:encoded><![CDATA[<p>A few folks have been asking for the source code of the WheelLayout. I created it as a proof-of-concept that our Spark layout APIs are sufficient for creation of 3D layouts. And just to showcase it in action, I decided to grab quickly the Flex3 Halo <a href="http://learn.adobe.com/wiki/display/Flex/1d.+RIA+Tutorial">FlickrRIA</a>, port it to Flex 4, and mash it up with the WheelLayout.</p>
<p><a href="http://evtimmy.com/wordpress/wp-content/uploads/2009/06/flickrriamodified1.swf"><img class="alignnone size-thumbnail wp-image-166" title="wheellayout" src="http://evtimmy.com/wordpress/wp-content/uploads/2009/06/wheellayout-150x150.png" alt="wheellayout" width="150" height="150" /></a></p>
<p><span id="more-136"></span><em>This example was compiled with the now oldish 4.0.0.7052 Flex SDK build. </em></p>
<p>The source code that I used is <a href="http://evtimmy.com/wordpress/wp-content/uploads/2009/06/flickriaandwheellayout.zip">here</a>. I’ve actually checked it in our flex4test project and therefore the up-to-date source is available from this <a href="http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/development/eclipse/flex/sparkTest/src/testWheel.mxml">location</a> (of course it’s outside of the SDK, so it’s not supported <img src='http://evtimmy.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> )<br />
<em></em></p>
]]></content:encoded>
			<wfw:commentRss>http://evtimmy.com/2009/06/wheellayout-source-and-quick-mashup/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

