Jump to content
  • Advertisement
Sign in to follow this  
Red Ant

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.

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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!