|
|
void InitTeapot()
{
D3DXCreateTeapot(pDevice, &teapot, 0);
D3DXCOLOR green( D3DCOLOR_XRGB(0,200,100));
D3DXCOLOR higreen( D3DCOLOR_XRGB(255,255,255));
D3DXCOLOR black(D3DCOLOR_XRGB(0,0,0));
mat = InitMaterial(green,green,higreen,black,2.0f);
pDevice->SetMaterial(&mat);
D3DXVECTOR3 dir2(0.0f, 3.0f, -5.0f);//如果改为(0.0f, 0.0f, 0.0f)物体是白色的
D3DXVECTOR3 pos(0.0f,0.0f,-5.0f);
D3DXCOLOR c(D3DCOLOR_XRGB(255,255,255));
D3DLIGHT9 dirLight = InitSpotLight(&pos,&dir2, &c,1000.0f,0.4f,0.9f);
pDevice->SetLight(0, &dirLight);
pDevice->LightEnable(0, true);
SetupPerspective();
SetupCamera();
pDevice->SetRenderState(D3DRS_LIGHTING,true);
pDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true);
pDevice->SetRenderState(D3DRS_SPECULARENABLE, false);
}
D3DLIGHT9 InitSpotLight(D3DXVECTOR3* position, D3DXVECTOR3* direction, D3DXCOLOR* color,double dRange, double theta,double phi)
{
D3DLIGHT9 light;
::ZeroMemory(&light, sizeof(light));
light.Type = D3DLIGHT_SPOT;
light.Ambient = *color * 0.0f;
light.Diffuse = *color;
light.Specular = *color * 0.6f;
light.Position = *position;
light.Direction = *direction;
light.Range = dRange;
light.Falloff = 1.0f;
light.Attenuation0 = 1.0f;
light.Attenuation1 = 0.0f;
light.Attenuation2 = 0.0f;
light.Theta = theta;
light.Phi = phi;
return light;
}
程序运行后物体是黑色的,但如果按上面的注解处改动后物体是白色的,不明白应该怎样设置才能正常 |
|