<?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; DiscreteDoubleKeyFrame</title>
	<atom:link href="http://joel.neubeck.net/tag/discretedoublekeyframe/feed/" rel="self" type="application/rss+xml" />
	<link>http://joel.neubeck.net</link>
	<description>Simplifing structure without changing results</description>
	<lastBuildDate>Wed, 26 May 2010 18:43:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<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>
