## Normal VectorsA An object's normal vectors define the orientation of its surface in space - in particular, its orientation relative to light sources. These vectors are used by OpenGL to determine how much light the object receives at its vertices. Lighting - a large topic by itself - is the subject of Chapter 5, and you might want to review the following information after you've read that chapter. Normal vectors are discussed briefly here because you define normal vectors for an object at the same time you define the object's geometry. You use
`glBegin (GL_POLYGON);`
` glNormal3fv(n0);`
` glVertex3fv(v0);`
` glNormal3fv(n1);`
` glVertex3fv(v1);`
` glNormal3fv(n2);`
` glVertex3fv(v2);`
` glNormal3fv(n3);`
` glVertex3fv(v3);`
`glEnd();`
There's no magic to finding the normals for an object - most likely, you have to perform some calculations that might include taking derivatives - but there are several techniques and tricks you can use to achieve certain effects. Appendix E explains how to find normal vectors for surfaces. If you already know how to do this, if you can count on always being supplied with normal vectors, or if you don't want to use the lighting facility provided by OpenGL lighting facility, you don't need to read this appendix. Note that at a given point on a surface, two vectors are perpendicular
to the surface, and they point in opposite directions. By convention, the normal
is the one that points to the outside of the surface being modeled. (If you
get inside and outside reversed in your model, just change every normal vector
from ( Also, keep in mind that since normal vectors indicate direction
only, their length is mostly irrelevant. You can specify normals of any length,
but eventually they have to be converted to having a length of 1 before lighting
calculations are performed. (A vector that has a length of 1 is said to be of
unit length, or normalized.) In general, you should supply normalized normal
vectors. To make a normal vector of unit length, divide each of its Normal vectors remain normalized as long as your model transformations
include only rotations and translations. (See Chapter 3 for a discussion of transformations.) If you perform irregular transformations
(such as scaling or multiplying by a shear matrix), or if you specify nonunit-length
normals, then you should have OpenGL automatically normalize your normal vectors
after the transformations. To do this, call |