# OpenGL Scaling: real-world dimensions to pixels

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

## Recommended Posts

1) I'm an OpenGL n00b (but the question isn't really OpenGL-specific anyway). 2) Assume you have an object, say an F-16 fighter plane, and you know its real-world dimensions. Now you're tasked with rendering this airplane on screen at a distance of 50 meters from the camera. How do you determine the size of the airplane in your 3D world? I suppose screen resolution is one factor, but how do you decide how many pixels in your 3D world should fit in one meter in the real world?

##### Share on other sites
First you determine your camera statistics, such as field of view and aspect ratio. Use an appropriate function to load those statistics as a matrix, such as gluPerspective(). Define the units in meters for things like clip distances. Scale your model so that the model unit scale corresponds to meters. Render the model at a point 50 units away from the camera. Let the GL pipeline figure out all the details like pixel positions. Profit.

##### Share on other sites
The basic formula is that the size of the object is inversely proportional to the distance in front (generally Z is used) of the camera.

If you have a 45 degree view angle either side of straight ahead then a point that is 5m ahead and 5m to the left will be at the very left hand side of the screen (lets call this -1.0 for now but generally screens are mapped 0.0->1.0). 5m to the right would be at +1.0. At the same horizonatal offset and 10m distance in front of the camera these screen space numbers become -0.5 and 0.5.

Easiest to draw this out from a top down view and see how the numbers work.

1. 1
2. 2
3. 3
4. 4
Rutin
11
5. 5

• 12
• 19
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632666
• Total Posts
3007722
• ### Who's Online (See full list)

There are no registered users currently online

×