unknown
2005.09.21, 03:45 PM
Im really confused here,
If I define a triangle by vertices 0, 3, 7 the normal is wonkey, any rotation of that 703 or 370 works fine.
I really cant understand this, has anyone encountered it before?
This is my code for calculating normals,
Im am gussing there is some assumption made by the code that isnt true in every case.
tmp1 = m->vertices[m->triangles[i].a];
tmp2 = m->vertices[m->triangles[i].b];
tmp3 = m->vertices[m->triangles[i].c];
x1 = tmp1.x-tmp2.x; x2 = tmp2.x-tmp3.x;
y1 = tmp1.y-tmp2.y; y2 = tmp2.y-tmp3.y;
z1 = tmp1.z-tmp2.z; z2 = tmp2.z-tmp3.z;
Nx = y1*z2-z1*y2;
Ny = z1*x2-x1*z2;
Nz = z1*y2-y1*x2;
x1 = sqrt(Nx*Nx+Ny*Ny+Nz*Nz);
m->triangles[i].Nx = Nx/x1;
m->triangles[i].Ny = Ny/x1;
m->triangles[i].Nz = Nz/x1;
http://www.geocities.com/ed72678954/badnormals.jpg
The normal pointing towards the camera is the bad one.
If I define a triangle by vertices 0, 3, 7 the normal is wonkey, any rotation of that 703 or 370 works fine.
I really cant understand this, has anyone encountered it before?
This is my code for calculating normals,
Im am gussing there is some assumption made by the code that isnt true in every case.
tmp1 = m->vertices[m->triangles[i].a];
tmp2 = m->vertices[m->triangles[i].b];
tmp3 = m->vertices[m->triangles[i].c];
x1 = tmp1.x-tmp2.x; x2 = tmp2.x-tmp3.x;
y1 = tmp1.y-tmp2.y; y2 = tmp2.y-tmp3.y;
z1 = tmp1.z-tmp2.z; z2 = tmp2.z-tmp3.z;
Nx = y1*z2-z1*y2;
Ny = z1*x2-x1*z2;
Nz = z1*y2-y1*x2;
x1 = sqrt(Nx*Nx+Ny*Ny+Nz*Nz);
m->triangles[i].Nx = Nx/x1;
m->triangles[i].Ny = Ny/x1;
m->triangles[i].Nz = Nz/x1;
http://www.geocities.com/ed72678954/badnormals.jpg
The normal pointing towards the camera is the bad one.