Sign in to follow this  
ProfEich

Mouse position on heightmap

Recommended Posts

Hi! Is there a faster way than using the glPushName/glPopName solution to find out the x,y position on the heightmap using the mouse pointers position? Maybe by calculating the position depending on the depth buffer using glReadPixels? An example would be also nice, because I'm not so good with calculating all those 3D things. Thanks for every help :)

Share this post


Link to post
Share on other sites
Should do some raypicking.
Get the Picking Ray with using glunproject for the near and farclipplane and with your mouse coordinates. Now you must test which triangle intersects with the picking ray. You will find some good slides which show how to do:
http://www.cs.princeton.edu/courses/archive/fall00/cs426/lectures/raycast/sld016.htm
Maybe you will get a some more than only one triangle. You must take that triangle which is closest to the viewpoint.
For improving this technique and not testing all of you triangles do something like spatial subdivision (fire up google...).
This sound very complicated but indeed it is quite easy and with the spatial subdivsion technique it's faster than all glReadPixels or whatever.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this