Calculating Normals

Started by
10 comments, last by colinisinhere 20 years, 8 months ago
float v1x = vertex2.x - vertex0.x;
float v1y = vertex2.y - vertex0.y;
float v1z = vertex2.z - vertex0.z;

float v2x = vertex1.x - vertex2.x;
float v2y = vertex1.y - vertex2.y;
float v2z = vertex1.z - vertex2.z;

should be

float v1x = vertex1.x - vertex0.x;
float v1y = vertex1.y - vertex0.y;
float v1z = vertex1.z - vertex0.z;

float v2x = vertex2.x - vertex0.x;
float v2y = vertex2.y - vertex0.y;
float v2z = vertex2.z - vertex0.z;

My Site
Advertisement
and why don''t you make a vector class with + - / etc. operators? that way it really makes your code much more readable. Calculating the normal will be only this if you do it that way:

VECTOR3D normal = CrossProduct(vert[1] - vert[0],vert[2] - vert0]);
normal.Normalize();

My Site

This topic is closed to new replies.

Advertisement