Microsoft DirectX 8.1 (C++)

Pick Sample

Description

The Pick sample shows how to implement picking; that is, finding which triangle in a mesh is intersected by a ray. In this case, the ray comes from mouse coordinates.

Path

Source: (SDK root)\Samples\Multimedia\Direct3D\Pick

Executable: (SDK root)\Samples\Multimedia\Direct3D\Bin

User's Guide

The following table lists the keys that are implemented. You can use menu commands for the same controls.

Key Action
ENTER Starts and stops the scene.
SPACEBAR Advances the scene by a small increment.
F2 Prompts the user to select a new rendering device or display mode.
ALT+ENTER Toggles between full-screen and windowed modes.
ESC Exits the application.

Use the mouse to pick any spot in the mesh to see that triangle.

Programming Notes

When you click the mouse, the code reads the screen coordinates of the cursor. These coordinates are converted, through the projection and view matrices, into a ray that goes from the eyepoint through the point clicked on the screen and into the scene. This ray is passed to IntersectTriangle along with each triangle of the loaded model to determine which triangles, if any, are intersected by the ray. The texture coordinates of the intersected triangle is also determined.

This sample uses common Microsoft® DirectX® code that consists programming elements such as helper functions. This code is shared with other samples in the DirectX SDK. You can find the common headers and source code in (SDK root)\Samples\Multimedia\Common.