1 /* normals, Copyright (c) 2002-2004 Jamie Zawinski <jwz@jwz.org>
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
11 * Compute normal vectors for arbitrary triangles.
18 /* Calculate the unit normal at p given two other points p1,p2 on the
19 surface. The normal points in the direction of p1 crossproduct p2
22 calc_normal (XYZ p, XYZ p1, XYZ p2)
31 n.x = pa.y * pb.z - pa.z * pb.y;
32 n.y = pa.z * pb.x - pa.x * pb.z;
33 n.z = pa.x * pb.y - pa.y * pb.x;
37 /* Call glNormal3f() with a normal of the indicated triangle.
40 do_normal(GLfloat x1, GLfloat y1, GLfloat z1,
41 GLfloat x2, GLfloat y2, GLfloat z2,
42 GLfloat x3, GLfloat y3, GLfloat z3)
45 p1.x = x1; p1.y = y1; p1.z = z1;
46 p2.x = x2; p2.y = y2; p2.z = z2;
47 p3.x = x3; p3.y = y3; p3.z = z3;
48 p = calc_normal (p1, p2, p3);
49 glNormal3f (p.x, p.y, p.z);