Sign in to follow this  

Problems calculating true normals

This topic is 4818 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites

This topic is 4818 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this