Search code examples
3dmapping2dperspectivevertices

3D Vertices To 2D Image Conversion


All I would like to do is create a viewport which maps a 3D terrain of flat squares to a 2D perspective.

Imagine looking out across a field which was perfectly flat. The further away blocks of terrain would appear slanted inwards further towards the horizon, and would also look shorter.

I have done a TON of research on how to scientifically do this correctly and came across this:

http://en.wikipedia.org/wiki/Visual_angle

(except this article is in 2D. I would want it to also account for the "height" or z dimention of the viewport)

Is there a simpler way to do this and create true perception rather than having to program:

-3D ray/sphere intersection

-distance from point to point on a sphere

Pretty much what I'm asking is if there exists a simpler way to map vertices in a 3D world to a 2D plane while staying true to perspective warping?

Any helpful articles or advice would be greatly appreciated!

Thanks!


Solution

  • The standard way to do this is to use homogeneous coordinates and a perspective projection matrix. This doesn't require any distance computations at all: per vertex, it requires a 4x4 matrix multiplication and a division to scale the final 2D point.

    And, yes, it is scientifically and geometrically correct, although I should note that it assumes a flat, camera-like projection screen and an ideal, pinhole-like lens. If you want a "visual angle"-based fisheye view the best option may be to add barrel distortion as a post-process....

    You should probably start with an introductory computer graphics text, like 3D Computer Graphics by Alan Watt. An older, "classic" work is Computer Graphics: Principles and Practice by Foley, van Dam, et al.