Game Development Reference
In-Depth Information
Figure 15.2:
A ray shooting
through p will
intersect the object
whose projection
surrounds p . Note
that the point p on
the projection win-
dow corresponds to
the clicked screen
point s .
In Figure 15.2 we see that if we shoot a picking ray , originating at the
origin, through p , we will intersect the object whose projection sur-
rounds p , namely the teapot. Therefore, once we compute the picking
ray, we can iterate through each object in the scene and test if the ray
intersects it. The object that the ray intersects is the object that was
picked by the user, which again is the teapot in this example.
The above example is specific to s and the teapot. Generally, we
have an arbitrary clicked screen point. We then compute the picking ray
and iterate through each object in the scene, testing if the ray inter-
sects it. The object that the ray intersects is the object that was picked
by the user. However, it is possible that the ray would not intersect any
objects. For instance, in Figure 15.1, if the user doesn't pick one of the
five objects but clicks the white background, the picking ray would not
intersect any of the objects. Thus, we conclude that if the ray doesn't
intersect any of the objects in the scene, then we, the user, didn't pick
an object, but rather the background of the screen or something we are
not interested in.
Picking is applicable to all sorts of games and 3D applications. For
example, players often interact with various objects in the world by
clicking on them with the mouse. The player may click on an enemy to
fire a projectile at the enemy or click on an item to pick up. In order for
the game to respond appropriately, it needs to know the object that was
picked (was it an enemy or item?) and its location in 3D space (where
should the projectile be fired or where should the player move to pick
up the item?). Picking allows us to answer these questions.
Search WWH ::




Custom Search