Game Development Reference
In-Depth Information
The constructor for the BillBoard class is shown in Listing 6-11. The constructor first calls the
constructor for the superclass Cube. Next, the scale for the billboard is set to normal along the x and
y local axes and minimized on the z axis, to make the billboard as thin as possible.
Listing 6-11. The BillBoard Class Constructor
BillBoard(Context iContext,
MeshEx iMeshEx,
Texture[] iTextures,
Material iMaterial,
Shader iShader )
{
super(iContext, iMeshEx, iTextures, iMaterial, iShader );
Vector3 Scale = new Vector3(1.0f,1.0f,0.1f);
m_Orientation.SetScale(Scale);
}
The SetBillBoardTowardCamera() function is where the billboard is actually turned toward the
camera or viewer.
The process of implementing billboarding is as follows:
1.
Get the front vector of the billboard object and project it onto the xz plane,
which is ForwardVecProj .
2.
Get the billboard position and project it onto the xz plane, which is
BillBoardPositionProj .
3.
Get the position of the camera and project it onto the xz plane, which is
CameraPositionProj .
4.
Calculate the vector from the billboard to the camera, which is
Bill2CameraVecProj .
5.
Find the angle between the forward or front vector of the billboard object and
the camera, which is Theta.
6.
Calculate the rotation axis by calculating the cross-product of the billboard's
front vector and the billboard to camera vector to form the rotation axis.
7.
Rotate the billboard toward the camera.
See Figure 6-2 for a visual depiction of the preceding steps, and see Listing 6-12 for the code that
implements the billboarding procedure.
 
Search WWH ::




Custom Search