我需要一个
Viewport3D
Petzold.Media3D.ViewportInfo
Window
或者以其他方式渲染它。
我试图通过实例化
并使用以下C#方法设置一些属性:
private Viewport3D CreateViewport(MainSettings settings)
{
var cameraPosition = new Point3D(0, 0, settings.CameraHeight);
var cameraLookDirection = new Vector3D(0, 0, -1);
var cameraUpDirection = new Vector3D(0, 1, 0);
var camera = new PerspectiveCamera
{
Position = cameraPosition,
LookDirection = cameraLookDirection,
UpDirection = cameraUpDirection
};
var viewport = new Viewport3D
{
Camera = camera,
Width = settings.ViewportWidth,
Height = settings.ViewportHeight
};
return viewport;
}
稍后,我将尝试使用此视口使用以下方法将鼠标位置转换为三维位置:
public Point3D? Point2dToPoint3d(Point point)
{
var range = new LineRange();
var isValid = ViewportInfo.Point2DtoPoint3D(_viewport, point, out range);
if (isValid)
return range.PointFromZ(0);
else
return null;
}
不幸的是,它不起作用。我想原因是
ActualWidth
ActualHeight
视口的属性都是零(并且这些属性是只读的,所以我不能手动设置它们)(注意:我用一个实际的渲染器测试了完全相同的方法
视口3D
你知道我怎样才能让WPF分配
和
实际高度
基于
Width
和
Height
设置?
我试着设置
HorizontalAlignment
和
VerticalAlignment
到
Left
Top
MinWidth
MinHeight
,但这些属性对
实际宽度
实际高度
.