# OpenGL pixel versus world cordinates

This topic is 4355 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I'm pretty new at OpenGL and I'm trying to do something what I thought was pretty simple:-s What I want to do is the following: - The user has a top-down vision of a map - The user can grab the map (mousepressed) and drag te map in order to move it. Now, when I grab the map at a certain landmark, and I drag my cursor 10 pixels to the left I want the map in OpenGL to move exactly the same amount (so the landmark should still be beneath my cursor). Problem is, 5 screenpixels don't seem to be 5 opengl coördinates:-s I allready found the gluUnprojectfunction, but I really don't know how to use it in order to move my camera around:-s Can anyone help me with this? Many thanks in advance, Pascal

##### Share on other sites
Hi Pascal,

You need to explain this a bit more before I can help. The first question (and the most important) is are you viewing you map in 3D or 2D i.e. how are you setting up you projection using glOrtho or gluPerspective.

Basically, if you are using an ortho perspective, the task is trivial i.e. multiplying the x / y values by a zoom value, if not, then you need to intesect the plane on which the map resides with a pick ray.

In simple terms, using gluUnproject twice (once for the near plane, once for the far plane) to create two vector, subtract and normalise to get your ray, then simply intersect a plane using this ray (do this once for the pevious mouse coordinates and once for the current) then simply translate by the differnce between the two vectors produced. This will allow you to drag your map easily.

I can help but you'll need to answer those questions first.

Chris

##### Share on other sites
Hi,

My problem is solved. I did use the glunproject correctly and I was doing a camera using sperical coördinates. My mistake was in the miscalculations of the upvector (when using glulookat). Many thanks for the help.

Pascal

1. 1
2. 2
3. 3
Rutin
18
4. 4
5. 5
JoeJ
13

• 14
• 10
• 23
• 9
• 49
• ### Forum Statistics

• Total Topics
632639
• Total Posts
3007588
• ### Who's Online (See full list)

There are no registered users currently online

×