Jump to content
  • Advertisement
Sign in to follow this  
Piranjah

How to get Z-value with mouseclick?

This topic is 4291 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
Advertisement
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
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!