Game Development Reference
In-Depth Information
D3DMATERIAL9 mtrl;
mtrl.Ambient = d3d::WHITE;
mtrl.Diffuse = d3d::WHITE;
mtrl.Specular = d3d::WHITE;
mtrl.Emissive = d3d::BLACK;
mtrl.Power
= 5.0f;
Device->SetMaterial(&mtrl);
Second to last, we create and enable a directional light. The directional
light rays run parallel to the x-axis in the positive direction. The light
emits strong white diffuse light ( dir.Diffuse = WHITE ), weak
white specular light ( dir.Specular = WHITE * 0.3f ), and a
medium amount of white ambient light ( dir.Ambient = WHITE *
0.6f ).
D3DLIGHT9 dir;
::ZeroMemory(&dir, sizeof(dir));
dir.Type = D3DLIGHT_DIRECTIONAL;
dir.Diffuse = d3d::WHITE;
dir.Specular = d3d::WHITE * 0.3f;
dir.Ambient = d3d::WHITE * 0.6f;
dir.Direction = D3DXVECTOR3(1.0f, 0.0f, 0.0f);
Device->SetLight(0, &dir);
Device->LightEnable(0, true);
Finally, we set the state to renormalize normals and enable specular
highlights.
Device->SetRenderState(D3DRS_NORMALIZENORMALS, true);
Device->SetRenderState(D3DRS_SPECULARENABLE, true);
// ... code to set up the view matrix and projection matrix
// omitted
return true;
}
5.6 Additional Samples
Three additional samples are included for this chapter in the companion
files. They use the D3DXCreate * functions to create the 3D objects
that compose the scene. The D3DXCreate* functions create vertex
data with the format D3DFVF_XYZ | D3DFVF_NORMAL . In addition
these functions compute the vertex normals of each mesh for us. The
additional samples demonstrate how to use directional lights, point
lights, and spot lights. Figure 5.8 shows a screen shot from the direc-
tional light sample.
Search WWH ::




Custom Search