Relationship between Viewport3D and GeometryModel3D?

I use Viewport3D in my WPF application. I use VisualBrush for the Material of the Model3D.I want the appearance of the 3D model the same size as my actual window(which the VisualBrush is from), and I want to control the size of the appearance at runtime time according to my actual window.

I don't know how to transform the Camera(PerspectiveCamera), or the GeometryModel3D, or the Viewport to let the perspective on the ViewPort3D to be the same size as my actual window

And what is the relationship between the Viewport3D and the GeometryModel3D in it



Answer this question

Relationship between Viewport3D and GeometryModel3D?

  • builtbikes

    Thank you very much,

    Is the ViewPort3D is exactly what we see on the screen or there is another transfrom between ViewPort3D to Screen

    I don't know what it meens indeed : (


  • pdaitguy

    The relationship between the two is a series of transforms. Using these transforms, you can find out what four points in 3D map to the 2D corners of the window

    Point3D * [ GM3D.Transform * (... parent Model3DGroup.Transforms ...) * (... parent ModelVisual3D.Transforms ...) * Camera.Transform^(-1) * Camera.ViewMatrix * Camera.ProjectionMatrix ] = Point

    Let's call the combination of all the transforms in the [ ]'s "M." Make each of your 2D window corners into 3D points like (x, y, 0) and multiply it by M^(-1) and that should give you your four points in 3D.

    Issues:

    1. You can't "walk up" from the GM3D to the Viewport3D to gather the transforms since M3Ds don't have parent properties. You'll have to walk down from the Viewport3D until you hit the GM3D you care about. I think 3DTools has methods that do this.
    2. PerspectiveCamera and OrthographicCamera don't expose the ViewMatrix and ProjectionMatrix properties. 3DTools has methods to compute them for you given the Camera.
    3. M might not be invertible depending on the transforms you set.
    4. I didn't test this. It "should work" ;)


  • Vishalbhambure

    Oh, wait, there's another 2D transform that happens at the end that I forgot about. Rather than have you duplicate that, just multiply the points:

    1. (-1, 1, 0)
    2. (1, 1, 0)
    3. (-1, -1, 0)
    4. (1, -1, 0)

    by M^(-1).

    If you're curious about the additional 2D transform I can explain it.


  • Relationship between Viewport3D and GeometryModel3D?