Sign in to follow this  

How to get Z-value with mouseclick?

This topic is 4075 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 a total newbie :-s I'm setting up my scene and I need to know how to get the z-value of the pixel I'm clicking on:s Is there any way to do this fast? Many thanks, Pascal

Share this post


Link to post
Share on other sites
glReadPixels is damn slow, because of framebuffer readbacks! I tried this with a simple landscape and it takes 10ms!
You should learn ray-picking. Use glunproject with the near and far clipplane and the mouse coordinates to get your picking ray. Then you have to calculate which of your objects the ray intersects. Here is an explanation on doing this (All calculation is done on the CPU with your vertex data):
http://www.cs.princeton.edu/courses/archive/fall00/cs426/lectures/raycast/sld016.htm
You can improve speed with spatial subdivision (Google will help you, it's very simple).

Share this post


Link to post
Share on other sites

This topic is 4075 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.

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