void calc_pn()
{
float rx1,rx2,ry1,ry2,rz1,rz2,val;
int i,j,c;
for (i=0;i<=last_face;i++) {
rx1=vertex[face[i].b].x-vertex[face[i].a].x;
ry1=vertex[face[i].b].y-vertex[face[i].a].y;
rz1=vertex[face[i].b].z-vertex[face[i].a].z;
rx2=vertex[face[i].c].x-vertex[face[i].a].x;
ry2=vertex[face[i].c].y-vertex[face[i].a].y;
rz2=vertex[face[i].c].z-vertex[face[i].a].z;
_normals[i].x = ry1*rz2 - ry2*rz1;
_normals[i].y = rz1*rx2 - rz2*rx1;
_normals[i].z = rx1*ry2 - rx2*ry1;
}
for (i=0;i<=last_vertex;i++) {
rx1=0;
ry1=0;
rz1=0;
c=0;
for (j=0;j<=last_face;j++) {
if ((face[j].x==i) || (face[j].y==i) || (face[j].z==i)) {
rx1+=_normals[j].x;
ry1+=_normals[j].y;
rz1+=_normals[j].z;
c++;
}
}
if (c!=0) {
rx1/=c;
ry1/=c;
rz1/=c;
val=sqrt(rx1*rx1+ry1*ry1+rz1*rz1);
if (val==0) val=1;
normals[i].x=(rx1/val)*128;
normals[i].y=(ry1/val)*128;
normals[i].z=(rz1/val)*128;
}
}
}
výheň