我该如何有条不紊地选择近剪裁平面距离的透视投影? [英] How do I methodically choose the near clip plane distance for a perspective projection?

查看:285
本文介绍了我该如何有条不紊地选择近剪裁平面距离的透视投影?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个3D场景,并使用 gluPerspective 相机定义。我有固定视场,我知道任何几何到相机的最小距离(它是第一人称视角,所以这是从视点到人物的碰撞体积的最小距离)。

I have a 3D scene and a camera defined using gluPerspective. I have a fixed FOV, and I know the minimum distance of any geometry to the camera (it is a first-person view, so that is the minimum distance from the viewpoint to the character's collision volume).

如何选择最远的近剪裁平面(最佳深度缓冲分辨率),这将不会造成任何剪切,无论怎样的球员动作和外观?

How can I choose the farthest near clip plane (for the best depth buffer resolution) which will will not cause any clipping, no matter how the player moves and looks?

这些距离不是简单的等于,因为近平面的的距离比原产地的中心更远。

These distances are not simply equal because the corners of the near plane are farther from the origin than the center.

推荐答案

公式:

nearPlane = nearestApproachToPlayer /开方(1 +棕褐色(FOV / 2) 2 ·(的aspectRatio 2 + 1)))

nearPlane = nearestApproachToPlayer / sqrt(1 + tan(fov/2)2 · (aspectRatio2 + 1)))

JavaScript的code:

  var nearPlane = nearestApproachToPlayer 
                  / Math.sqrt(1 + Math.pow(Math.tan(fov/180*Math.PI/2), 2)
                                  * (Math.pow(aspectRatio, 2) + 1));

的推导:

几何,考虑的金字塔的,其基础是近剪裁平面和小费为原点。让的 nearPlane 的是金字塔的高度,和的瓦特的和的ħ的金字塔的基部的宽度和高度。

Geometrically, consider the pyramid whose base is the near clip plane and tip is the origin. Let nearPlane be the height of the pyramid, and w and h the width and height of the pyramid's base.

是W = 的aspectRatio·H

的视场角确定金字塔的高度轴边的斜率:

The FOV determines the slope of the height-axis sides of the pyramid:

斜率的=棕褐色( FOV 的/ 2)
  
   H / nearPlane = 2棕褐色( FOV 的/ 2)
  
   ^ h 的/ 2 =的 nearPlane 的棕褐色( FOV 的/ 2)

slope = tan(fov/2)

h/nearPlane = 2 tan(fov/2)

h/2 = nearPlane tan(fov/2)

近剪辑平面的任何角点从剪辑平面的由中心被偏移(的瓦特的/ 2,的ħ的/ 2),因此,距离是开方((是W 的/ 2) 2 +( ^ h 的/ 2) 2 )。从原点这个角落点的的所述的距离是由 nearPlane 的和前距离形成直角三角形的斜边,因此是的sqrt((的瓦特 / 2) 2 +( ^ h 的/ 2) 2 + nearPlane 2 )。

Any corner point of the near clip plane is offset from the center of the clip plane by (w/2, h/2), so the distance is sqrt((w/2)2 + (h/2)2). The distance from the origin of this corner point is the hypotenuse of the right triangle formed by nearPlane and the former distance, so is sqrt((w/2)2 + (h/2)2 + nearPlane2).

我们希望该距离角落点为等于任何几何图形的最接近

We want that distance to the corner point to be equal to the closest approach of any geometry.

nearestApproachToPlayer 的=开方((是W 的/ 2) 2 +( ^ h 的/ 2) 2 + nearPlane 2

nearestApproachToPlayer = sqrt((w/2)2 + (h/2)2 + nearPlane2)

运用简单的代数产生上面给出的公式。

Applying straightforward algebra produces the formula given above.

我没有检查我的代数,但是我已经测试经验公式:如果我乘nearPlane 1.1,那么它产生的剪切面这仅仅是一个有点过头,对各种纵横比。我还没有尝试过不同的视场超过60°。

I have not checked my algebra, but I have empirically tested the formula: if I multiply nearPlane by 1.1, then it produces a clip plane which is just a bit too far, for various aspect ratios. I have not tried different FOVs than 60°.

这篇关于我该如何有条不紊地选择近剪裁平面距离的透视投影?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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