Reputation: 2538
Say I have a WPF form to enter a tube diameter and tube height, and I want to visualize the tube entered by the user.
I've found a few tutorials to 3D but they are too complex for me to get started. Hoping someone could kickstart my 3D understanding. It would be great if this was possible using only XAML... :)
Upvotes: 0
Views: 1437
Reputation: 14640
This is possible mostly using XAML, you create an object that's a tube of length 1 and diameter 1, and then use the entered values to scale the tube appropriately. If you're using the MVVM pattern, you can bind the TextBoxes that the user uses to enter the diameter and height to properties in the ViewModel, and then bind the scaling matrices to those values too.
For the tube, you need two sets of vertices, both points on a circle, at e.g. y=0 and y=1. The x and z coordinates will be cos(angle) and sin(angle) respectively, for angle between 0 and 360 degrees/2Pi radians. The more values you use the smoother the tube will appear, 10 to 15 is a good starting point. To make the tube appear smoother you can use shared normals, which will fake smoother sides by fudging the lighting. The normals for a vertex in my example above are the same as the base of the tube: cos(angle), 0, sin(angle), for both the top and bottom vertices. To create the XAML that describes this shape you're best off reading some XAML 3D primers, that way you'll understand what it's doing.
Upvotes: 1