关于WPF的问题。 Viewport3D中的大小

时间:2010-08-25 16:47:00

标签: wpf xaml viewport3d

<Window x:Class="Viewport2DVisual3DExample.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Button on 3D"  
    WindowStyle="None"
    Background="{x:Null}"
    Foreground="{x:Null}"
    AllowsTransparency="True"
    >

    <Viewport3D>
        <Viewport3D.Camera>
            <PerspectiveCamera Position="0, 0, 4"/>
        </Viewport3D.Camera>

        <!-- Front -->
        <Viewport2DVisual3D>
            <!-- Give the plane a slight rotation -->
            <Viewport2DVisual3D.Transform>
                <RotateTransform3D>
                    <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D x:Name="frontTransform" Angle="0" Axis="0, 1, 0" />
                    </RotateTransform3D.Rotation>
                </RotateTransform3D>
            </Viewport2DVisual3D.Transform>

            <!-- The Geometry, Material, and Visual for the Viewport2DVisual3D -->
            <Viewport2DVisual3D.Geometry>
                <MeshGeometry3D Positions="-1,1,0 -1,-1,0 1,-1,0 1,1,0"
                                TextureCoordinates="0,0 0,1 1,1 1,0" TriangleIndices="0 1 2 0 2 3"/>
            </Viewport2DVisual3D.Geometry>

            <Viewport2DVisual3D.Material>
                <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" Brush="White"/>
            </Viewport2DVisual3D.Material>

            <!-- Here Here Here Here Here  -->
            <Image Source="i:\\tempa\\tm.png" Width="534" Height="458" />

    </Viewport2DVisual3D>

        <!-- Back -->
        <Viewport2DVisual3D>
            <!-- Give the plane a slight rotation -->
            <Viewport2DVisual3D.Transform>
                <RotateTransform3D >
                    <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D x:Name="backTransform" Angle="180" Axis="0, 1, 0" />
                    </RotateTransform3D.Rotation>
                </RotateTransform3D>
            </Viewport2DVisual3D.Transform>

            <!-- The Geometry, Material, and Visual for the Viewport2DVisual3D -->
            <Viewport2DVisual3D.Geometry>
                <MeshGeometry3D Positions="-1,1,0 -1,-1,0 1,-1,0 1,1,0"
                                TextureCoordinates="0,0 0,1 1,1 1,0" TriangleIndices="0 1 2 0 2 3"/>
            </Viewport2DVisual3D.Geometry>

            <Viewport2DVisual3D.Material>
                <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" Brush="White"/>
            </Viewport2DVisual3D.Material>

            <Button Name="btnBack">Back</Button>
        </Viewport2DVisual3D>

        <ModelVisual3D>
            <ModelVisual3D.Content>
                <DirectionalLight Color="#FFFFFFFF" Direction="0,0,-1"/>
            </ModelVisual3D.Content>
        </ModelVisual3D>

    </Viewport3D>

我正在尝试使用Viewport3D构建一个双面窗口。但后来我在尺寸方面遇到了一些麻烦。

                <!-- Here Here Here Here Here  -->
            <Image Source="i:\\tempa\\tm.png" Width="534" Height="458" />

我希望此图像与其源图像的大小完全相同。

指定值或“auto”都不起作用。

我怎样才能得到我想要的东西?

2 个答案:

答案 0 :(得分:2)

我的3D知识是有限的,有人可以更好地回答这个问题,但在3d环境中,对象的大小取决于很多东西..摄像机位置,近/远平面,大小/位置对象,应用于该对象的变换,视口大小,以及我忘记的其他东西。 3d引擎在渲染内容时会考虑所有内容。设置图像的大小只是它的一部分。

可能会尝试弄乱相机位置或为图像添加比例变换。

答案 1 :(得分:1)

您要找的是the projection matrix of the camera。该矩阵将3D点转换为2D点。因此,通过传递MeshGeometry3D的3D坐标,您可以找到2D坐标和尺寸。

相关问题