I am writing a 3ds file parser in c++. Now I am working on normals, and I found this piece of code somewhere on web:
void calculateNormals(vert a, vert b, vert c,GLfloat *nx,GLfloat *ny, GLfloat *nz){
GLfloat Qx, Qy, Qz, Px, Py, Pz;
GLfloat v1[3] = {a.x,a.y,a.z};
GLfloat v2[3] = {b.x,b.y,b.z};
GLfloat v3[3] = {c.x,c.y,c.z};
Qx = v2[0]-v1[0];
Qy = v2[1]-v1[1];
Qz = v2[2]-v1[2];
Px = v3[0]-v1[0];
Py = v3[1]-v1[1];
Pz = v3[2]-v1[2];
*nx = Py*Qz - Pz*Qy;
*ny = Pz*Qx - Px*Qz;
*nz = Px*Qy - Py*Qx;
}
I understand almost everything, except 3 last lines. I just... can't figure out how and why it works.
Can someone explain how it's calculated?