Mouse picking is an often used, intuitive operation to interact with 3D scenes in a variety of 3D graphics applications. CHAI3D provides some basic capabilities to detect if an object has been selected. The mouse selection procedure requires first setting up a collision recorder and the desired collision settings. The following listing illustrate a basic example.
The collision recorder is empty at first and accumulates the selected objects located underneath the mouse pointer. The information returned for each collision event is stored in a cCollisionEvent structure. Such structure will contain a pointer to the object, 3D position information of the mouse click, selected triangle (cMesh), and surface normal.
Collision settings can be setup to filter certain types of data or to speed up the procedure.
In the following listing extracted from example 12-polygon, a mouse click callback is programmed. If a triangle from a mesh object is selected, its vertices a painted in red.