Shadow
声明变量ID3DXMesh* mesh;
ID3DXMesh* wall;
开启深度缓存不再赘述
绘制场景D3DXMATRIX T;
D3DXMatrixTranslation(&T, 1, 1, 0);
g_pd3dDevice->SetTransform(D3DTS_WORLD, &T);
g_pd3dDevice->SetMaterial(&red_mtrl);
mesh->DrawSubset(0);
D3DXMatrixTranslation(&T, 0, -0.5f, 0);
g_pd3dDevice->SetTransform(D3DTS_WORLD, &T);
g_pd3dDevice->SetMaterial(&white_mtrl);
wall->DrawSubset(0);
绘制阴影//光的位置
D3DXVECTOR4 lightDirection(1, -1, 0, 0.0f);
D3DXPLANE groundPlane(0.0f, -1.0f, 0.0f, 0.0f);
D3DXMATRIX S;
//计算阴影位置
D3DXMatrixShadow(&S, &lightDirection, &groundPlane);
//物体平移位置
D3DXMatrixTranslation(&T, 1, 1, 0);
D3DXMATRIX W = T * S;
g_pd3dDevice->SetTransform(D3DTS_WORLD, &W);
D3DMATERIAL9 mtrl = InitMatrix(Black, Black, Black, Black, 0.0f);
mtrl.Diffuse.a = 0.5f;
g_pd3dDevice->SetMaterial(&mtrl);
mesh->DrawSubset(0);
效果