PDA

View Full Version : Averaging normals



Questions Burner
01-03-2002, 07:02 PM
How?

Raf
01-04-2002, 01:22 AM
You have to learn the linear algebra to calculate the normals.

j
01-04-2002, 06:27 AM
Pseudocode:

NORMAL result = 0;

for(i = 0; i < number of normals; i++)
result += normal[i];

normal /= number of normals;

j

Zeno
01-04-2002, 09:03 AM
The above code needs to have the line:
"normal /= number of normals" replaced with normal.normalize().

This is because, for instance, if one normal is 0,0,1 and another is 0,1,0 you would get 0,0.5,0.5 as the answer which is not unit length.

-- Zeno

Questions Burner
01-04-2002, 08:31 PM
Is it...






NORMAL result = 0;

for(i = 0; i < total_of_normals; i++)
{
result += normal[i];
}

normal /= total_of_normals;
normalize(result);

Bob
01-05-2002, 02:35 AM
You don't have to divide by the number of normals at all. Just sum them and normalize the resulting vector.

Questions Burner
01-06-2002, 07:49 PM
http://www.opengl.org/discussion_boards/ubb/smile.gif