如何绘制2D视角,正确的网格 [英] How to draw a Perspective-Correct Grid in 2D

查看:233
本文介绍了如何绘制2D视角,正确的网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,在2D定义当然是一个现实世界的矩形上的图像/照片的顶部,这可能不是一个矩形,因为你看着它从一个角度。

I have an application that defines a real world rectangle on top of an image/photograph, of course in 2D it may not be a rectangle because you are looking at it from an angle.

现在的问题是,说的矩形需要有付款人的网格线,例如,如果它是3x5的,所以我要画两行从1侧到另一边3和4号线从2侧到另一边4。

The problem is, say that the rectangle needs to have grid lines drawn on it, for example if it is 3x5 so I need to draw 2 lines from side 1 to side 3, and 4 lines from side 2 to side 4.

截至目前,我打破了每行成等距部分,让所有的网格线的起点和终点。然而,一个角矩形上的越多,不正确这些行成了,因为水平线远离你应该紧密地结合在一起。

As of right now I am breaking up each line into equidistant parts, to get the start and end point of all the grid lines. However the more of an angle the rectangle is on, the more "incorrect" these lines become, as horizontal lines further from you should be closer together.

有谁知道我应该寻找?算法的名称

Does anyone know the name of the algorithm that I should be searching for?

是的,我知道你可以在三维做到这一点,但我仅限于2D的这个特殊的应用。

推荐答案

这里的解决方案: <一href="http://freespace.virgin.net/hugo.elias/graphics/x_persp.htm">http://freespace.virgin.net/hugo.elias/graphics/x_persp.htm

的基本思想是可以通过的角部对角地连接找到你的矩形的透视正确的中心。这两个结果行的交集就是你的观点正确的中心。从那里,你细分您的矩形成四个更小的矩形,并重复这一过程。的次数取决于您准确的希望。可以细分到像素的正下方的大小为有效完美透视

The basic idea is you can find the perspective correct "center" of your rectangle by connecting the corners diagonally. The intersection of the two resulting lines is your perspective correct center. From there you subdivide your rectangle into four smaller rectangles, and you repeat the process. The number of times depends on how accurate you want it. You can subdivide to just below the size of a pixel for effectively perfect perspective.

然后在您的subrectangles你刚才您的标准未修正的质感三角形或矩形或什么的。

Then in your subrectangles you just apply your standard uncorrected "textured" triangles, or rectangles or whatever.

您可以不用去构建一个真实的3D世界的复杂麻烦执行这个算法。它也是很好的,如果你的执行的有一个真正的3D世界为蓝本,但在硬件上textriangles没有角度纠正,或者您需要一个高性能的方式来获得透视校正飞机没有每个像素渲染挂羊头卖狗肉。

You can perform this algorithm without going to the complex trouble of building a 'real' 3d world. it's also good for if you do have a real 3d world modeled, but your textriangles are not perspective corrected in hardware, or you need a performant way to get perspective correct planes without per pixel rendering trickery.

这篇关于如何绘制2D视角,正确的网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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