PlaneProjection for 3D effects. Part III : carousels

by Administrator 17. August 2009 00:28

Let's make use of PlaneProjection to program other 3D effects : carousels in this post.

First a simple one, to show how easy it is : just a few lines of code !


Project / source code

The images are not included in the xap file as internal ressources, they are loaded from the web server at run time (to do so, the images must be copied in the ClientBin folder, the one that contains the xap file to be published).

We define a playing ground for the carousel :
 <Grid x:Name="ground" Width="400"  />

The code is self-explanatory (just a bit of very basic geometry to put each image at different angle) :
 string[] arImageNames = { "Amsterdam", "London", "Moskow", "Paris", "Pisa", "Roma",
                           "TajMahal", "Venice" };
 Image[] arImages;
 public MainPage()
 {
  InitializeComponent();
  InitializeCarrousel();
 }
 private void InitializeCarrousel()
 { 
  Storyboard stb = new Storyboard();
  int N = arImageNames.Length;       // number of images
  arImages = new Image[N];
  // for each image
  for (int i = 0; i < N; i++)
  {
   // load image first from the server
   arImages[i] = new Image();
   arImages[i].Width = 150; arImages[i].Height = 150;
   arImages[i].Source = new BitmapImage(new Uri(arImageNames[i] + ".jpg", UriKind.Relative));
   // prepare an image for the carousel
   Image img = new Image();
   img.Width = img.Height = 150;
   img.Source = arImages[i].Source;
   img.Stretch = Stretch.Fill;
   // prepare rotation around the Y-axis
   PlaneProjection pp = new PlaneProjection();
   pp.CenterOfRotationZ = -250;  // center behind the screen
   img.Projection = pp;
   // prepare the animation
   DoubleAnimation da = new DoubleAnimation();
   da.From = i * 360 / N;     // each image at different angle
   da.By=360; da.Duration = TimeSpan.FromSeconds(10);
   da.RepeatBehavior = RepeatBehavior.Forever;
   Storyboard.SetTarget(da, pp);
   Storyboard.SetTargetProperty(da, new PropertyPath("RotationY"));
   stb.Children.Add(da);
   
   // add image to the carousel
   ground.Children.Add(img);
  }
  this.Resources.Add("stb", stb);
  stb.Begin();
 }

Let's now create a more sophisticated carousel :


Project / source code

We replaced each image with a stack panel made of :
- a semi-transparent black rectangle,
- an image,
- another semi-transparent black rectangle.

A bit more geometry to compute the width of each semi-transparent rectangle.

To change speed, we handle the MouseMove event in a colored rectangle and change the Duration property of each animation (as many as images to be displayed). To change rotation, we need to stop the animation and restart it.


To end the day, another carousel :


Project / source code

Each city is displayed as a TextBlock inside a border. For each such border, we add 6 containers (again borders). Doing so, the figure looks more as a circle. The trick is to compute the height of each elementary border : we fixed the

height of each display panel, we know how many cities we have. And we know from basic geometry that a circonference is 2*PI*radius...

 

Tags:

Comments

8/17/2009 3:58:53 AM #

PlaneProjection for 3D effects. Part III  : carousels

Thank you for submitting this cool story - Trackback from DotNetShoutout

DotNetShoutout

8/17/2009 7:24:15 PM #

PlaneProjection for 3D effects. Part III : carousels

Thank you for submitting this cool story - Trackback from progg.ru

progg.ru

8/18/2009 3:13:32 AM #

Thanks so much! It's realy cool story!

calabonga Russia

8/18/2009 6:56:07 PM #

Excelente, muchas gracias por la aportación y por no guardar el conocimiento solo para ti.

Saludos!!!

Arturo Mexico

8/22/2009 11:39:40 AM #

Silverlight 3 : RIA Services for your LOB Applications – Part 3

I hope the first two part of this series are useful for your development on RIA Services. There is lot

Community Blogs

9/11/2009 2:37:52 PM #

It is indeed a great resource to obtain information on this subject. Keep posting. Thanks.

Enduring Power Of Attorney United Kingdom

9/15/2009 7:02:46 AM #

PlaneProjection for 3D effects. Part III  : carousels

DotNetBurner - burning hot .net content

DotNetBurner - Silverlight

9/15/2009 10:54:34 AM #

I havent any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.

payday online United States

9/19/2009 6:30:49 PM #

Howdy, i read your blog occasionally and i own a similar one and i was just wondering if you get a lot of spam comments? If so how do you prevent it, any plugin or anything you can advise? I get so much lately it's driving me mad so any assistance is very

Orlando criminal defense United States

9/19/2009 6:46:27 PM #

Well, this is my first visit to your blog! We are a group of volunteers and starting a new initiative in a community in the same niche. Your blog provided us valuable information to work on. You have done a marvellous job!

Orlando divorce attorney United States

9/22/2009 9:39:31 AM #

Pingback from silverlike.net

3D Menu Carousel using PlaneProjection | Silverlike - We Like Silverlight

silverlike.net

9/24/2009 4:49:23 PM #

Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck!

California toxic torts attorney United States

9/24/2009 11:21:30 PM #

Hello,

Currently I was researching a subject on divorces for our German divorce website (http://perspektive-scheidung.de) when I discovered your site. Actually, I didn't find exactly what I was looking for. However, I was impressed by your professional looking site. So I decided to leave you a little note.

Kind regards,
E. Scheidung

Scheidung Germany

9/24/2009 11:21:30 PM #

Hello,

Currently I was researching a subject on divorces for our German divorce website (http://perspektive-scheidung.de) when I discovered your site. Actually, I didn't find exactly what I was looking for. However, I was impressed by your professional looking site. So I decided to leave you a little note.

Kind regards,
E. Scheidung

Scheidung Germany

9/30/2009 11:29:43 AM #

PlaneProjection for 3D effects. Part III : carousels

Thank you for submitting this cool story - Trackback from progg.ru

Tiffany Rings People's Republic of China

9/30/2009 6:22:57 PM #

I just bookmarked your site because I am impressed with the info that you keep on sharing. I plan to do try the carousels in my personal portal that features some family photos.

Erik B. United States

10/5/2009 6:00:44 PM #

Dude.. I am not much into reading, but somehow I got to read lots of articles on your blog. Its amazing how interesting it is for me to visit you very often

Houston mesothelioma lawyers United States

10/8/2009 5:41:44 PM #

valuable information and excellent design you got here! I would like to thank you for sharing your thoughts and time into the stuff you post!! Thumbs up

Pinball games United States

10/8/2009 8:38:42 PM #

I never imagine that this was very easy and the duration and span was perfect on timing. This 3d effects  carousels rules and you have great coding skills.

Abrahamsen Denmark

10/9/2009 10:01:38 AM #

Never realized this before, but you have a very high-quality tip indeed

buying property solicitor United Kingdom

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About the author

Gerard Leblanc is the author of several books (in french) on C++, C#, .NET and Silverlight (Eyrolles, Paris as publisher). See www.gleblanc.eu as the companion web site for these books (included sample programs).
He is Microsoft MVP for Silverlight.

MVP logo