Game Development Reference
In-Depth Information
Finally, we are ready to draw the reflected teapot:
Device->SetTransform(D3DTS_WORLD, &W);
Device->SetMaterial(&TeapotMtrl);
Device->SetTexture(0, 0);
Device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
Teapot->DrawSubset(0);
Recall from section 8.2.3.4 that W correctly transforms the reflected
teapot into its appropriate position in the scene. Also, observe that we
change the backface cull mode. We must do this because when an
object is reflected, its front faces will be swapped with its back faces;
however, the winding order will not be changed. Thus, the “new” front
faces will have a winding order that indicates to Direct3D that they are
back facing. Similarly, the “new” back-facing triangles will have a wind-
ing order that indicates to Direct3D that they are front facing.
Therefore, to correct this, we must change our backface culling
condition.
Cleaning up, we disable blending and stenciling and restore the
usual cull mode:
Device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
Device->SetRenderState( D3DRS_STENCILENABLE, false);
Device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
} // end RenderMirror()
8.3 Sample Application: Planar Shadows
Shadows aid in our perception of where light is being emitted in a scene
and ultimately makes the scene more realistic. In this section we show
how to implement planar shadows—that is, shadows that lie on a plane
(see Figure 8.5).
Figure 8.5: A screen shot
taken from this chapter's
sample application.
Notice the teapot's
shadow on the floor.
Team-Fly ®
Search WWH ::




Custom Search