Microsoft DirectX 8.1 (Visual Basic) |
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 so that it always faces the eyepoint. This technique is commonly used to render trees, clouds, smoke, explosions, and so on. For more information, see Billboarding.
In the Billboard 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 toward 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\Multimedia\VBSamples\Direct3D\Billboard
Executable: (SDK root)\Samples\Multimedia\VBSamples\Direct3D\Bin
The following table lists the keys that are implemented.
Key | Action |
---|---|
F2 | Prompts you 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 that 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 that 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 not appear to be fixed to the ground. In a 3-D flight simulation or space shooter, for effects like explosions, 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 on the DirectX SDK. You can find the common source code in (SDK root)\Samples\Multimedia\VBSamples.