void DrawTriangle( float x0,float y0, float z0,float x1, float y1, float z1, float x2, float y2, float z2)
{
float vec0[3],vec1[3],normal[3];
// calculate vectors A->B, A->C
vec0[0] = x1-x0;
vec0[1] = y1-y0;
vec0[2] = z1-z0;
vec1[0] = x2-x0;
vec1[1] = y2-y0;
vec1[2] = z2-z0;
// do cross product
normal[0] = vec0[1]*vec1[2] - vec0[2]*vec1[1];
normal[1] = vec0[2]*vec1[0] - vec0[0]*vec1[2];
normal[2] = vec0[0]*vec1[1] - vec0[1]*vec1[0];
// normalise vector
float l = sqrt( normal[0]*normal[0] + normal[1]*normal[1] + normal[2]*normal[2] );
normal[0] /= l;
normal[1] /= l;
normal[2] /= l;
// draw triangle
glBegin(GL_TRIANGLES);
glNormal3fv(normal);
glVertex3f(x0,y0,z0);
glVertex3f(x1,y1,z1);
glVertex3f(x2,y2,z2);
glEnd();
}