11.07.2015 Views

Chapter 54

Chapter 54

Chapter 54

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

diffuse shading from a directed light source as min(1DredxRredx(L'* N), 1) and likewisefor the green and blue color components.The overall red shading for each polygon can be calculated by summing the ambientshadingred component with the diffuse-shading component from each light source,as in min( (IAredxRred) + (1Drcd,,xRredx(LO' N)) + (IDredlxRredx(L1' N)) +..., 1) whereIDredo and Lo' are the red intensity and the reversed unit-direction vector, respectively,for spotlight 0. Listing <strong>54</strong>.2 shows the X-Sharp module DRAWPOBJ.C, whichperforms ambient and diffuse shading. Toward the end, you will find the code thatperforms shading exactly as described by the above equation, first calculating theambient red, green, and blue shadings, then summing that with the diffuse red,green, and blue shadings generated by each directed light source.LISTING <strong>54</strong>.2 DRAWP0BJ.C/* Draws all visible faces in the specified polygon-based object. The objectmust have previously been transformed and projected, so that al vertexarrays are filled in. Ambient and diffuse shading are supported. */Dincl ude "polygon. h"void DrawPObject(P0bject * ObjectToXform)tint i. j. NumFaces - ObjectToXform->NumFaces. NumVertices:int * VertNumsPtr, Spot;Face * FacePtr - ObjectToXform->FaceList:Point * Screenpoints = ObjectToXform->ScreenVertexList;PointListHeader Polygon:Fixedpoint Diffusion:Model Col or Col orTemp:ModelIntensity IntensityTemp:Point3 UnitNormal, *NormalStartpoint. *NormalEndpoint:long VI. v2, wl. w2:Point VerticesCMAX-POLY-LENGTH];/* Draw each visible face (polygon) of the object in turn */for (i=O: iVertNums:NormalEndpoint - &ObjectToXform->XformedVertexList[*VertNumsPtr++l:NormalStartpoint = &ObjectToXform->XformedVertexListC*VertNumsPtrl:/* Copy over the face's vertices from the vertex list */NumVertices = FacePtr->NumVerts:for (j-0: j 0) [/* It is facing the screen, so draw */3-D Shading 1025

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!