我有一个带有视口对象和简单方形模型的基本应用程序。我试图用它的 Postion 和 LookDirection 来理解 PerspectiveCamera。阅读此答案后,我认为我了解相机的工作方式。我可以将相机放在模型前面并从不同的角度查看它。
只要我有一个正 Z,这一切都是正确的,但是当我试图查看模型的背面时,使用负 Z 和正 Z 方向,模型是不可见的。而且我似乎无法找出我做错了什么。
我想我应该看到模型的背面,给出 Z:-4 和 LookDir Z:4,但视口没有显示任何内容。
任何人都可以看到,我在这里缺少什么,是照明问题(如果是,我该怎么办),还是有其他问题?
这是我的视口对象:
<Viewport3D ClipToBounds="True" Canvas.Left="0" Canvas.Top="10" x:Name="viewport" Grid.RowSpan="2" Grid.ColumnSpan="2" >
<!-- Defines the camera used to view the 3D object. -->
<Viewport3D.Camera>
<PerspectiveCamera Position="{Binding CameraPosition}" LookDirection="{Binding CameraLookDirection}" FieldOfView="60" />
</Viewport3D.Camera>
<!-- The ModelVisual3D children contain the 3D models -->
<Viewport3D.Children>
<!-- This ModelVisual3D defines the light cast in the scene. Without light, the 3D
object cannot be seen. Also, the direction of the lights affect shadowing. If desired,
you can create multiple lights with different colors that shine from different directions. -->
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight Color="#FFFFFF" Direction="-0.612372,-0.5,-0.612372" />
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D>
<ModelVisual3D.Content>
<GeometryModel3D>
<!-- The geometry specifies the shape of the 3D plane. In this sample, a flat sheet is created. -->
<GeometryModel3D.Geometry>
<MeshGeometry3D
TriangleIndices="0,1,2 3,4,5 "
Normals="0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 "
TextureCoordinates="0,0 1,0 1,1 1,1 0,1 0,0 "
Positions="-1,-1,0 1,-1,0 1,1,0
1,1,0 -1,1,0 -1,-1,0 " />
</GeometryModel3D.Geometry>
<!-- The material specifies the material applied to the 3D object. In this sample a linear gradient
covers the surface of the 3D object.-->
<GeometryModel3D.Material>
<MaterialGroup>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<LinearGradientBrush.GradientStops>
<GradientStop Color="Yellow" Offset="0" />
<GradientStop Color="Red" Offset="0.25" />
<GradientStop Color="Blue" Offset="0.75" />
<GradientStop Color="LimeGreen" Offset="1" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</MaterialGroup>
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D.Children>