//-----------------------------------------------------------------------------
// Desc: Set materials and lights
//-----------------------------------------------------------------------------
Void setlight ()
{
// Set the material.
D3dmaterial9 mtrl;
Zeromemory (& mtrl, sizeof (d3dmaterial9 ));
Mtrl. Diffuse. r = mtrl. Ambient. r = 1.0f;
Mtrl. Diffuse. G = mtrl. Ambient. G = 1.0f;
Mtrl. Diffuse. B = mtrl. Ambient. B = 0.0f;
Mtrl. Diffuse. A = mtrl. Ambient. A = 1.0f;
G_pd3ddevice-> setmaterial (& mtrl );
// Set the light
D3dxvector3 vecdir;
D3dlight9 light;
Zeromemory (& Light, sizeof (d3dlight9 ));
Light. type = d3dlight_directional;
Light. Diffuse. r = 1.0f;
Light. Diffuse. G = 1.0f;
Light. Diffuse. B = 1.0f;
Vecdir = d3dxvector3 (cosf (timegettime ()/3500000f ),
1.0f,
Sinf (timegettime ()/3500000f ));
// Vecdir = d3dxvector3 (1.0f, 1.0f, 0.0f );
D3dxvec3normalize (d3dxvector3 *) & Light. Direction, & vecdir );
Light. range = 1000.0f;
G_pd3ddevice-> setlight (0, & Light );
G_pd3ddevice-> lightenable (0, true );
G_pd3ddevice-> setrenderstate (d3drs_lighting, true );
// Set the ambient light
G_pd3ddevice-> setrenderstate (d3drs_ambient, 0x00505050 );
}
By setting the orientation of the rotating light, you can also make people feel that the object is rotating.
The material settings make us see the color of the object. If the light is turned on without the material, the object we see is black,
By default, the material does not reflect any light.
Change the color of g_pd3ddevice-> setrenderstate (d3drs_ambient, 0xff000000 );
Feel the difference between ambient light and a direction light source.