iDevGames Forums
Dodgy Normals!?!?!??! - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Dodgy Normals!?!?!??! (/thread-5010.html)

Dodgy Normals!?!?!??! - unknown - Sep 21, 2005 11:45 AM

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;

[Image: badnormals.jpg]
The normal pointing towards the camera is the bad one.

Dodgy Normals!?!?!??! - Zekaric - Sep 21, 2005 12:24 PM

Check your cross product for Nz. It has an error.

Dodgy Normals!?!?!??! - unknown - Sep 21, 2005 12:25 PM

Haha, thank you very much, im so dumb!

Dodgy Normals!?!?!??! - Zekaric - Sep 21, 2005 05:11 PM

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.