Mapping object coords to window coords

Started by
2 comments, last by Xtreme 23 years, 5 months ago
This is a bit hard to explain. As far as i know, in OGL, the coord system is like this: Y ^ | | | | -----------> X / / / Z What is the "ratio" of object coords to window coords. Example when using glTranslatef(x, y, z) if I replaced it with glTranslatef(1.0, 1.0, 1.0) where is that coord if you were representing them in windows coords?, ie, in pixels?
Yes! There are kangaroos in Australia but I haven't seen them...yet
Advertisement
It all depends on how you set up your projection.

Imagine you set up an orthographic projection with the highs and lows at 0,0 640,480. When you use a window of that size there will be a direct mapping between the world coords and the screen coords.

Correct me if I''m wrong

Paul Groves
pauls opengl page
Paul Grovespauls opengl page
Paul,
I meant using perspective projection not ortho.. but you are on the right track!

Is there a function or something that converts from screen to object coords or vice versa?
So, say I set up perspective proj. with the following:
.....
glViewport(0, 0, SCR_W, SCR_H);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90, (double)SCR_W/SCR_H, 1, 1000);
glMatrixMode(GL_MODELVIEW);
.....
where SCR_W & SCR_H are the screen widths and heights respectively.

Now, if I map a texture say, 512x512 pixels onto this, what is the exact ratio?
Yes! There are kangaroos in Australia but I haven't seen them...yet
You need to look at the gluUnProject and gluProject functions in the man. pages.

Paul
Paul Grovespauls opengl page

This topic is closed to new replies.

Advertisement