Game Development Reference

In-Depth Information

Figure 27.1 shows that the teapot was projected to the area surrounding
W
on the

projection window, corresponding to screen point
S
. With that said, we can compute

a picking ray that will project from the origin and pass through
W
. Intersection tests

can then be performed against all objects in the scene to determine which objects

were picked by the user. It is possible that the intersection tests performed on the

scene objects will return no hits. This simply means that the user did not click on

any objects.

Note

The point
W
on the projection window corresponds to the clicked screen point
S
.

We must first transform the clicked screen point
S
to point
W
on the projection

window. This is done by working backwards from the equations that transform

projection window points to screen points. The viewport transformation matrix

used in the equations is shown here:

Working backwards, transforming a world space point
W
(X, Y, Z) by the viewport

transformation matrix, yields the screen space point
S
(X, Y). Following are the

two equations to solve for
S
. The 2D image displayed by your graphics card after

rasterization does not contain any depth information (Z).

These two equations are great when converting from world space to screen space,

but they will serve no purpose unless we can get them into a more useful state.

Solving for variable
W
, we get the following new equations.