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.
20 /* Calculate the unit normal at p given two other points p1,p2 on the
21 surface. The normal points in the direction of p1 crossproduct p2
24 calc_normal (XYZ p, XYZ p1, XYZ p2)
33 n.x = pa.y * pb.z - pa.z * pb.y;
34 n.y = pa.z * pb.x - pa.x * pb.z;
35 n.z = pa.x * pb.y - pa.y * pb.x;
39 /* Call glNormal3f() with a normal of the indicated triangle.
42 do_normal(GLfloat x1, GLfloat y1, GLfloat z1,
43 GLfloat x2, GLfloat y2, GLfloat z2,
44 GLfloat x3, GLfloat y3, GLfloat z3)
47 p1.x = x1; p1.y = y1; p1.z = z1;
48 p2.x = x2; p2.y = y2; p2.z = z2;
49 p3.x = x3; p3.y = y3; p3.z = z3;
50 p = calc_normal (p1, p2, p3);
51 glNormal3f (p.x, p.y, p.z);