Jump to content
  • Advertisement
Sign in to follow this  
Piranjah

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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

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!