Charles Petzold

Demos from Chapter 9 of My 3D Book

June 10, 2007
Roscoe, N.Y.

Chapter 9 of my forthcoming book 3D Programming for Windows is entitled "Applications and Curiosa." The chapter contains several demo programs that I hope will inspire my readers in using 3D in their own WPF applications.

Today I published five of these demo programs to the new 3D Programming for Windows page of my Web site. Two of them are standalone XAML files, two of them are XBAPs, and the third is a ClickOnce app that does not install on your Start menu. Of course, running these programs requires that you're running Vista or you have .NET 3.0 installed.

Knife-Switch CheckBox

Use 3D in WPF templates to turn ordinary controls such as a CheckBox into animated 3D objects like these antique knife switches used in countless mad-scientist laboratories and executions.

State Population Animator

Visualization of data gains extra dimensions when you add 3D and animation through data bindings. The graphs show population data for each state based on census data from 1790 through 2000. Move the progress bar to advance by year. Click the checkbox to see state proportions rather than totals. Move the mouse to a bar to view the state and population. Use the scrollbar at the right to get a different view.

Goblin Market

Reading online is a whole different experience when you can actually turn the pages of the book. Read Christina Rossetti's eerie and erotic poem Goblin Market by clicking the pages with the mouse.

Mouse Tracking

Getting interactive with 3D is a non-trivial exercise. This program demonstrates how to write code that lets users grab and move 3D objects with the mouse. Click one of the cubes with the left mouse button and drag it to a new location. The program is written so that objects always move parallel to the XY plane. Use the mouse wheel to move the cubes along the Z axis. Use the scrollbars to view the cubes from a different direction.

Space Station

Put on your cyan/red 3D glasses for this anaglyph of a 3D space station rotating in the darkness of deep space.

The Mouse Tracking program might not look like a big deal to people who haven't done any 3D programming, but it's harder than you might assume.

I was intending to publish the Goblin Market app to my Web site as an XBAP, but apprently the XpsDocument constructor requires full trust. (Internally, the text of the poem is an XPS file saved from Word 2007 and stored as a application resource; the program obtains Visual objects of all the pages and makes VisualBrush objects from them.)

The State Population Animator program is an XBAP, but I had to replace ToolTip controls with imitations.

The source code for these programs will be downloadable sometime before the publication of the book on July 25. You'll be able to download the source code for free without actually buying the book, but you'll definitely want to buy the book as well, if only to make me happy.