Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: 3D Graphics Programming With QuickDraw 3D /
Chapter 8 - Light Objects


Using Light Objects

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

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 QuickDraw 3D 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).

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.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
11 JUL 1996




Navigation graphic, see text links

Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help