Game Development Reference
In-Depth Information
far.Unproject(device.Viewport,
device.Transform.Projection,
device.Transform.View,
world);
far.Subtract(near);
return entity.Mesh.Intersect(near, far);
}
Conclusion
This chapter covered the math and implementation details behind converting screen
space coordinates into world space, and performing intersection tests to determine
objects that have been picked in a scene.
Remember the following steps:
Given the screen point S , find its corresponding point ( W ) on the projection
window.
Compute the picking ray shooting from the origin through point W .
Transform the picking ray into the same space as each object.
Perform intersection tests to determine the objects picked by the user.
The Companion Web site has the full source code for the example that is frag-
mented throughout this chapter. The example displays several teapots; the user
can click on a teapot and it will turn a different color when selected. Figure 27.2
shows the example provided with this chapter.
Figure 27.2
Screenshot of the provided
example for mouse picking.
Search Nedrilad ::




Custom Search