I've made this function to calculate true normals:
Bvertex Bmap::RetNormal(int w, int h) {
Bvertex n1, n2, n3, n, face1;
if (w < 0) w = 0; if (h < 0) h = 0;
n1 = CreateVertex(w, h);
n2 = CreateVertex(w - step, h);
n3 = CreateVertex(w - step, h + step);
n = bFunctions::Normal(n1, n2, n3);
n1 = CreateVertex(w, h);
n2 = CreateVertex(w - step, h + step);
n3 = CreateVertex(w, h + step);
face1 = bFunctions::Normal(n1, n2, n3);
AddVertex(&n, face1);
n1 = CreateVertex(w, h);
n2 = CreateVertex(w, h + step);
n3 = CreateVertex(w + step, h + step);
face1 = bFunctions::Normal(n1, n2, n3);
AddVertex(&n, face1);
n1 = CreateVertex(w, h);
n2 = CreateVertex(w + step, h + step);
n3 = CreateVertex(w + step, h);
face1 = bFunctions::Normal(n1, n2, n3);
AddVertex(&n, face1);
n1 = CreateVertex(w, h);
n2 = CreateVertex(w + step, h);
n3 = CreateVertex(w + step, h - step);
face1 = bFunctions::Normal(n1, n2, n3);
AddVertex(&n, face1);
n1 = CreateVertex(w, h);
n2 = CreateVertex(w + step, h - step);
n3 = CreateVertex(w, h - step);
face1 = bFunctions::Normal(n1, n2, n3);
AddVertex(&n, face1);
n1 = CreateVertex(w, h);
n2 = CreateVertex(w, h - step);
n3 = CreateVertex(w - step, h + step);
face1 = bFunctions::Normal(n1, n2, n3);
AddVertex(&n, face1);
n1 = CreateVertex(w, h);
n2 = CreateVertex(w - step, h - step);
n3 = CreateVertex(w - step, h);
face1 = bFunctions::Normal(n1, n2, n3);
AddVertex(&n, face1);
n = bFunctions::Normalize(n);
return n;
}
I'm sorry for the less comments.. :)
But it doesn't work, i get a kind of weird lighting. I call it in this way:
LoadNormalCoord(w, h, &faces[0], &faces[1]); // Load the right vertexes into the memory
/*--- Render first triangle ---*/
face = faces[0]; // Put in face the first face
glNormal(RetNormal(w, h));
glVertex(face.v1); // Render top-left part
glNormal(RetNormal(w+1, h));
glVertex(face.v2); // Render top-right part
glNormal(RetNormal(w+1, h+1));
glVertex(face.v3); // Render down-right part
/*--- Render second triangle ---*/
face = faces[1]; // Put in face the second face
glNormal(RetNormal(w, h));
glVertex(face.v1); // Render top-left part again
glNormal(RetNormal(w+1, h+1));
glVertex(face.v2); // Render down-right part again
glNormal(RetNormal(w, h+1));
glVertex(face.v3); // Render down-left part
What am i doing wrong? The calculation of normals doesn't contain any errors (it works with flat normals).
Thanks in advance..
[Edited by - programBoy on October 8, 2004 9:22:49 AM]