Hit testing is performed in the graphics window (GraphicsWindow) using a side-effect mechanism. There is a special rendering mode (see Rendering Modes) that performs hit testing. In this mode (called GW_PICK), the item is not actually drawn, but is instead tested for intersection with the specified hit region. When hit-testing is enabled, primitives set a flag if they pass through or are fully contained in the hit region. When in this mode, the primitives do not cause any visual side-effects -- in particular, they do not change the image or Z buffers If an item needs to be hit tested, a developer must simply draw the item using a rendering level GW_PICK and then check the result.
By clearing the flag before a primitive is rendered, and checking it immediately afterwards, a hit-check for that particular primitive is made. Hit testing on vertices, edges, entire meshes, etc., can be accomplished by rendering only the desired primitives and checking the hit flag at the desired granularity.
When the hit region is a single point, each "hit" primitive also sets a distance variable (representing distance from the hit point to the line in wire-frame mode, and Z distance in filled mode), so that "smart" hit testing -- i.e. choosing the closest primitive to the hit point -- may be implemented.
The following methods are used for hit testing.
Typically you use these methods in the following sequence: