Sign in to follow this  
Piranjah

How to get Z-value with mouseclick?

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

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