How to draw a Perspective-Correct Grid in 2D

后端 未结 9 1210
滥情空心
滥情空心 2020-12-25 08:43

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 angl

9条回答
  •  长发绾君心
    2020-12-25 09:29

    Here's the solution.

    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.

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

    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.

提交回复
热议问题