How to get Z-value with mouseclick?
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
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).
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement