14.03.2014 Views

Scripting Guide - SAS

Scripting Guide - SAS

Scripting Guide - SAS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 13 Three-Dimensional Scenes 457<br />

Lighting and Normals<br />

The normal vector is of length 1 and is perpendicular to the vertex. Typically, a vertex is shared between<br />

several polygons and a smooth shaded effect is desired, so the perpendicular at the vertex is calculated as a<br />

(possibly weighted) average of the polygon’s normals. It is important to calculate the “outward” normal for<br />

polygons unless two-sided shading is enabled because only the outer face of the polygon is illuminated.<br />

With a scaled polygon, the normal’s length is not 1 after scaling, and the lighting is wrong.<br />

Normal vectors are set at the same time the surface is constructed, and are specified with the Normal<br />

command. Use the Enable(NORMALIZE) command to have the normals re-normalized to 1 each time the<br />

scene is drawn.<br />

Shading Model<br />

The shading model of a polygon is set using the Shade Model command.<br />

Shade Model (mode)<br />

where mode can be SMOOTH (the default) or FLAT. SMOOTH shading interpolates the colors of the primitive<br />

from one vertex to the next. FLAT mode duplicates the color of one vertex across the entire primitive.<br />

The following script changes the color at each of a triangle’s vertices. The FILL shade model interpolates the<br />

color of the interior automatically.<br />

// make a scene box...holds an OpenGL scene.<br />

scene = SceneBox( 200, 200 );<br />

// put the scene in a window.<br />

NewWindow( "Shade Model", scene );<br />

scene

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

Saved successfully!

Ooh no, something went wrong!