PETZOLD BOOK BLOG

Charles Petzold on writing books, reading books, and exercising the internal UTM


Recent Entries
< PreviousBrowse the ArchivesNext >
Subscribe to the RSS Feed

A Rotating *Solid* Cube in Silverlight 3

August 6, 2009
Roscoe, N.Y.

Much time has passed since I posted a blog entry describing how to make a rotating wireframe cube in Silverlight 3, which I then proclaimed was about as far as Silverlight could go. I later realized that I could use Canvas.SetZIndex to order elements from foreground to background, and I could calculate shades based on surface normals and hypothetical lighting vectors. I have now persuaded Silverlight 3 to render a rotating solid cube:


RotatingCube.html

On the web page, the cube on the left is animated; the one on the right can be turned horizontally and vertically using the sliders. (I'm using an orthographic camera projection here — i.e., no perspective — and if you think the rear of the cube looks larger than the front, that's an optical illusion where your mind tries to project prospective into the image.)

The source code is in no state to be posted at this time. It needs a considerable amount of refactoring and cleaning up and testing with other types of simple figures. (The dodecahedron is next.) But keep in mind that the techniques I'm developing here cannot be used to simulate full-blown WPF-like 3D in Silverlight. The only clipping that's going on is on the 2D level based on the normal Canvas.ZIndex attached property, and it's easy to come up with examples where this technique will fail.

It's also not clear to me how much interest there is in this stuff. I've only gotten a little feedback from previous blog posts about simulating 3D in Silverlight, so I'm not sure it's really worth my time to get the code in usable shape for public consumption. Let me know.

Also, while working with the 3D transforms and other algorithms to get this program working, I found myself consulting a book on WPF 3D that I wrote two years ago, and which you might also find of use in understanding some of the complex mathematics involved. (Although it seems pretty hopeless at this time, if this book were to sell several thousand more copies, I might be able to persuade my publisher to let me get back into the book-writing business!)

Amazon.com BookSense.com Barnes & Noble
Amazon Canada Amazon UK Amazon Français
Amazon Deutsch Amazon Japan

Comments:

For whatever it's worth, I would certainly like to see how it was done.

I observe that, to run the animation, it takes roughly 1/3 of a single core on a Intel Q6600 (quad core, 2.4 GHz) after setting IE's process affinity to one core. Not unexpected given the nature of Silverlight but it does limit the applications somewhat.

— GrumpyYoungMan, Thu, 6 Aug 2009 20:04:59 -0400 (EDT)

Being platform independent, Silverlight can't take advantage of any hardware acceleration on the graphics board. — Charles

Charles, I'm a big fan of your blog though I have to admit I'm most interested when you put on your math/graphics geek hat. I've been buying your books for years (including the 2 covering WPF) so I'm hoping you can continue to write books. It's clearly what you enjoy doing most.

On topic: are you aware of SLKIT3D ? It is a 3D software engine for Silverlight 2. Should work okay for SL3 I guess.

https://Kit3D.svn.codeplex.com/svn

Keep up the writing, blog-wise or book-wise :-)

Sven, Mon, 10 Aug 2009 05:13:35 -0400 (EDT)

Hi Charles,

I am interested in seeing how you do the 3D in Silverlight.

I bought your WPF 3D book and used it to implement some CAD rendering. 3D has always been a big interest of mine.

Your examples are cool because they show what can be accomplished with limited tools.

— Doug, Mon, 10 Aug 2009 08:03:00 -0400 (EDT)

Hello

I have been trying to make something just like this example but have been really struggling, I am really interested in making something like the 3D cube on the right with the sliders, I was wondering if you had had a chance to refactor the code as you mentioned or if you had posted it anyway so that I could try to understand how this is done.

Many thanks for any help.

Richard, Tue, 15 Dec 2009 12:35:11 -0500


Recent Entries
< PreviousBrowse the ArchivesNext >
Subscribe to the RSS Feed

(c) Copyright Charles Petzold
www.charlespetzold.com