WPF 3D - Detirmine是否ModelVisual3D被修剪它里面的Viewport3D [英] WPF 3D - Detirmine whether a ModelVisual3D is being clipped inside it's Viewport3D

查看:220
本文介绍了WPF 3D - Detirmine是否ModelVisual3D被修剪它里面的Viewport3D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Viewport3D 里面的一个立方体的渲染,我需要知道的方式,找出是否所有的立方体是对用户可见。

I have a cube rendering inside a Viewport3D and i need to know a way to find out whether ALL of the cube is visible to the user.

编辑:只是要清楚,..我不是在谈论剪辑,因为近/远平面的距离在这里。我的意思是立方体是高或宽,以适应视摄像头领域。

任何帮助将是大量AP preciated!

Any help would be massively appreciated!

在此先感谢。

推荐答案

我不能提供一个解决方案,但我可以,也许,你指明正确的方向。

I can't offer a solution but I can, perhaps, point you in the right direction.

您需要什么弄个是在视图平面立方体的2D投影的程度。然后,您可以做的最小和最大X'放一个简单的检查; Y值看整个魔方是否可见。

What you need to get hold of is the extent of the 2D projection of the cube on the view plane. You can then do a simple check on the min and max X & Y values to see whether the whole of the cube is visible.

添加一个宽容的因素在某种程度上将采取任何舍入误差的照顾。

Adding a tolerance factor to the extent will take care of any rounding errors.

编辑:我刚刚做了谷歌搜索2D投影WPF这链接上来。它看起来像它解决了你想要的。

I have just done a Google search for "2D projection WPF" and this link came up. It looks like it addresses what you want.

进一步编辑:我从这里上面的链接复制的code中的相关章节

FURTHER I've copied the relevant section of code from the above link here.

public static Rect Get2DBoundingBox(ModelVisual3D mv3d)
{
    bool bOK;

    Matrix3D m = MathUtils.TryWorldToViewportTransform(vpv, out bOK);

    bool bFirst = true;    
    Rect r = new Rect();

    if (mv3d.Content is GeometryModel3D)
    {
        GeometryModel3D gm3d = (GeometryModel3D) mv3d.Content;

        if (gm3d.Geometry is MeshGeometry3D)
        {
            MeshGeometry3D mg3d = (MeshGeometry3D)gm3d.Geometry;

            foreach (Point3D p3d in mg3d.Positions)
            {
                Point3D pb = m.Transform(p3d);
                Point p2d = new Point(pb.X, pb.Y);
                if (bFirst)
                {
                    r = new Rect(p2d, new Size(1, 1));
                    bFirst = false;
                }
                else
                {
                    r.Union(p2d);
                }
            }
        }
    }

    return r;
}

这篇关于WPF 3D - Detirmine是否ModelVisual3D被修剪它里面的Viewport3D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆