Custom Animations, the GenieAnimation

Several weeks back I had posted a simulation of the Genie effect that you see in Mac OSX. Ofcourse it was created using the Windows Presentation Foundation ;) However the effect could only be used in that specific demo. There was no way for example to use it in my other projects, which were also desperately asking for some cool animations. Since then I went through a couple of iterations and made the Genie effect into a reusable animation. This was possible because the WPF animation system makes it pretty easy to create Custom animations. So what I have now is a class called GenieAnimation that can be used directly in XAML.

Here is an example of using the GenieAnimation inside a Storyboard:

<Storyboard x:Key="GenieAnim">
<local:GenieAnimation Storyboard.TargetName="SlidingScreen"
              Storyboard.TargetProperty="Geometry.(MeshGeometry3D.Positions)"
              AspectRatio="1.25"
              HorizontalPoints="25"
              VerticalPoints="25"
              EffectType="IntoLamp"
              LeftPoint2="0.75,0.333,0"
              LeftPoint4="1,1,0"
              RightPoint3="0.25,0.667,0"
              Duration="0:0:1"
              AccelerationRatio="0.5"
              DecelerationRatio="0.5"
/>
</Storyboard>

Note that there are some extra properties like AspectRatio, HorizontalPoints, VerticalPoints, EffectType, etc. These are custom dependency properties defined on the GenieAnimation class. Also note that the Storyboard.TargetProperty for the animation is of type System.Windows.Media.Media3D.Point3DCollection. If you look under the WPF namespaces then you would not find any animation defined for this type. So I had to create an abstract Point3DCollectionAnimationBase class that sets the TargetPropertyType to Point3DCollection. This is as per the SDK article on custom animations. The GenieAnimation then derives from Point3DCollectionAnimationBase.

What I really like about the GenieAnimation is that I get lot of cool stuff for Free, just for being a citizen of the WPF animation system. This includes features like AutoReverse, RepeatBehavior, AccelerationRatio, DecelerationRatio, etc. To do these things in my previous implementation would have required lot of extra code!

Using the GenieAnimation

To make use of the properties that control the GenieAnimation, you will have to know a little bit about how the animation works. I have already spoken about it in my earlier post. But let me go over it again. The GenieAnimation works over the MeshGeometry3D.Positions property (type: Point3DCollection). In every time interval the animation updates the mesh positions and transforming the mesh from its rectangular form to the more curvaceous genie-form. The genie is created by two beziers, one on the left and one on the right. The left bezier can be specified by the 4 control points: LeftPoint1, LeftPoint2, LeftPoint3, LeftPoint4. The same works for the right bezier: RightPoint[1-4].

Since the Genie is really a mesh, you also need to tell me how smooth a mesh you want to use. This is specified using the HorizontalPoints and VerticalPoints property. The value 25 works very well for these two properties. The AspectRatio property is a technical detail, that I really want to hide. This is used when creating the mesh positions. The value for this property depends on the size of your Viewport3D object, so in most cases you would just use Viewport3D.ActualWidth / Viewport3D.ActualHeight as your AspectRatio.

Out of all the properties, my favorite is the EffectType, which can be either IntoLamp or OutOfLamp. IntoLamp creates a suction effect and sucks in the mesh, whereas OutOfLamp releases the genie out of the lamp ;)

A Video demonstration

Yes! a video of the GenieAnimation. In the video I modify various properties of the GenieAnimation and then run the app. So you will see me switching between Visual Studio and the app window.

 
Technorati tags: , , , ,

Similar Posts:

10 responses to “Custom Animations, the GenieAnimation”

  1. Pavan Podila

    I am still in mixed minds about how I can release the source. Part of it is using some proprietary code. I am thinking of making it available as an assembly to start with. What do you guys feel about that ??

  2. (no name)
    would love to have a go at using this, is that source likely to surface ;)
    many thanks and respect
    Si. 
  3. Pavan Podila

    Wow! The Quark UI looks pretty sweet

  4. daBoman
    Could you make this example into something like the nvidia gui Demo … thinks it looks nice :D

    http://gizmodo.com/gadgets/gadgets/nvidias-quark-smarphone-shows-its-ui-237215.php

  5. saiku73
    It would be great if you could release the source for this. Good work.
  6. Pavan Podila

    Hi Reno,
           Thanks for your interest! I would love to put the source online as soon as I finish refactoring my libraries. Right now there is some proprietary stuff surrounding this code, which I need to remove before making it public.

  7. Reno
    Fantastic stuff!  Any chance you’re going to make the source available for the animation effect?
  8. MJC

    cool animation, keep the good work!

  9. TransitionContainer added to FluidKit | Pixel in Gene

    [...] there are several classes that have been added. The most important of the lot is GenieAnimation, a custom animation class that animates a 3D mesh to simulate the popular Mac OSX Genie effect. The [...]

  10. freeman

    Hi,
    How to use the class “GenieAnimation”?
    Can you show a whole sample?
    Thanks!

Leave a Reply