?/TD> |
Microsoft DirectX 9.0 |
The Billboard sample illustrates the billboarding technique. Rather than rendering complex 3-D models, such as a high-polygon tree model, billboarding renders a 2-D image of the model and rotates it to always face the eyepoint. This technique is commonly used to render trees, clouds, smoke, explosions, and more. For more information, see Billboarding.
In this sample, a camera flies around a 3-D scene with a tree-covered hill. The trees look like 3-D objects, but they are actually 2-D billboarded images that are rotated towards the eyepoint. The hilly terrain and the skybox, a six-sided cube containing sky textures, are objects loaded from .x files. They are used for visual effect and are unrelated to the billboarding technique.
Source: (SDK root)\Samples\C++\Direct3D\Billboard
Executable: (SDK root)\Samples\C++\Direct3D\Bin
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. |
The billboarding technique is the focus of this sample. The camera is moved in each frame, so the viewpoint changes accordingly. As the viewpoint changes, a rotation matrix is generated to rotate the billboards about the y-axis so that they face the new viewpoint. The computation of the billboard matrix occurs in the FrameMove function. The trees are also sorted in this function, as required for proper alpha blending, because billboards typically have some transparent pixels. The trees are rendered from a vertex buffer in the DrawTrees function.
The billboards in this sample are constrained to rotate about the y-axis only. Otherwise, the tree trunks would appear to not be fixed to the ground. For effects such as explosions in a 3-D flight simulator or space shooter, billboards are typically not constrained to one axis.
This sample uses common Microsoft?DirectX?code that consists of programming elements such as helper functions. This code is shared with other samples in the DirectX software development kit (SDK). You can find the sample framework headers and source code in (SDK root)\DXSDK\Samples\C++\Common\Include and (SDK root)\DXSDK\Samples\C++\Common\Src.