gpt4 book ai didi

c# - 如何在代码中动态计算 WPF 所有相机设置?

转载 作者:太空狗 更新时间:2023-10-29 17:53:18 28 4
gpt4 key购买 nike

我在窗口中有 Viewport3D。当窗口大小改变时,它会改变大小。

<Window>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition/>
<Grid.RowDefinitions>
<Label Grid.Row="0" Content="top label"/>
<Viewport3D Grid.Row="1" x:Name="vp3D" >
<Viewport3D.Camera >
<PerspectiveCamera x:Name="pCamera" LookDirection="0 0 -1" UpDirection="0 1 0" />
</Viewport3D.Camera>
<Viewport2DVisual3D x:Name="v2dv3d">
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D x:Name="mg3d" 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>

<Image Height="{Binding ElementName=vp3D, Path=ActualHeight}" Width="{Binding ElementName=vp3D, Path=ActualWidth}" Stretch="Fill"/>

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

现在 我希望图像像原始 2d 窗口一样显示(看起来没有任何变化,但实际上图像是 3d)。

但问题是如果我希望它看起来与 WPF 原始外观相同,我必须更改一些相机设置,例如 PerspectiveCamera.PositionMeshGeometry3D.Position .因为 Viewport3D 会在窗口改变大小时动态改变大小,我必须动态计算 Viewport3D 设置。有什么办法吗?

我已经试过了,但无法正确计算: WPF 3D: Fitting entire image to view with PerspectiveCamera

最佳答案

我不确定这是否是您想要的,但您尝试过吗?

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="top label"/>
<Image HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="1" Stretch="Fill"/>
<Viewport3D Grid.Row="1" x:Name="vp3D">
<Viewport3D.Camera >
<PerspectiveCamera x:Name="pCamera" Position="0,0,1" LookDirection="0,0,-1" />
</Viewport3D.Camera>
<Viewport2DVisual3D x:Name="v2dv3d">
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D x:Name="mg3d" 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>
</Viewport2DVisual3D>
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight Color="#FFFFFFFF" Direction="0,0,-1"/>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
</Grid>

关于c# - 如何在代码中动态计算 WPF 所有相机设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38221053/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com