0

Let's say that I have a perspective view in OpenGL and choose a point at a given depth. Let's say that it's at z=-10. How do I know which actual x- and y-coordinates this point have? It is easy when having an orth view because it then is the same for every depth. but for the perspective one: How do I find these x-y-values?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Nicke
  • 133
  • 12

2 Answers2

0

The coordinates you supply are basically "world" coordinates -- i.e., where things exist in the virtual world you build. In other words, the coordinates you work with are always orthogonal.

Just for example, if I was going to do a 3D model of a house, I could set it up so I was working in actual feet, so when I could draw a line from 0,0 to 0,10 to represent something exactly 10 feet long. That would remain 10 feet whether I viewed it up close, so it filled my view, or from a long ways away so it was only a couple of pixels long.

Only when objects are being displayed is perspective transformation done. I don't do it on the coordinates being fed into the system at all.

If you're asking about computing the screen coordinates for an object, yes, you can. The usual way to do this is with gluUnProject. At least in my experience it's relatively unusual that you end up needing to do this though.

The one time you sort of care is when you're selecting something on-screen using the mouse. Though it's possible to do with with gluUnProject, OpenGL has a selection mode that's intended specifically for this kind of purpose, and it works pretty well.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • Thank you for your answer Jerry. The background objective is actually stated here: http://stackoverflow.com/questions/10457834/how-do-i-apply-proper-perspective-to-this-opengl-es-texture/10458680#10458680, and sorry for beeing unclear, it's an iOS application for iPad so the OpenGL version is actually for embedded systems. The problem, is as you say, related to selecting an area with the mouse (by touch) and to figure out which coordinates the vertices actually have. Do you know if the gluUnProject is still applicable for ES? – Nicke May 05 '12 at 06:40
  • @Nicke: It's not built in, but there is at least one independent [re-implementation](http://softwareprodigy.blogspot.com/2009/08/gluunproject-for-iphone-opengl-es.html). – Jerry Coffin May 05 '12 at 06:48
  • Hmm, thinking some more. It still might not really be the thing I asked for. Lets say that the z-value is known for the given point I select on the display. Then the problem should be just an projection function of some sort, am I correct? I mean, suppose that there is not an actual object, say cube, that exist in the world that I touch. – Nicke May 05 '12 at 07:10
0

Look at gluProject as a way of projecting your cursor position into a "world" position (and gluUnproject as a way of finding out where your object is on screen).

ravuya
  • 8,586
  • 4
  • 30
  • 33