Book Discussion Page: WPF 3d

[WPF 3d]

This is a discussion page for my book WPF 3D, Three-Dimensional Graphics with WPF and C#. Please post questions, thoughts, and suggestions here in the “Leave a Reply” box at the bottom of the page. I will moderate posts and reply as appropriate.

[ OverviewTable of ContentsQuestions and DiscussionErrataSample PicturesSource Code (17.2 MB) ]

[ Buy at: Amazon ]

Follow me on Twitter   RSS feed   Donate

About RodStephens

Rod Stephens is a software consultant and author who has written more than 30 books and 250 magazine articles covering C#, Visual Basic, Visual Basic for Applications, Delphi, and Java.
This entry was posted in 3D, 3D graphics, algorithms, books, drawing, graphics, mathematics, Uncategorized, wpf, XAML and tagged , , , , , , , , , , , , , , . Bookmark the permalink.

28 Responses to Book Discussion Page: WPF 3d

  1. Pingback: WPF 3d: Table of Contents - C# HelperC# Helper

  2. Pingback: Book Sample Pictures: WPF 3d - C# HelperC# Helper

  3. Pingback: Book Errata Page: WPF 3d - C# HelperC# Helper

  4. John M says:


    I just purchased your book on Amazon, should get here shortly. It’s great to have another book on 3D programming with WPF, I have Charles Petzold’s book “3D Programming for Windows” as well. Although I have a graduate in Comp Science, I never got into 3D stuff, basically staying with OS design and low level programming. However, a project my employer started me on using the MPU-9250 has changed much of this – basically I have to project a 3D object’s gyro movements via a USB link to a computer. As well, I have started into 3D MAX to further my development in this field, proving an old tiger might be able to change stripes!

    • RodStephens says:

      Hi John,

      I hope you enjoy the book! Let me know if you have questions as you work through it. Or if you create any cool pictures, please post them.= so everyone else can see! And, of course, post a review on Amazon if you have a chance.

  5. Kyle says:

    Hi Rod,
    I was wondering if your WPF 3D book is available in an electronic version such as PDF or Kindle. If not, is this something that you are considering.
    This is my first time on your site and all of your work looks intriguing.
    Thank you.

  6. Ibrahim Konuk says:


    I got the book in the weekend. Literally, I could not drop it from my hand. It is a superb book. Your helper functions and their algorithms are superb. I wish I could think of them earlier. I am developing a scientific (engineering) application which requires some 3D visualizations and I was in the process of testing Helix 3d wpf toolkit which works. But your approach is going to get rid of a lot of overhead and will give me a lot more flexibility to design my program.

    I am now diving into the material in the book. I will post any comments or suggestions as I go along. My initial intuition tells me the perhaps I can suggest alternative triangulation algorithms using Delaunay triangulation or Voronoi diagrams. I will let you know when I get there.

    Thank you again for writing a beautiful book.


    • RodStephens says:

      Hi Ikonuk,

      Thanks for the kind words. Post a review when you have a chance!

      I thought about making Delaunay triangulations but decided that it was too much work. There are also some related topics such as making three-dimensional splines to define surfaces. I decided not to include those, mostly to save space and to focus on the graphics and not spend as much time on those algorithms.

      If you build something that you think others might find useful, feel free to post a link in the comments.

  7. John S says:

    Thanks for the book. I just got it. I’m using VS2012 I bought a while back. I’m also on Windows 8.1 Professional. I got busy and entered the code in a WFP project and it compiles fine, I just cant see a Cube. Chapter 2. Since it compiles without any issues I would expect a Cube to display. Anyway I downloaded the source and I will see if there are any discrepancies between what I have and what you have. Have not tried the XAML example yet; Chapter 1. I will try that to. Looking forward to seeing it all work and adding graphics to my projects. I will let you know if I run into any ongoing issues, or what I did to correct them. The only thing I can think of currently the issue may be a setting in VS2012 I’m missing. If you have any knowledge on this please share.

    • RodStephens says:

      I don’t know why it wouldn’t work in VS 2012. I have written similar programs in VS 2008 and they work just fine. There may be some property set on the controls or perhaps the control hierarchy is slightly different. Please post what you find so we can all see what the difference is.

  8. Daniel says:

    Hello, Dear Rod, I’m interested in your book ‘WPF 3d: Three-Dimensional Graphics with WPF and C#’, But i have a question:
    I want to learn 3D from the basics, i want to learn all the math of 3D, Projections and all the process of making a 3D scene absolutely from scratch (Converting 3D Coordinates to screen coordinates, etc, etc), I don’t want to use any of WPF’s built in 3D capabilities, I don’t want to use any 3D library, What i want is to learn how to create my own 3D world totally from zero. (In C# WPF of course).
    Are these issues discussed in your book?

    • RodStephens says:

      Unfortunately that book doesn’t cover the underlying mathematics. It does cover some important stuff like the coordinate systems and how to produce different kinds of projections (like orthographic and cavalier).

      My book “Visual Basic Graphics Programming” covers that, but it’s not the main focus of the book, so there are only 5 chapters about 3D graphics, and one of those is about ray tracing.

      If you want to build your own, you might want to consider ray tracing. It produces a result that is better in many ways and in some ways it is more elegant. It is also slower, but if you do this yourself, you’re not going to get stunningly fast performance in either case. (I’ve written a book about ray tracing as a follow-on to “WPF 3d” but haven’t had the time to publish it yet. I really need to do that.)

      Also note that WPF probably won’t give you a lot of help if you want to do this with your own code, so you could use Windows Forms instead. The big advantage of WPF is the 3D viewport, which you won’t be using.

      • Leonardo says:

        I’ve been looking for this other book too and found it seems the first chapter contents can be found in another book but not the others. Isn’t there any other more up-to-date book with this content? I have found it to be very expensive (at least here in Brazil) for a 20+ yo book.

        • RodStephens says:

          If you mean “Visual Basic Graphics Programming,” then yes it is an older book that is out of print. You may be able to get a used copy somewhere like ebay, but I doubt you can find a new copy.

          There are other books that cover the mathematics of 3D graphics. They tend to be more academic and use pseudocode instead of C#. If you search Amazon for “mathematics of 3d graphics” you’ll see some books that may help. (All books are pretty expensive these days, though. 🙁 )

          • Leonardo says:

            Yes, it was about that book. It would be great if there was such a book with C# examples but I’ve found some on Amazon and will check them out. Thanks.

          • RodStephens says:

            Note that that book was written for Visual Basic 5/6. You may find the mathematics and ideas interesting, but the code won’t translate into .NET very well.

  9. Daniel says:

    Thank you!! Very appreciated!! So helpful!!

  10. Hornebom says:

    Hello, just started with the book and I have a question.
    Chapter 1, first example (cube):
    why did you define 24 points, 8 should have been sufficient?

    • RodStephens says:

      In WPF (and at least some other 3d modeling tools) if two triangles share a point then the system smooths them so the edge between them is not visible. For example, that’s how you can make a sphere look smooth rather than built out of a bunch of triangles.

      The cube example uses separate points so you can see the edges of its sides. The two triangles that make up a side can share, so we need 4 points per side for a total of 24.

      You might want to try making the cube with just 8 vertices to see the result. It’s pretty interesting and very confusing if you don’t know what’s happening.

  11. Allen Tanner says:

    The book arrived yesterday. I got the cube working. I followed your advice and started to fiddle with the code. I wanted to create a button that would change color from light blue to say red.
    I tried this:

        material = new DiffuseMaterial(Brushes.LightBlue);
        GeometryModel3D model = new GeometryModel3D(mesh, material);
        int c = group.Children.Count;
    private void Button_Click(object sender, RoutedEventArgs e)
    private void CButton_Click(object sender, RoutedEventArgs e)
        material = new DiffuseMaterial(Brushes.LightBlue);
        GeometryModel3D model = new GeometryModel3D(mesh, material);
        group3d.Children[2] = model;

    group3d.Children[2] is where the GeometryModel3D object is located. This made the image disappear. Is there a better way than [2] to navigate the group3d data structure?

    • Allen Tanner says:

      Never mind. I got it working. Indexing group3d.Children[2] works but it doesn’t seem the right way to find where to change the data structure.

      • RodStephens says:

        Sorry I didn’t reply sooner. I’ve been crazy busy tech editing some books for other authors.

        I think if you save a reference to the model that you want to change, you can change that object’s material without using its location in the child array. Some of the examples later in the book, notably in Chapter 32, show how to change materials. Basically they just change the material for the object that you select with the mouse.

  12. yass says:


    i notice a behaviour that i don’t expect when i use a spherical camera.
    If i increase the Phi angle (up down keyboard for example) , the scene rotate well. But when the phi angle reach 180°, there is like a projection of my scene and the rotational direction changed.
    When the angle theta change (right left keyboard), the rotation is ok and i don’t notice the same behaviour. It is possible to have the same behaviour (like theta angle) for these 2 rotation axis.


    • RodStephens says:

      There is a difference because phi and theta don’t work the same way. You can rotate around and around with theta. With phi, at some point you are above the scene looking down (or below looking up). When phi passes 90 degrees, you switch from going up to going down. (Similarly if you go past -90 degrees.)

      Imagine trying to film a scene with a handheld camera IRL. You can circle your subject but something weird happens with you cross phi = 90 degrees.

      Most 3D systems (that I know of at least) prevent this by not allowing phi to go above 90 or below -90. In a 3D gaming system, for example, you might restrict phi even further and not allow it to go outside +/-80 or something. That’s kind of realistic because your neck can’t bend that far anyway.

      So, sorry, there’s not much you can do about that except decide what you want the program to do when phi gets too big or small.

Comments are closed.