<?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>Silverlight &#124; WPF &#124; Microsoft.Net &#187; DoubleAnimationUsingKeyFrames</title>
	<atom:link href="http://joel.neubeck.net/tag/doubleanimationusingkeyframes/feed/" rel="self" type="application/rss+xml" />
	<link>http://joel.neubeck.net</link>
	<description>Simplifing structure without changing results</description>
	<lastBuildDate>Fri, 01 Apr 2011 21:34:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Perspective 3D Screen flip with PlaneProjection</title>
		<link>http://joel.neubeck.net/2009/04/perspective-3d-screen-flip-with-planeprojection/</link>
		<comments>http://joel.neubeck.net/2009/04/perspective-3d-screen-flip-with-planeprojection/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 16:31:09 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[DoubleAnimationUsingKeyFrames]]></category>
		<category><![CDATA[perspective 3D]]></category>
		<category><![CDATA[Silverlight 3]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/?p=384</guid>
		<description><![CDATA[Almost a year ago I created a Silverlight 2 example that demonstrated how you could use a procedural animation to duplicate one of the transitions used on the iPhone. When a iPhone user goes to make a phone call, if you choose to display the keypad there is a cool 3D flip that occurs. Back [...]]]></description>
			<content:encoded><![CDATA[<p>Almost a year ago I created a Silverlight 2 example that demonstrated how you could use a procedural animation to duplicate one of the transitions used on the iPhone.  When a iPhone user goes to make a phone call, if you choose to display the keypad there is a cool 3D flip that occurs.  Back in SL2 it was a pretty lengthy animation that never quite duplicated the correct amount of 3d perspective needed to make the flip look realistic.</p>
<p>Thankfully in Silverlight 3 we now have perspective 3D which allows us to take  2D objects and rotate them in 3D space.  For this example I will use PlaneProjection to rotate a Grid with an extremely simple DoubleAnimationUsingKeyFrames.</p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2009/04/3dflip_sl3.png" border="0"><img class="alignleft size-full wp-image-385" title="3dflip_sl3" src="http://joel.neubeck.net/wp-content/uploads/2009/04/3dflip_sl3.png" alt="3dflip_sl3" width="500" border="0"/></a><br />
<br style="clear:both" /><br />
My first DoubleAnimationUsingKeyFrames simply targets the RotateY property of Grid.Projection.PlaneProjection.  The second two are used to fade  the back from opacity 0 to 1 and the front from opacity 1 to 0.</p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2009/04/3dflip_sl3_2.png" border="0"><img class="alignleft size-full wp-image-386" title="3dflip_sl3_2" src="http://joel.neubeck.net/wp-content/uploads/2009/04/3dflip_sl3_2.png" alt="3dflip_sl3_2" width="500" border="0"/></a><br />
<br style="clear:both" /></p>
<p>To get my  grid representing the back to start flipped  180 degrees I simply apply PlaneProject to it as well.</p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2009/04/3dflip_sl3_3.png" border="0"><img class="alignleft size-full wp-image-387" title="3dflip_sl3_3" src="http://joel.neubeck.net/wp-content/uploads/2009/04/3dflip_sl3_3.png" alt="3dflip_sl3_3" width="500" border="0"/></a></p>
<p><br style="clear:both" /></p>
<p>Here is the final example with nothing in the code behind except for the Flip button handler.</p>
<p><iframe src="/wp-content/uploads/2009/04/ScreenFlipv3/default.html" width="300" height="250"></iframe></p>
<p>Code: <a onclick="javascript: pageTracker._trackPageview('/code/ScreenFlipv3.zip');" href="/wp-content/uploads/2009/04/ScreenFlipv3/ScreenFlipv3.zip">ScreenFlipv3.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2009/04/perspective-3d-screen-flip-with-planeprojection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight 3D flip animation</title>
		<link>http://joel.neubeck.net/2008/04/silverlight-3d-flip-animation/</link>
		<comments>http://joel.neubeck.net/2008/04/silverlight-3d-flip-animation/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 07:20:16 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[3D Flip]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[DiscreteDoubleKeyFrame]]></category>
		<category><![CDATA[DoubleAnimationUsingKeyFrames]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[SplineDoubleKeyFrame]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/2008/04/silverlight-3d-flip-animation/</guid>
		<description><![CDATA[Up until now I have not had an opportunity to create any Silverlight procedural animations that were more complicated then positioning an object with some simple easing. I thought it would be fun to attempt to duplicate one of the transitions used on the iPhone. While making a phone call, if you choose to display [...]]]></description>
			<content:encoded><![CDATA[<p>Up until now I have not had an opportunity to create any Silverlight procedural animations that were more complicated then positioning an object with some simple easing.  I thought it would be fun to attempt to duplicate one of the transitions used on the iPhone. While making a phone call, if you choose to display the keypad there is a cool 3D flip that occurs. Here is a quick video of the transition.   [[VIDEO]] In hopes not to reinvent the wheel, I embarked on an endless search of the Internet for anything resembling a flip.  After some quality time on Google, I stumbled upon a great Flash site called <a href="http://tinyurl.com/63c89a" target="_blank">reflektions</a> by Paul Ortchanian. This site has a ton of Flash examples that highlight 2D and 3D effects done in flash.  Those of us new to interactive development can learn a ton from the techniques Flash and Flex developers have used for years.  To get started I created a simple page that contained two Grid controls, one for the front of the flip and one for the back.  Both were placed inside of a single canvas named &#8220;screens&#8221;.
<p><iframe src="/wp-content/uploads/2008/04/ScreenFlip/default.html" width="300" height="250"></iframe></p>
<p>  The guts of this effect has been encapsulated in a method called &#8220;AnimateFlip&#8221;.  The result of this method is a DobuleAnimation with approximately 48 descreate keys frames.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
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
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code"><pre class="c-sharp" style="font-family:monospace;">private TimeSpan AnimateFlip(Storyboard sb, ScaleTransform scale, 
out TimeSpan tsLastFrame)
{
    double speed = 4;
    double flipRotation = 0;
    double flipped = 2;
    tsLastFrame = new TimeSpan();
    TimeSpan tsSideFlipped = new TimeSpan();
&nbsp;
    int frames = 1;
    DoubleAnimationUsingKeyFrames daX = 
	new DoubleAnimationUsingKeyFrames();
    tsLastFrame = new TimeSpan();
    while (flipRotation != flipped * 180)
    {
        flipRotation += speed;
        double flipRadian = flipRotation * (Math.PI / 180);
        double size = Math.Cos(flipRadian);
        double scalar = (1 / (1 / size));
&nbsp;
        DiscreteDoubleKeyFrame ddkfX = new DiscreteDoubleKeyFrame();
        ddkfX.Value = (size * scalar) ;
&nbsp;
        tsLastFrame = TimeSpan.FromMilliseconds(frames * 7);
&nbsp;
        //the first time we flip to negative capture the 
	//tsLastFrame so we know when we will need to
        //visualize the flip side
        flipped = (size &lt; 0) ? +1 : +0;
        if (flipped == 1 &amp;&amp; tsSideFlipped.Ticks == 0)
        {
            tsSideFlipped = tsLastFrame;
        }
&nbsp;
        ddkfX.KeyTime = KeyTime.FromTimeSpan(tsLastFrame);
&nbsp;
        //add the DiscreteDoubleKeyFrame to the 
	//DoubleAnimationUsingKeyFrames
        daX.KeyFrames.Add(ddkfX);
&nbsp;
        flipRotation %= 360;
        frames++;
    }
&nbsp;
    Storyboard.SetTarget(daX, scale);
    Storyboard.SetTargetProperty(daX, &quot;ScaleX&quot;);
    sb.Children.Add(daX);
&nbsp;
    VisualizeSide(sb, tsSideFlipped, 0, TimeSpan.FromMilliseconds
		((tsSideFlipped.Milliseconds + 100)), 
		back.Opacity, this.back);
    VisualizeSide(sb, TimeSpan.FromMilliseconds((
		tsSideFlipped.Milliseconds - 100)), front.Opacity, 
		tsSideFlipped, 0, this.front);
    back.Opacity = 0;
    return tsLastFrame;
}</pre></td></tr></table></div>

<p>At the very bottom of the above method their is two calls to &#8220;VisualizeSide&#8221;.  This method is responsible for visualizing the second side when the screen has rotated 180 degrees (Flipped). </p>
<p>My animation is by no means exact, but a pretty good first attempt.  If you watch the video very slowly you might notice that on the iPhones rotation it looks like it rotates in perspective.  I would love to add this, but am at a lost </p>
<p>Code: <a onclick="javascript: pageTracker._trackPageview(&#39;/code/ScreenFlip.zip&#39;);" href="/wp-content/uploads/2008/04/ScreenFlip/ScreenFlip.zip">ScreenFlip.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2008/04/silverlight-3d-flip-animation/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

