PlaneProjection for 3D effects. Part I

by Administrator 31. July 2009 07:20

Silverlight 3 is not fully but somewhat 3D. It means you cannot expect the capabilities of Direct3D (though some libraries from 3rd parties are in progress and promising) but there is enough today in SL3 to easily implement eye-catching 3D effects. In this serie, we will implement a bunch of them.

But first, in this part one, the basis illustrated by two programs you can play with, to experiment. These two programs help you to visualize the rendering of perspective transforms. The first program helps in the understanding of the basic plane transformations while the second allows you to animate projections.

To provide these 3D effects, you just need to implement a plane projection, ie a transformation that gives perspective to a 2D plane surface. For instance (here a PlaneProjection applied to an image but it's applicable to buttons, complex forms, grids, ie anything that has a visual 2D representation) :

 <Image Source=..... >
  <Image.Projection>
   <PlaneProjection ..... >
  </Image.Projection>
 </Image>


PlaneProjection has a few attributes you need to know, each with X, Y and Z variants : first Rotation (thus RotationX, RotationY and RotationZ) to specify rotation angles, then CenterOfRotation (thus CenterOfRotationX, CenterOfRotationY and CenterOfRotationZ) to specify axes of rotation. With just these two attributes (well, six...), you can already perform a lot. To go a bit further, there are LocalOffset and GlobalOffset (again, with the X, Y and Z variants) to specify two types of translation. Let's forget LocalOffset and GlobalOffset for the moment.

Before experimenting, a few words about the axis. The X-axis is horizontal, from left to right. The Y-axis is vertical, from top to bottom. The Z-axis is perpendicular, from inside to outside of the screen. With RotationX, we rotate a surface (for instance an image) around the (horizontal) X-axis. The rotation angle is expressed in degrees. As expected, with RotationY, we rotate the surface around the (vertical) Y-axis. With RotationZ (and with other default values), we rotate the surface around the center point, without leaving 2D space (by default, rotation around the center of the surface). Take time to experiment with the first program to feel at ease.

With CenterOfRotation, we change rotation axis. CenterOfRotationX and CenterOfRotationY are in the 0 to 1 range. CenterOfRotationX has an influence on RotationY while CenterOfRotationY has an influence on RotationX. Both have an influence on RotationZ.

0 in CenterOfRotationX corresponds to the left side of the surface (the one we apply the PlaneProjection) and 1 to the right side. A RotationY operation is then performed around a vertical axis that doesn't anymore traverse the surface center (though this new vertical rotation axis remains parallel to the Y-axis).

0 in CenterOfRotationY corresponds to the top side of the surface and 1 to the bottom side. RotationX is then performed around an horizontal axis that is parallel to the X-axis.

CenterOfRotationZ indicates a distance along the Z-axis. If attribute CenterOfRotationZ has a value of -200 (the point is then behind the screen) and you perform a RotationY operation, a rotation is performed around a vertical axis that traverses the point at -200 along the Z-axis. As the surface (an image or a form in the following program) is rotated, it appears smaller and smaller (the image is moving away) until RotationY reaches the value 180. If rotation continues, the surface appears larger and larger (the image is coming back to you), to its original size when RotationY reaches the value 360.

Let's experiment.

When a surface is rotated, the content disappears (it becomes very thin) and then, the back of the surface becomes visible ! Funny to discover the back side of pixels (as if the surface was drawn on a pane of glass) but unfortunately rarely realistic. This is a problem we will have to solve. Do not expect to solve the problem with a surface made of two consecutive images : the first one will not become the back side of the second one (Silverlight will only take the last one into account).

Now, let's explain LocalOffset and GlobalOffset. Both perform a translation (along the X, Y and Z axis, depending on the variant). GlobalOffset performs a translation along the X, Y and Z axis of the screen. These are fixed and unaffected by Rotation operations. X is always horizontal (from left to right) and Y always vertical (from top to bottom). GlobalOffset is always performed as the last transform, just before painting on the screen.

LocalOffset is performed after the rotation. This rotation (that depends on Rotation attributes) changes axis : if RotationZ is 90 (anti-clockwise rotation with positive values), the X-axis becomes vertical (from bottom to top) ! LocalOffsetX performs then a translation along the newly configured X-axis. GlobalOffsetX would always perform an horizontal translation. If no rotation is specified in the PlaneProjection attributes, LocalOffset and GlobalOffset have the same effect.

Experiment with the following program. Be careful, since some attributes are initialized (for the automatic animation), reset them to reinitialize with default values.

In the following posts, we will make use of these PlaneProjection.

Tags:

Comments

8/1/2009 12:00:30 AM #

PlaneTransform

Thank you for submitting this cool story - Trackback from NewsPeeps

NewsPeeps

8/2/2009 3:07:45 PM #

PlaneProjection for 3D effects. Part I

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

progg.ru

8/9/2009 11:53:58 AM #

Really cool demo, could you adapt this to do Beryl wobbly windows - http://www.youtube.com/watch?v=icm7GGCPOt8.
I was playing with a sample but could not get to quite work cid-289eaf995528b9fd.skydrive.live.com/.../wobbly.zip

slyi Ireland

8/11/2009 3:40:52 AM #

Nice post! GA is also my biggest earning. However, it�s not a much.Smile

cash loans United States

8/11/2009 3:40:55 AM #

A SUPPORTED BY THE DEVELOPER TOOLS? It was interesting. You seem very knowledgeable in ypour field.

cash loans United States

8/14/2009 1:45:04 PM #

There are certainly a lot more details to take into consideration, but thanks for sharing.

Buying Selling Home United States

8/20/2009 4:43:07 AM #

We�re reading, keep writing! Thanks for explaining!

Acoustic Electric Guitar United States

8/25/2009 2:43:54 PM #

I usually don�t post in Blogs but your blog forced me to, amazing work.. beautiful �

bad credit loans United States

8/25/2009 2:43:58 PM #

Hi, I can�t understand how to add your site in my rss reader. Can you Help me, please Smile

bad credit loans United States

8/28/2009 8:29:30 PM #

Would you mind me asking where did you find a theme for this blog, looks cool.

Jack United States

8/28/2009 8:29:32 PM #

Blogengine yay, this is one of my favorite blog platforms!

Jack United States

9/2/2009 6:20:21 AM #

Hello, maybe this is off topic but anyway, i've been browsing around your site and it looks really really neat. I'm building a new blog and struggling to make it look good, everytime i touch something i mess it up. How hard was it to build your site? Could someone like me with no experience do it, and add family update pages without wrecking it every time?

where to buy salvia seeds United States

9/2/2009 6:20:24 AM #

Hi, would you please be so kind to show me how to add your rss feed to my feed reader, that would really help a lot, as i want to follow your blog, thanks so much.

where to buy salvia localy United States

9/15/2009 7:53:23 AM #

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts.Any way Ill be subscribing to your feed and I hope you post again soon

payday online United States

9/15/2009 3:57:59 PM #

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/16/2009 1:46:54 AM #

I don�t usually reply to posts but I will in this case. WoW Smile

payday loan United States

9/16/2009 1:46:58 AM #

Hello Guru, what tempt you to post an article. This article was exceedingly fascinating, especially since I was searching for thoughts on this subject last Thursday.

payday loan United States

9/16/2009 5:15:37 PM #

Easy option to get useful information as well as share good stuff with good ideas and concepts

payday loans United States

9/20/2009 12:29:04 AM #

I'd love to have a blog like this, great theme btw.

Gabriel Method United States

9/20/2009 12:29:06 AM #

This is some good stuff, definitely worth bookmarking, thanks much!

Gabriel Method United States

9/23/2009 7:44:23 PM #

Wow! what an idea ! What a concept ! Beautiful .. Amazing �

payday loans United States

9/23/2009 7:44:28 PM #

Hello. Great job. I did not expect this on a Wednesday. This is a good story. Thanks!

payday loans United States

9/30/2009 11:30:32 AM #

PlaneProjection for 3D effects. Part I

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

Tiffany Rings People's Republic of China

10/6/2009 7:18:14 AM #

Hello Guru, what entice you to post an article. This article was extremely interesting, especially since I was searching for thoughts on this subject last Thursday.

personal loan United States

10/6/2009 7:18:18 AM #

Thank you for your help!Thank you and My best regards! Thank you and Sorry for so many questions but i really need your help.

personal loan United States

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