Jump to content
  • Advertisement
Sign in to follow this  
Beatcow

OpenGL OpenGL FOV & Units

This topic is 3336 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

Aloha! I've always dealt with openGL in a way that just seemed to look right. Every object seemed realistically proportional with a 60 to 90 degree Field of View. All was great until recently... I'm currently working on something that requires everything to look as realistic as possible (size-wise). That being said, I wish to make OpenGL units in centimeters so that if I specify a line to be 1.0 openGL unit, then it will actually be 1 cm on screen(and will be able to be verified with an actual ruler). Let's initially assume I'm using orthographic projection. That being said, 1.0 ogl unit would correspond to 1 pixel. For me to get 1 cm, would I be required to do a "glScale3f" before rendering that would make the 1.0 ogl unit into 1 cm? I calculated that there are approximately 34 pixels in 1 cm on my screen (1280x1024). Now let's assume perspective projection. This is where I find things most confusing. How would I set up the same type of situation? Let's say I sit 60 centimeters away from my screen. For me to see a centimeter on screen as I would in real life, would I have to position the openGL camera 60 units away? For Field of View calculation, would I just use the angle from the center of my eyes to the sides of my screen? Hopefully someone can shed some light on this. I tried looking in books and on the internet, but to no avail. Perspective projection really gets my mind in knots. db

Share this post


Link to post
Share on other sites
Advertisement
For an orthographic projection, just set the values to whatever dimension you want. If you want 1 unit to be 1 cm, and your window is 34 cm wide, then the view volume must be 34 units wide.

For perspective, you need to calculate a proper field of view. If you consider your world around you as the scene, and your monitor as a viewport into the scene, you can figure out the FOV as the angle between your eyes and the borders of the window. So, the horizontal FOV shall match the angle between the left edge, your face, and the right edge of the window. Typically, this is around 40 degrees. You can calculate the FOV as atan(w*d/2)*2, where w is the width of the window and d is the distance from the monitor to your face.

Share this post


Link to post
Share on other sites
Quote:
Original post by Brother Bob
You can calculate the FOV as atan(w*d/2)*2, where w is the width of the window and d is the distance from the monitor to your face.

Shouldn't that be atan((w/2)/d)*2?

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
Shouldn't that be atan((w/2)/d)*2?


Yes, that's correct.

Quote:
Original post by Brother Bob
If you want 1 unit to be 1 cm, and your window is 34 cm wide, then the view volume must be 34 units wide.


When you say "make the viewing volume 34 units", how do you propose doing this?

Share this post


Link to post
Share on other sites
Quote:
Original post by Beatcow
Quote:
Original post by Sneftel
Shouldn't that be atan((w/2)/d)*2?


Yes, that's correct.

Indeed it should. Typo on my part.
Quote:
Original post by Beatcow
Quote:
Original post by Brother Bob
If you want 1 unit to be 1 cm, and your window is 34 cm wide, then the view volume must be 34 units wide.


When you say "make the viewing volume 34 units", how do you propose doing this?

For example, if the screen is 34x20 cm (a 16:9 monitor), glOrtho(0, 34, 0, 20, -1, 1) will give you cm-based units.

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!