🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Perspective

Started by
1 comment, last by alvaro 5 years, 6 months ago

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.

image.png.99236ea9d3e15640b8cf28d7d762ee7a.png

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

6

22.14213562373095

9.65685424949238

4+√8+√32+(4+√32)

5

12.48528137423857

5.65685424949238

4+√8+√32

4

6.82842712474619

2.82842712474619

4+√8

3

4

2

4

2

2

0.585786437626905

2

1

1.414213562373095

0.414213562373095

√2

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

Advertisement

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.

 

This topic is closed to new replies.

Advertisement