I have created a class that reads a 3d studio asc file into a standard format ( list of verticies , list of faces , list of models) and i have successfully calculated the normals for the faces. this works fine when i render the model but I want to be able to make it look smooth.

i have written a piece of code to calculate vertex normals based on the average of the normals for each of the faces that share a particulatr vertex.

this gives me a horrible result (all the faces are shaded in a very strange way) and i cant work out whats wrong.

can anyone help?

kev.

here is the code:

void C3DImportedASCObject::CalculateVertexNormals()

{

if(m_numModels > -1) {

for(int ii=0; ii<=m_numModels; ii++) {

for(int jj=0; jj<m_model[ii].numFaces; jj++) {

```
// set the vertex normal to the sum of all the shared face normals
for(int kk=0; kk<3; kk++) {
m_model[ii].faceList[jj].vertex[kk]->normal[0] +=
m_model[ii].faceList[jj].normal[0];
m_model[ii].faceList[jj].vertex[kk]->normal[1] +=
m_model[ii].faceList[jj].normal[1];
m_model[ii].faceList[jj].vertex[kk]->normal[2] +=
m_model[ii].faceList[jj].normal[2];
m_model[ii].faceList[jj].vertex[kk]->m_numSharedFaces++;
}
}
// average the vertex normals
for(int ll=0;ll<m_model[ii].numVertices;ll++) {
m_model[ii].vertexList[ll].normal[0] = m_model[ii].vertexList[ll].normal[0] /
m_model[ii].vertexList[ll].m_numSharedFaces;
m_model[ii].vertexList[ll].normal[1] = m_model[ii].vertexList[ll].normal[1] /
m_model[ii].vertexList[ll].m_numSharedFaces;
m_model[ii].vertexList[ll].normal[2] = m_model[ii].vertexList[ll].normal[2] /
m_model[ii].vertexList[ll].m_numSharedFaces;
Normalise(m_model[ii].vertexList[ll].normal[0],
m_model[ii].vertexList[ll].normal[1],
m_model[ii].vertexList[ll].normal[2]);
}
}
}
```

}