Picking is a process of selecting objects in the 3D space contained in a scene by user inputs. This is a very common requirement in 3D graphic applications, where you may be interested in an object tapped by an end user. The tapped point contains position in the screen coordinate system, which is a reference to the viewport. This reference point can be used in various picking techniques to detect the tapped object. In the present recipe, we will use a very versatile picking technique called "ray picking" or "ray trace pick".
In this technique, a ray is simulated using the tapped point in the scene. When the ray intersects with an object, it's assumed to be clicked on. The ray can be intersected with multiple objects in a given scene; the selected objects can be collected and sorted according to the distance from the viewpoint in order to become the closest selected object. In this recipe, we will implement the ray trace picking technique,...