相关疑难解决方法(0)

将3D点投影到2D屏幕坐标

根据3D Programming for Windows(Charles Petzold)第7章中的信息,我试图编写一个辅助函数,将Point3D投影到包含相应屏幕坐标(x,y)的标准2D点:

public Point Point3DToScreen2D(Point3D point3D,Viewport3D viewPort )
{
    double screenX = 0d, screenY = 0d;

    // Camera is defined in XAML as:
    //        <Viewport3D.Camera>
    //             <PerspectiveCamera Position="0,0,800" LookDirection="0,0,-1" />
    //        </Viewport3D.Camera>

    PerspectiveCamera cam = viewPort.Camera as PerspectiveCamera;

    // Translate input point using camera position
    double inputX = point3D.X - cam.Position.X;
    double inputY = point3D.Y - cam.Position.Y;
    double inputZ = point3D.Z - cam.Position.Z;

    double aspectRatio = viewPort.ActualWidth / viewPort.ActualHeight;

    // Apply projection to X and …
Run Code Online (Sandbox Code Playgroud)

c# math 3d wpf

7
推荐指数
1
解决办法
3万
查看次数

标签 统计

3d ×1

c# ×1

math ×1

wpf ×1