Advertisement

Perspective math

Started by February 05, 2004 09:50 AM
11 comments, last by Tree Penguin 21 years, 1 month ago
Does anyone have a tutorial on perspective calculations? What i need to know is how large a unit is at a distance (like, when it''s 2 times as far away, how much smaller is it). Thanks
http://www.compuphase.com/axometr.htm might help ya.
------------------------"If it says it loves me, how can it be a virus?"
Advertisement
The equations can be derived using congruent triangles, geometry.
height_of_object/distance_from_view = apparent_height
(essentially a conversion of eyespace into screen space)

assume that a 1m high object is 1m away from the viewer. We will take this as the reference.
Move the object an additional 1m away from the viewer.
1m/2m=1/2 the object appears half as small.

Successive doublings of distance will result in halfings of the apparent height.
1m/4m=1/4
1m/8m=1/8
ad infinium.
Thanks, those will help me out, especially aaron_ds''s information (i didn''t know it whas that simple, i was already using squares/square roots to approach it a little more )!
Ok, i now have 2 problems, one related to the first question in this topic, the other is about texturing:

1. I think my perspective is incorrect, might be an optical illusion though. Anyone know why it seems like that (or why it is like that)? I am using my own modelview matrix, but not my own perspective matrix (that's just opengl). Screen shots:






2. When i load objects from a file, sometimes one or more textures aren't loaded. In this case the texture pointer points to the first loaded texture (instead of the textures loaded for the model itself). I have loaded the grass texture first, then the bricks, then the roof. The house model binds texture 0 and 1 (grass and bricks).
I load every texture that's needed for a model once per model. Screenshot:




And here it is the first model loaded so there aren't any textures loaded so far:


The wierd thing: this doesn't always happen!! (actually about one out of ten times)

Thanks in advance.

[edited by - Tree Penguin on February 6, 2004 6:01:25 AM]
quote:
Original post by aaron_ds
The equations can be derived using congruent triangles, geometry.
height_of_object/distance_from_view = apparent_height
(essentially a conversion of eyespace into screen space)

assume that a 1m high object is 1m away from the viewer. We will take this as the reference.
Move the object an additional 1m away from the viewer.
1m/2m=1/2 the object appears half as small.

Successive doublings of distance will result in halfings of the apparent height.
1m/4m=1/4
1m/8m=1/8
ad infinium.


Surely it can''t be that simple? If your perspective has a very wide FOV (almost fish-eye lens), an object 1m away will appear much smaller than the same object in the same position when using a very narrow FOV (a zoom lens). Or did I misunderstand your explanation?
Advertisement
I found out one thing: the view looks much more realistic when you devide the fov value by the aspect ratio, this way the perspective keeps the right porportions.
One problem though, i need to know the direction two opposite corners are in. Anyone knows a simple way to get those values?

Thanks
I don't think it is as simple as halving when distance doubles. It depends on your field of view. Consider the frustum idea, a pyramid with the top cut off. The wider the angle on the pyramid, the greater the change will be for a change distance.
           .                        .          . .                     .   .         .   .                  .       .        ._____.               .___________.       .       .            .               . 


[edited by - variant on February 6, 2004 10:21:15 AM]
The apparent width will half as the distance doubles. If for example an object at distance d is 32 pixels wide then at distance 2 *d it will be 16 pixels wide.
[1] frustrumWidth = 2 * tan (fovx / 2) * d 

at d = d1:
[2] frustrumWidth0 = 2 * tan (fovx / 2) * d1 

at d = d1 * 2:
[3] frustrumWidth1 = 2 * tan (fovx / 2) * d1 * 2[4] frustrumWidth1 = 2 * frustrumWidth0 

If an object takes up 50% of the frustrum width at distance d1 then it will take up:
[5] objectWidth / frustrumWidth0 = 0.5[6] objectWidth / frustrumWidth1 = objectWidth / (frustrumWidth0 * 2)                              = (objectWidth / frustrumWidth0) / 2                              = 0.5 / 2                              = 0.25 

So the object will take up 25% of the frustrum width at distance 2 * d1.

Enigma

EDIT: typos

[edited by - Enigma on February 6, 2004 10:31:36 AM]
quote:
Original post by variant
I don''t think it is as simple as halving when distance doubles. It depends on your field of view. Consider the frustum idea, a pyramid with the top cut off. The wider the angle on the pyramid, the greater the change will be for a change distance.
           .                        .          . .                     .   .         .   .                  .       .        ._____.               .___________.       .       .            .               .  


[edited by - variant on February 6, 2004 10:21:15 AM]


Actualy it is just that. Matrix trnasformations are linear so object at distance 2d will be 1/2 of size of object at distance d. What the actual size in pixels is for distance d, thats another story and this is dependand on FOV. But the relative sizes are not.
You should never let your fears become the boundaries of your dreams.

This topic is closed to new replies.

Advertisement