Hey all im just messing around with what I am learning in class about direct3d light, particularly Point light. Anyways I have some code that creates a cube primitive and a point light. I basically just want to allow the user to move the light left and right over the object. Well it doesnt appear to be moving so perhaps someone can see whats wrong with my code.
Here is the code for the movement:
LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
break;
case WM_KEYUP:
if(wp == VK_ESCAPE) PostQuitMessage(0);
break;
case WM_KEYDOWN:
if(wp == VK_LEFT) pos.x -= 1.0f ;
if(wp == VK_RIGHT) pos.x += 1.0f;
break;
}
return DefWindowProc(hWnd, msg, wp, lp);
}
Here is the code for the light
bool InitializeObjects()
{
pos.x = 0.0f;
pos.y = 0.0f;
pos.z = 1.0f;
// Set default rendering states.
g_D3DDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
g_D3DDevice->SetRenderState(D3DRS_AMBIENT,
D3DCOLOR_COLORVALUE(0.3f, 0.3f, 0.3f, 1.0f));
// Setup the light source.
g_light.Type = D3DLIGHT_POINT;
g_light.Direction = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
g_light.Diffuse.r = g_light.Diffuse.g = 1.0f;
g_light.Diffuse.b = 1.0f;
g_light.Specular.r = g_light.Specular.g = 1;
g_light.Specular.b = g_light.Specular.a = 1;
g_light.Position = pos;
g_light.Attenuation0 = 0.1f;
g_light.Range = 300.0f;
// Register the light.
g_D3DDevice->SetLight(0, &g_light);
g_D3DDevice->LightEnable(0, TRUE);
// Setup the material properties for the teapot.
ZeroMemory(&g_material, sizeof(D3DMATERIAL9));
g_material.Diffuse.r = g_material.Ambient.r = 0.6f;
g_material.Diffuse.g = g_material.Ambient.g = 0.6f;
g_material.Diffuse.b = g_material.Ambient.b = 0.7f;
g_material.Specular.r = 0.4f;
g_material.Specular.g = 0.4f;
g_material.Specular.b = 0.4f;
g_material.Power = 8.0f;
// Create the objects.
if(FAILED(D3DXCreateBox(g_D3DDevice, 2, 2, 2, &g_cube, NULL)))
return false;
// Define camera information.
D3DXVECTOR3 cameraPos(0.0f, 0.0f, -8.0f);
D3DXVECTOR3 lookAtPos(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 upDir(0.0f, 1.0f, 0.0f);
// Build view matrix.
D3DXMatrixLookAtLH(&g_ViewMatrix, &cameraPos, &lookAtPos, &upDir);
return true;
}
Any help is greatly appreciated thanks for your time!
Mike