Question

I am trying to perform picking in OpenGL, and have 3 questions in 1.

  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 ?

  2. 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" ?

  3. 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 ?

Was it helpful?

Solution

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top