URL: https://graphicscomputing.fr/cgp/reference/picking_structure/
Description: Result of a picking (picking_spheres...) with the selected index, the 3D position and the ray.

# picking_structure

Result of a picking (picking_spheres...) with the selected index, the 3D position and the ray.

Fields:

- `bool active` - True if the ray hit an element, false otherwise (the other fields except the ray are then not meaningful).
- `int index` - Index of the picked element in the array given to the picking function, -1 when nothing is picked.
- `vec3 position` - 3D position of the hit point on the picked sphere.
- `vec3 normal` - Normal at the hit point: the sphere normal for picking_spheres, the vertex normal for picking_mesh_vertex_as_sphere.
- `vec3 ray_origin` - Origin of the picking ray, the position of the camera.
- `vec3 ray_direction` - Unit direction of the picking ray, through the clicked point of the screen.
- `vec2 screen_clicked` - Clicked position in relative screen coordinates in [-1,1], as given to the picking function.

Functions returning it:

- `picking_structure picking_spheres(vec2 const& screen_click, numarray<vec3> const& spheres_centers, float spheres_radius, camera_generic_base const& camera, camera_projection_perspective const& projection)` - Cast a ray through a screen position (normalized device coordinates) and return the closest hit among spheres of common radius, with its index, position and normal.
- `picking_structure picking_mesh_vertex_as_sphere(vec2 const& screen_click, numarray<vec3> const& vertex_position, numarray<vec3> const& vertex_normal, float picking_distance, camera_generic_base const& camera, camera_projection_perspective const& projection)` - Casts the camera ray through the screen position and returns the closest vertex whose sphere of radius picking_distance it hits, with the hit point, the vertex normal and the vertex index (active is false if none).
