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 typeTQ3PointLightData
and then callQ3PointLight_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, theMyNewPointLight
function defined in Listing 8-1 simply fills in themyPointLight
structure and then callsQ3PointLight_New
.MyNewPointLight
returns to its caller either a reference to the new light (ifQ3PointLight_New
succeeds) or the valueNULL
(ifQ3PointLight_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 callQ3LightGroup_New
to create a new (empty) light group andQ3Group_AddObject
to add lights to that group. Then you need to callQ3View_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 callingQ3PhongIllumination_New
. The illumination shader is not explicitly associated with the view. Instead, you specify the illumination shader by callingQ3Shader_Submit
in your rendering loop. See the chapter "Shader Objects" for details.
Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help