Archived

This topic is now archived and is closed to further replies.

how big does it look

This topic is 5583 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If I have a sphere of diameter x a distance of d away from the camera which has a fov of f, how many pixels in diameter will it be on the screen? Thanks.

Share this post


Link to post
Share on other sites
It would depend on the tesselation of the sphere, the screen resolution, and probably also on the API used to render it. It might also depend on the accuracy of the hardware (CPU and GPU both).

"The Requested Information Is Unknown Or Classified" -Anonymous

[edited by - Extrarius on August 31, 2002 6:33:54 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Extrarius
It would depend on the tesselation of the sphere, the screen resolution, and probably also on the API used to render it. It might also depend on the accuracy of the hardware (CPU and GPU both).

"The Requested Information Is Unknown Or Classified" -Anonymous

[edited by - Extrarius on August 31, 2002 6:33:54 AM]



I can understand the screen resolution affecting it, but how would the other stuff affect it to any significant degree?

Just in general, is there an equation that can give me an estimate on how large the object will look on the screen? This will help plan my game''s world and lod optimizations. If something is going to be only 3 or 4 pixels on the screen, then I can easily get away with a super low poly model, where as something taking up most of the screen should probably use all of the polys it can get. Thanks for your help.

Share this post


Link to post
Share on other sites
Tesselation shouldn''t matter; it''ll affect the apothem of the projected polygon (which will approximate a circle) but not the radius.

(Note: Apothem = segment from center to midpoint of edge; radius = segment from center to vertex)

I doubt API matters either. AFAIK, transforms are done by the hardware nowadays independent of API.

The hardware does matter (very very slightly) due to differences in internal floating-point representations. Again, though, the change is very small.

Extrarius hairsplitting wasn''t incorrect, just obviously not what you were looking for! I''ll try to help.

First, the simple projection equations you probably already know:

x'' = (x * k) / z
y'' = (y * k) / z

(k is a constant dependant on the view angle)

Imagine a sphere centered in the middle of screen space (With a center in camera space of c= (0, 0, d)), the distance from the camera). The center is projected, obviously, at (0, 0) (Forget about adding half the screen width and all that stuff for now; 0,0 is the center of the screen). A point that will lie on the edge of the projected sphere is at cx + r, cy, cz, or (r, 0, d). Project that on the screen and you get ((r*k)/d, 0), whose distance from (0, 0) is simply (r*k)/d.

Or, to make that long story short, the radius of a sphere projected on the screen is inversely proportional to the distance it is from the camera. Now all we need to do is find the constant of proportionality, k, which as I said before depends on the FOV angle.

Now, to steal two lines of code from my simple raytracer (and to get into the part that I''m not absolutely certain of, but think is probably right):

  
const float FOV = 55.0f; //degrees < 180; 55 is average human FOV

const float FOCAL_LENGTH = (float)(SCREEN_WIDTH/2)/tanf(FOV*DTOR*0.5f); //FOV*DTOR = FOV in radians


FOV is the view angle; FOCAL_LENGTH, IIRC, is your k. If this last part, about finding k turns out to be innacurate, post back, and I''ll do a real post on finding k rather than just copying a bit of my old code!

Share this post


Link to post
Share on other sites
OK, I did some experimenting and found out a few things. First, like you stated, the size of the object is inversely proportional to the distance from the camera. However, it is not a linear relationship, rather it is more hyperbolic.

The experiments went like this: I sat a sphere of radius 100 at the origin and then moved back on one axis until the sphere disappeared (the depth of my frustum was significantly larger than any of the disappearing points, so I hope that didn''t affect the results). I measured the width of the sphere in pixels at various distances.

Obviously, the sphere lasted longer at higher resolutions and lower FOVs.

Here are a few sample results:
FOV: 45 Screen Res: 640x480 Disappearing point: approx 85000
FOV: 45 Screen Res: 1280x1024 Disappearing point: approx 183000
FOV: 55 Screen Res: 1280x1024 Disappearing point: approx 147000
FOV: 95 Screen Res: 640x480 Disappearing point: approx 35000

(This program was written using OpenGL and SDL on Linux and run on a computer w/ AMD Athlon XP and Geforce 2mx, fyi).

So, it seems the apparent size of the object is proportional to the screen resolution and inversely proportional to the FOV.

OK, now help me understand the relationship between the apparent size of the object and the focal length (as computed in your code sample)? Perhaps I have the wrong idea of what the focal point is. Also, what is "DTOR"? Is that the distance from camera to the object?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The comment in his code says DTOR is used to convert degrees to radians so I assume it is a constant equal to pi/180. The reason the size is not linearly related to the distance is the equations

newX = (x * focalLength) / z
which is like the mathematical funtion:
f(x) = C/x where C = width * focalLength

meaning there is a hyperbolic(like you suggested). As to the relationship between focal length and the size of the object, The size should depend on the focal length linearly as can be seen in the equation. In an API like OGL you define the focal length indirectly through the FOV by using the equations TF posted before.

So sphere with diameter x distance d and fov f(in radians) should be
(x * (SCREEN_WIDTH/2)/tanf(f/2)) / d pixels in width.

Share this post


Link to post
Share on other sites