Jump to content
  • Advertisement
Sign in to follow this  
jbworld

OpenGL Semi-ortographic projection

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

Hello, I am currently working on a project (mostly for my personal amusement), using a variety of languages, tools, and concepts - including OpenGL. To be specific, I use OpenGL to set up a window manager for my application, and it works pretty well, using gluOrtho2D to set up the projection: gluOrtho2D(0, Width, Height, 0); (this also inverts the coordinate system, but that is desirable) However, I want to add some neat effects, and I would need perspective projection for that. So the question is: how can I set up a perspective projection where for a certain Z coordinate, other coordinates are screen coordinates (pixels)? (Or in other words: a perspective projection where if I draw with a certain Z coordinate, I get the same results I would get for the projection created by the statement above?) Thanks, JB

Share this post


Link to post
Share on other sites
Advertisement
im not sure i understand your question, but if all your wanting is to have the same Z coordinate for all pixels, why would you want to use perspective projection. The call to gluOrtho2D does exactly what you said you needed.

if you wanted to specify a perspective projection you can call the function
glPerspective(GLfloat fovy, GLfloat ratio, GLfloat near, GLfloat far);

fovy is the angle of the field of view you desire. I like to relate fov to how a camera "zooms" in and out. Your not actually zooming so much as you are changing the angle of the fov. When you increase fov, objects will appear smaller/farther away, while if you decrease fov, objects seem bigger/closer.

ratio is the aspect ratio of the window your drawing on. this is typically your window width / window height.

the last two params, your specifying how far you would be able to see. near is typically 0.1f, and far depends upon your application

hope this helps

Share this post


Link to post
Share on other sites
Thanks, maybe I wasn't quite clear. I do want to draw with other Z index values, it is just that I want to have a specific Z index which works like orthographic projection. Switching between the too (perspective and orthographic) won't work either, as only some parts of objects will be at the given Z index. Also, I know how to set up projections (ortho, frustum, etc), I just don't know how to set up a projection like this.

Share this post


Link to post
Share on other sites
If you use glFrustum with the left, right, top, bottom, zNear, and zFar parameters, and furthur use the typical symmetric set-up
left == -right
top == -bottom
and consider that
width := right-left at zNear
height := top-bottom at zNear
then the intercept theorem tells that
w(z) := width * z / zNear
h(z) := height * z / zNear
are the width and height at a distance z.

The values of w(z), h(z) are prescribed by the orthographic projection in the given use case. Say they are named w' and h', resp. Hence:
z = w' / width * zNear == h' / height * zNear
The identity on the right requires that the aspect ratio of both projections is the same.

One can use the original formulas also to compute the frustum parameters if a specific depth should be matched for a given width and height, of course.

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!