I am trying to perform picking in O开发者_如何学编程penGL, and have 3 questions in 1.
I use twice the Unproject command, once with 0 and once with 1 as near/end planes. Some article say that 0 and 1 are ok, some others say that I should use a calculated depth. Which one should I take ?
Then, assuming I could substract both results, that gives me a ray (the ray is going from my "camera" to the direction indicated as x,y,z, right ? x,y,z are absolute values or relative to my "camera" ?
Now that I have the ray, how can I intersect it with shapes ? By the way, how can I list existing shapes and calculate their coordinates vs the ray ?
2 - Your ray will be relative to the camera, just multiply it by the inverse camera transform.
3 - For just about all purposes, you need a spatial subdivision algorithm (Binary Space Partition, Bounding Volume Hierarchy, etc.) And you should maintain a list of the shapes you have created...
精彩评论