<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Silverlight 3D flip animation</title>
	<atom:link href="http://joel.neubeck.net/2008/04/silverlight-3d-flip-animation/feed/" rel="self" type="application/rss+xml" />
	<link>http://joel.neubeck.net/2008/04/silverlight-3d-flip-animation/</link>
	<description>Simplifing structure without changing results</description>
	<pubDate>Thu, 28 Aug 2008 11:50:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: Richard</title>
		<link>http://joel.neubeck.net/2008/04/silverlight-3d-flip-animation/#comment-646</link>
		<dc:creator>Richard</dc:creator>
		<pubDate>Tue, 01 Jul 2008 19:03:07 +0000</pubDate>
		<guid isPermaLink="false">http://joel.neubeck.net/2008/04/silverlight-3d-flip-animation/#comment-646</guid>
		<description>I spun this off as a class with a static methods so I could reuse it in many places.  Here's the code for anyone that wants to save some time.

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ScreenFlip
{
    public class FlipStoryboardCreator
    {
        public static void Create(UIElement front, UIElement back, out Storyboard sb, out ScaleTransform scale, out TimeSpan tsLastFrame)
        {
            double speed = 4;
            double flipRotation = 0;
            double flipped = 2;
            sb = new Storyboard();
            scale = new ScaleTransform();
            tsLastFrame = new TimeSpan();
            TimeSpan tsSideFlipped = new TimeSpan();

            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));

                DiscreteDoubleKeyFrame ddkfX = new DiscreteDoubleKeyFrame();
                ddkfX.Value = (size * scalar);

                tsLastFrame = TimeSpan.FromMilliseconds(frames * 7);

                //the first time we flip to negative capture the tsLastFrame so we know when we will need to
                //visualize the flip side
                flipped = (size &#60; 0) ? +1 : +0;
                if (flipped == 1 &#38;&#38; tsSideFlipped.Ticks == 0)
                {
                    tsSideFlipped = tsLastFrame;
                }

                ddkfX.KeyTime = KeyTime.FromTimeSpan(tsLastFrame);

                //add the DiscreteDoubleKeyFrame to the DoubleAnimationUsingKeyFrames
                daX.KeyFrames.Add(ddkfX);

                flipRotation %= 360;
                frames++;
            }

            Storyboard.SetTarget(daX, scale);
            Storyboard.SetTargetProperty(daX, new PropertyPath("(ScaleX)"));
            sb.Children.Add(daX);

            VisualizeSide(sb, tsSideFlipped, 0, TimeSpan.FromMilliseconds((tsSideFlipped.Milliseconds + 100)), back.Opacity, back);
            VisualizeSide(sb, TimeSpan.FromMilliseconds((tsSideFlipped.Milliseconds - 100)), front.Opacity, tsSideFlipped, 0, front);
            back.Opacity = 0;
        }

        private static void VisualizeSide(Storyboard sb, TimeSpan tsStart, double opacityStart, TimeSpan tsEnd, double opacityEnd, UIElement side)
        {
            DoubleAnimationUsingKeyFrames daOpacity = new DoubleAnimationUsingKeyFrames();
            SplineDoubleKeyFrame sdkfStart = new SplineDoubleKeyFrame();
            sdkfStart.Value = opacityStart;
            sdkfStart.KeyTime = tsStart;
            sdkfStart.KeySpline = DefineKeySpline(0, 0, 1, 1);
            daOpacity.KeyFrames.Add(sdkfStart);

            SplineDoubleKeyFrame sdkfEnd = new SplineDoubleKeyFrame();
            sdkfEnd.Value = opacityEnd;
            sdkfEnd.KeyTime = tsEnd;
            sdkfEnd.KeySpline = DefineKeySpline(0, 0, 1, 1);
            daOpacity.KeyFrames.Add(sdkfEnd);

            Storyboard.SetTarget(daOpacity, side);
            Storyboard.SetTargetProperty(daOpacity, new PropertyPath("(UIElement.Opacity)"));

            sb.Children.Add(daOpacity);
        }

        private static KeySpline DefineKeySpline(double cp1X, double cp1Y, double cp2X, double cp2Y)
        {
            KeySpline ksStart = new KeySpline();
            ksStart.ControlPoint1 = new Point(cp1X, cp1Y);
            ksStart.ControlPoint2 = new Point(cp2X, cp2Y);
            return ksStart;
        }
    }
}</description>
		<content:encoded><![CDATA[<p>I spun this off as a class with a static methods so I could reuse it in many places.  Here&#8217;s the code for anyone that wants to save some time.</p>
<p>using System;<br />
using System.Net;<br />
using System.Windows;<br />
using System.Windows.Controls;<br />
using System.Windows.Documents;<br />
using System.Windows.Ink;<br />
using System.Windows.Input;<br />
using System.Windows.Media;<br />
using System.Windows.Media.Animation;<br />
using System.Windows.Shapes;</p>
<p>namespace ScreenFlip<br />
{<br />
    public class FlipStoryboardCreator<br />
    {<br />
        public static void Create(UIElement front, UIElement back, out Storyboard sb, out ScaleTransform scale, out TimeSpan tsLastFrame)<br />
        {<br />
            double speed = 4;<br />
            double flipRotation = 0;<br />
            double flipped = 2;<br />
            sb = new Storyboard();<br />
            scale = new ScaleTransform();<br />
            tsLastFrame = new TimeSpan();<br />
            TimeSpan tsSideFlipped = new TimeSpan();</p>
<p>            int frames = 1;<br />
            DoubleAnimationUsingKeyFrames daX = new DoubleAnimationUsingKeyFrames();<br />
            tsLastFrame = new TimeSpan();<br />
            while (flipRotation != flipped * 180)<br />
            {<br />
                flipRotation += speed;<br />
                double flipRadian = flipRotation * (Math.PI / 180);<br />
                double size = Math.Cos(flipRadian);<br />
                double scalar = (1 / (1 / size));</p>
<p>                DiscreteDoubleKeyFrame ddkfX = new DiscreteDoubleKeyFrame();<br />
                ddkfX.Value = (size * scalar);</p>
<p>                tsLastFrame = TimeSpan.FromMilliseconds(frames * 7);</p>
<p>                //the first time we flip to negative capture the tsLastFrame so we know when we will need to<br />
                //visualize the flip side<br />
                flipped = (size &lt; 0) ? +1 : +0;<br />
                if (flipped == 1 &amp;&amp; tsSideFlipped.Ticks == 0)<br />
                {<br />
                    tsSideFlipped = tsLastFrame;<br />
                }</p>
<p>                ddkfX.KeyTime = KeyTime.FromTimeSpan(tsLastFrame);</p>
<p>                //add the DiscreteDoubleKeyFrame to the DoubleAnimationUsingKeyFrames<br />
                daX.KeyFrames.Add(ddkfX);</p>
<p>                flipRotation %= 360;<br />
                frames++;<br />
            }</p>
<p>            Storyboard.SetTarget(daX, scale);<br />
            Storyboard.SetTargetProperty(daX, new PropertyPath(&#8221;(ScaleX)&#8221;));<br />
            sb.Children.Add(daX);</p>
<p>            VisualizeSide(sb, tsSideFlipped, 0, TimeSpan.FromMilliseconds((tsSideFlipped.Milliseconds + 100)), back.Opacity, back);<br />
            VisualizeSide(sb, TimeSpan.FromMilliseconds((tsSideFlipped.Milliseconds - 100)), front.Opacity, tsSideFlipped, 0, front);<br />
            back.Opacity = 0;<br />
        }</p>
<p>        private static void VisualizeSide(Storyboard sb, TimeSpan tsStart, double opacityStart, TimeSpan tsEnd, double opacityEnd, UIElement side)<br />
        {<br />
            DoubleAnimationUsingKeyFrames daOpacity = new DoubleAnimationUsingKeyFrames();<br />
            SplineDoubleKeyFrame sdkfStart = new SplineDoubleKeyFrame();<br />
            sdkfStart.Value = opacityStart;<br />
            sdkfStart.KeyTime = tsStart;<br />
            sdkfStart.KeySpline = DefineKeySpline(0, 0, 1, 1);<br />
            daOpacity.KeyFrames.Add(sdkfStart);</p>
<p>            SplineDoubleKeyFrame sdkfEnd = new SplineDoubleKeyFrame();<br />
            sdkfEnd.Value = opacityEnd;<br />
            sdkfEnd.KeyTime = tsEnd;<br />
            sdkfEnd.KeySpline = DefineKeySpline(0, 0, 1, 1);<br />
            daOpacity.KeyFrames.Add(sdkfEnd);</p>
<p>            Storyboard.SetTarget(daOpacity, side);<br />
            Storyboard.SetTargetProperty(daOpacity, new PropertyPath(&#8221;(UIElement.Opacity)&#8221;));</p>
<p>            sb.Children.Add(daOpacity);<br />
        }</p>
<p>        private static KeySpline DefineKeySpline(double cp1X, double cp1Y, double cp2X, double cp2Y)<br />
        {<br />
            KeySpline ksStart = new KeySpline();<br />
            ksStart.ControlPoint1 = new Point(cp1X, cp1Y);<br />
            ksStart.ControlPoint2 = new Point(cp2X, cp2Y);<br />
            return ksStart;<br />
        }<br />
    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick</title>
		<link>http://joel.neubeck.net/2008/04/silverlight-3d-flip-animation/#comment-641</link>
		<dc:creator>Rick</dc:creator>
		<pubDate>Tue, 24 Jun 2008 06:43:48 +0000</pubDate>
		<guid isPermaLink="false">http://joel.neubeck.net/2008/04/silverlight-3d-flip-animation/#comment-641</guid>
		<description>Great Post!

I do have a question. Would it be easy to make the Back grid larger then the front Grid? So that if you click on the front youll get more detail on the back side and still make a good 3d animation?</description>
		<content:encoded><![CDATA[<p>Great Post!</p>
<p>I do have a question. Would it be easy to make the Back grid larger then the front Grid? So that if you click on the front youll get more detail on the back side and still make a good 3d animation?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: &#187; Silverlight Flipping Tiles Animation</title>
		<link>http://joel.neubeck.net/2008/04/silverlight-3d-flip-animation/#comment-389</link>
		<dc:creator>&#187; Silverlight Flipping Tiles Animation</dc:creator>
		<pubDate>Fri, 16 May 2008 06:36:35 +0000</pubDate>
		<guid isPermaLink="false">http://joel.neubeck.net/2008/04/silverlight-3d-flip-animation/#comment-389</guid>
		<description>[...] a few weeks ago I posted an example of how to create a 3D flip animation similar to the effect seen on an iPhone. Today I will build upon that procedural animation and [...]</description>
		<content:encoded><![CDATA[<p>[...] a few weeks ago I posted an example of how to create a 3D flip animation similar to the effect seen on an iPhone. Today I will build upon that procedural animation and [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Roh</title>
		<link>http://joel.neubeck.net/2008/04/silverlight-3d-flip-animation/#comment-352</link>
		<dc:creator>David Roh</dc:creator>
		<pubDate>Sat, 03 May 2008 13:42:39 +0000</pubDate>
		<guid isPermaLink="false">http://joel.neubeck.net/2008/04/silverlight-3d-flip-animation/#comment-352</guid>
		<description>Hi Joel,

Thank you for sharing this - it's very nice!

David</description>
		<content:encoded><![CDATA[<p>Hi Joel,</p>
<p>Thank you for sharing this - it&#8217;s very nice!</p>
<p>David</p>
]]></content:encoded>
	</item>
</channel>
</rss>
