#### Archived

This topic is now archived and is closed to further replies.

# problem with generating normals

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

## Recommended Posts

whenever i compile my code and run the program i keep getting unlit triangles. i am generating the normals on the fly from my vertex values. the vertex array is designed so that i can just throw them into a loop with glVertex3fv(). the function Cross generates the cross product. anyway here is the code:
vector<float> normal;
vector<float> vertex;
vector<float> face;
struct Vector3
{float x, y, z};

normal.resize(36*3);
Vector3 vertex1, vertex2, vertex3;
Vector3 edge1, edge2;
Vector3 tnormal;
for(int x=0; x<normal.size(); x+=9)
{
vertex1.x = face[x];	vertex1.y = face[x+1];	vertex1.z = face[x+2];
vertex2.x = face[x+3];	vertex2.y = face[x+4];	vertex2.z = face[x+5];
vertex3.x = face[x+6];	vertex3.y = face[x+7];	vertex3.z = face[x+8];

edge1 = vertex3 - vertex2;
edge2 = vertex1 - vertex2;

tnormal = Cross(edge1, edge2);

normal[x%9] = tnormal.x;
normal[(x%9)+1] = tnormal.y;
normal[(x%9)+2] = tnormal.z;
}

[edited by - adam17 on May 26, 2004 9:29:00 PM]

##### Share on other sites
For one, you are missing normal normalization.

You should never let your fears become the boundaries of your dreams.

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 10
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999987
×