Original Post
Hi everyone ! I started reading on lights using DX SDK tutorials but there are things I don't quite understand. Consider the following code:Why does everything turn black if I change ANY variable of light.Diffuse to something else than 1.0f ? Could someone explain the whole D3DXVec3Normalize() line ? I don't understand why the author used timeGetTime() to set the light's direction... and I don't know what normalizing is (I'm taking physic classes but it's a bit ahead of me for now...) In this example, after 1000.0f (Z axis) the light will be completely off right ? How would it be possible to have many different lights at the same time ? Is it hard ? What does the last line do ? Finally, what's the difference between those 2 lines ?
void SetupLight()
{
D3DMATERIAL9 mtrl;
ZeroMemory(&mtrl, sizeof(D3DMATERIAL9));
mtrl.Diffuse.a = 1.0f;
mtrl.Diffuse.b = 0.0f;
mtrl.Diffuse.r = 1.0f;
mtrl.Diffuse.g = 0.0f;
D3DDev->SetMaterial(&mtrl);
D3DLIGHT9 light;
ZeroMemory(&light, sizeof(D3DLIGHT9));
light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse.b = 1.0f;
light.Diffuse.r = 1.0f;
light.Diffuse.g = 1.0f;
D3DXVec3Normalize((D3DXVECTOR3*)&light.Direction,
&D3DXVECTOR3(cosf(timeGetTime() / 350.0f), 0.0f, sinf(timeGetTime() / 350.0f)));
light.Range = 1000.0f;
D3DDev->SetLight(0, &light);
D3DDev->LightEnable(0, true);
D3DDev->SetRenderState(D3DRS_LIGHTING, true);
D3DDev->SetRenderState(D3DRS_AMBIENT, 0x00202020);
}
D3DDev->LightEnable(0, true);
D3DDev->SetRenderState(D3DRS_LIGHTING, true);Thank you a lot guys/girls.