I need Viewport3Dfor the sole purpose of performing geometric calculations using Petzold.Media3D.ViewportInfo. I would prefer not to post it in Windowor otherwise render it.
I am trying to accomplish this by instantiating Viewport3Dand setting multiple properties using the following C # method:
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;
}
Later, I try to use this viewport to convert the location of the mouse to a three-dimensional location using this method:
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 ( , ). (. Viewport3D, , , .)
, WPF ActualWidth ActualHeight Width Height?
HorizontalAlignment VerticalAlignment Left Top , MinWidth MinHeight, ActualWidth ActualHeight.