Jump to content
  • Advertisement


Recommended Posts

Hello there Gamedev.net

This is about rendering a realistic perspective viewport. I know that matrices and trigonometry are used, from my days doing maths at school, but i’ve never seen the code for DirectX or OpenGL. I have some ideas about how software engineers might do it but I need more information.

First thing I should mention is this geometry, where a square bounds and circle, then a bigger circle bounds that square, and you keep repeating it as shown in the diagram below. If you draw diagonal lines, from the centre, to the corners of the geometry, it looks like you could walk through it, like a realistic corridor. I’m calling each square/circle pair a unit of depth (in to, out of) the scene. If you add a bigger square/circle to the outside, this pushes the far clipping plane further away from the virtual camera.


How is this idea useful for building a code based engine for allowing transformations (move, rotate, scale) to occur? I think if you consider the length from the origin, up to the point at which the next square intersects the circle, and store this value, to build a series, you could use the expression to apply transformations in an efficient way.

I have started working on a table that builds the expression from the bottom up, here is what I have so far.

n (units of depth out of the scene)

y (square/circle intersection)

√ (2*(circle minus square)2)

expression for y

























I do it from the bottom up, because the geometry starts in the centre and works outwards. I start with a square who’s length from the origin to the edge is 1, and to calculate the length from the origin to the corner, from pythagorean trig, is √(2*(12)), namely, (two times 1 squared, square rooted), or √2. Then, by subtracting 1 from root 2 (to give you the difference between the square/circle pair), and using the same function, to calculate the length from the corner, to the next corner (outwards), you can add this value onto the value from the previous iteration, to give a new value for the next term in the expression.

Building the expressions up in this way, and having an expression for y, should hopefully help us to figure out an expression for the entire series. I am thinking that this has already been done, by the guys at Microsoft and Silicon Graphics (DirectX, OpenGL), but I need more information because this seems like the most interesting part of computer graphics.

So I guess my question is, can you point me to further resources, or help me find more information about this technique. I was hoping there would be a wikipedia page showing how the technique works, it’s just that I don’t know what it’s called. It seems quadratic to me, but I would love to read about it, and see the code.

I tried to get in touch with Jim Van Verth too, but he hasn’t replied to me yet. Jim worked for Nvidia so he might know exactly how they do it.

Best regards.

Steven Wiseman

Share this post

Link to post
Share on other sites

That squares-in-circles-in-squares diagram might give you the qualitative feeling of things getting smaller as you move to the middle of the image, which is a feature of perspective. However, it's not correct in the details. The size of things changes exponentially in that diagram, but things only get hyperbolically smaller in correct perspective.

Imagine a 3D space of points with coordinates (x,y,z), with your eye at the origin. The plane of the screen in front of you consists of all the points where z=1. If you have an arbitrary point in front of you (i.e., (x,y,z) with z>0), you can consider the ray that starts at your eye and passes through that point. That ray will intersect the screen plane at (x/z,y/z,1). So just draw the point at (x/z,y/z) on the screen. That's nearly all there is to perspective.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!