## Dodgy Normals!?!?!??!

Sage
Posts: 1,403
Joined: 2005.07
Post: #1
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.
Code:
```        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;```

The normal pointing towards the camera is the bad one.

Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
Member
Posts: 131
Joined: 2004.10
Post: #2
Check your cross product for Nz. It has an error.
Sage
Posts: 1,403
Joined: 2005.07
Post: #3
Haha, thank you very much, im so dumb!

Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
Member
Posts: 131
Joined: 2004.10
Post: #4
It happens.

A co-worker one time couldn't figure out why his code wasn't working. Apparently he was too tired and could see the different between 1 and l. Fonts didn't help here.

One from me recently. I got a rather unusual compiler error, one that I don't normally see. Something to the effect of FuncX doesn't exist when it really did and all includes were in order. Ended up being a missing ';' the line above it.

Get used to the frustration. When it gets too much, step away for a while and come back to it.