# quad coordinate to image coordinate?

Hi everyone,

I texture mapped an image to a quad. I just want to display this image quickly as an image viewer. I used texture mapping to take advantage of fast panning/zooming/interpolation.

When my mouse is moving over the image view, I would like to know what pixel that corresponds to of my original image.

I made my quad be of size 256x256. And my image is 256x256 pixels. So there is a 1:1 relationship. I was thinking if maybe I could shoot a ray into my quad, and if it intersects the quad at location x:34.3 y:120.16, I could safely say that I am moving the mouse then over 34,120 in my original image.

Is this the way to do it? I am new to this, so if there is an obvious solution, don’t hesitate to give me a heads up, thanks!

That’s one way to do it that sounds quite reasonable.

If it’s not 3D and aligned to the screen the solution could be even simpler with a pure 2D mouse -> texture coord interpolation via the viewport numbers and vertex values used.

Hi dorbie,

Thanks for your reply. I’m a little confused with how my viewer setup can be labeled (to see if it fits your easier solution). I just texture map the quad and stick the camera looking at the quad’s z direction. The user can’t rotate around the quad in space, just zoom in on it and pan it, so it appears like a 2D image, yet it really is in 3D space.

So in my case, I know the viewport coordinate the user clicked on. Can you give me some more info on how I can take that viewport coordinate, and shoot a ray from it directly down the z-direction and see where (if it all) it hits my quad?

I don’t think I can use your easier solution because due to the zooming/panning, there may not be a direct relationship between the clicked viewport coordinate and image coordinate (if that’s what you meant).

Thanks dorbie,
Mark

But surely you use an ortho projection?

Then it should be pretty much a matter of:

1. reversing Y coordinate - because OGL Y axis is opposite to mouse Y axis
2. subtract pan offset
3. divide by zoom factor

(Or maybe reverse steps 2 and 3, depending on whether you do the pan before or after zoom)

Basically, it’s taking the reverse of the operations you would use to display the picture, even though you’re using OGL for that.

Hi T101,

I tried using an ortho projection (makes most sense of course) but I couldn’t get any zooming capability - everytime I tried moving the camera down the z axis, the image would not change size - is there some way to get around this using ortho projection? I’m sure the z axis was changing. If I could get into ortho view, this would be a lot easier,

Thanks!

Simple: just use glScale before rendering the quad.

Hi T101,

I’ll try it out,

Thanks so much,
Mark