3D Graphics Programming with QuickDraw 3D

8 Using Light Objects

QuickDraw3D supplies routines that you can use to create and manipulate light objects. This section describes how to accomplish these tasks.

8 Creating a Light

You create a light by filling in the fields of the data structure for the type of light you want to create and then by calling a QuickDraw3D function to create the light. For example, to create a point light, you fill in a data structure of type TQ3PointLightData and then call Q3PointLight_New, as shown in Listing 8-1.

Listing 8-1 Creating a new point light

TQ3LightObject MyNewPointLight (void)
{
 TQ3LightData        myLightData;
 TQ3PointLightData        myPointLightData;
 TQ3LightObject        myPointLight;
 TQ3Point3D        pointLocation = {-20.0, 0.0, 20.0};
 TQ3ColorRGB        WhiteLight = { 1.0, 1.0, 1.0 };

 /*Set up light data for a point light.*/
 myLightData.isOn = kQ3True;
 myLightData.brightness = 1.0;
 myLightData.color = WhiteLight;
 myPointLightData.lightData = myLightData;
 myPointLightData.castsShadows = kQ3False;
 myPointLightData.attenuation = kQ3AttenuationTypeNone;
 myPointLightData.location = pointLocation;

 /*Create a point light.*/
 myPointLight = Q3PointLight_New(&myPointLightData);
 return (myPointLight);
}
As you can see, the MyNewPointLight function defined in Listing 8-1 simply fills in the myPointLight structure and then calls Q3PointLight_New. MyNewPointLight returns to its caller either a reference to the new light (if Q3PointLight_New succeeds) or the value NULL (if Q3PointLight_New fails).

8 Manipulating Lights

For a light to affect a model in a view, you need to insert the light into the light group associated with the view. You call Q3LightGroup_New to create a new (empty) light group and Q3Group_AddObject to add lights to that group. Then you need to call Q3View_SetLightGroup to attach the light group to a view. Finally, you need to create an illumination shader that specifies the kind of illumination model you want applied to objects in the model. For example, to provide Phong illumination on the objects in a model, you can create an illumination shader by calling Q3PhongIllumination_New. The illumination shader is not explicitly associated with the view. Instead, you specify the illumination shader by calling Q3Shader_Submit in your rendering loop. See the chapter "Shader Objects" for details.

8 - Creating a Light
8 - Manipulating Lights

3D Graphics Programming with QuickDraw 3D - 16 OCT 1995

© Apple Computer, Inc.

Let us know what you think of these prototype pages.

Generated with Harlequin WebMaker