Hey guys, Im working with wpf 3d, im currently writing a program that will create 3d tiles across the screen left to right, But i need to know what my bounds are on the X, Y i.e (-x-0) (0-x+) so I know when to start another row of tiles. My initial thoughts are trying to figure out a complex algorithm to go from pixels to screen coordinates, however it seems like there should be an easier way.
If I understand you correctly, you want to find out what range of 3D coordinates are visible through your Viewport3DVisual.
This question does not have a single answer. To see why, imagine you are sitting at your kitchen table eating breakfast and happen to look through the window. What horizontal range can you see? Well, you can see about five miles of those blue mountains off in the distance but only thirty feet of your back fence. In other words, the viewable area is not a rectangle prism but rather a pyramid.
The bottom line is, you'll have to specify the distance involved before it is meaningful what horizontal and vertical range are visible through the viewport.
Once you have specified a distance, here is how to map your viewport to 3D points on a given plane without doing all the calculations yourself:
- Create model in a separate Viewport3dVisual, using the same camera settings but with a model consisting solely of a single large rectangle at the desired distance.
- Use hit-testing to test each corner of the viewport, receving a hit test result callback.
- Extract the coordinates on the rectangle from the hit test result and use them for your calculations.
This technique has the advantage of working reliably wherever the camera may be facing, and even works for animated cameras and such.
Note: If I misunderstood the question, and you are merely asking about laying out rows of tiles in 2D that will contain 3D content, then you can get the effect you describe by simply using an WrapPanel. If you want to data bind, use an ItemsControl or ListBox with a ItemPanelTemplate of a WrapPanel.