Mouse position on heightmap


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 :slight_smile:

Selection will only return hits at the granularity of the objects themselves, so it’s not very useful or efficient in this particular context.

A reading of the depth buffer followed by a reverse projection (gluUnProject) makes quite a bit more sense in this scenario, that is if pinpoint accuracy is not a requirement (you’re really at the mercy of zbuffer precision here).

Line tracing is also a good possibility, probably the best. A bit more difficult to implement robustly, but more accurate and potentially more efficient, depending on the algorithm.