Setting Up the Lights

The BuildScene function implements two light sources: an ambient light and a directional light. An ambient light casts a uniform light over the entire scene. The position and orientation of its containing frame are ignored. A directional light, on the other hand, has direction but no position. It is attached to a frame but appears to illuminate all objects with equal intensity, as if it were at an infinite distance from each object.

First the BuildScene function creates a frame for the directional light and calls the IDirect3DRMFrame::SetPosition method to set its position in the scene. Then it calls the IDirect3DRM::CreateLightRGB method to create a directional light source. The IDirect3DRMFrame::AddLight method adds the directional light to the lighting frame. Then the IDirect3DRMFrame::SetRotation method causes the lighting frame to rotate.

After setting up the directional light, BuildScene creates a much dimmer ambient light source, again by calling IDirect3DRM::CreateLightRGB. Because ambient lights are not affected by the position and orientation of their containing frame, the BuildScene function specifies the frame for the entire scene in the call to IDirect3DRMFrame::AddLight that adds the ambient light.

LPDIRECT3DRMFRAME lights = NULL;

LPDIRECT3DRMLIGHT light1 = NULL;

LPDIRECT3DRMLIGHT light2 = NULL;

.

.

.

if (FAILED(lpD3DRM->lpVtbl->CreateFrame(lpD3DRM, scene, &lights)))

goto generic_error;

if (FAILED(lights->lpVtbl->SetPosition(lights, scene, D3DVAL(5),

D3DVAL(5), -D3DVAL(1))))

goto generic_error;

if (FAILED(lpD3DRM->lpVtbl->CreateLightRGB(lpD3DRM,

D3DRMLIGHT_DIRECTIONAL, D3DVAL(0.9),

D3DVAL(0.8), D3DVAL(0.7), &light1)))

goto generic_error;

if (FAILED(lights->lpVtbl->AddLight(lights, light1)))

goto generic_error;

if (FAILED(lights->lpVtbl->SetRotation(lights, scene, D3DVAL(0),

D3DVAL(1), D3DVAL(1), D3DVAL(-0.02))))

goto generic_error;

if (FAILED(lpD3DRM->lpVtbl->CreateLightRGB(lpD3DRM, D3DRMLIGHT_AMBIENT,

D3DVAL(0.1), D3DVAL(0.1), D3DVAL(0.1), &light2)))

goto generic_error;

if (FAILED(scene->lpVtbl->AddLight(scene, light2)))

goto generic_error;

The generic_error label identifies a place in the code where Egg.c displays a message box with an error value, releases any created COM objects, and returns FALSE from the BuildScene function.