i have this function that i made,it will eventually do smooth normals but for now i want face normals to work
here is the function:
void SmoothNormals(float *coords,float *normals,int ncoords,float angle) {
for(int i = 0;i < ncoords;i += 9) {
Vector3 vVector1(coords[i],coords[i+1],coords[i+2]);
Vector3 vVector2(coords[i+3],coords[i+4],coords[i+5]);
Vector3 vVector3(coords[i+6],coords[i+7],coords[i+8]);
Vector3 mVector1 = vVector2 - vVector1;
Vector3 mVector2 = vVector3 - vVector1;
Vector3 vNormal = Cross(mVector2,mVector1);
vNormal = Normalize(vNormal);
for(int j = 0;j<9;j+=3) {
normals[i+j] = vNormal.x;
normals[i+j+1] = vNormal.y;
normals[i+j+2] = vNormal.z;
}
}
}
and this is how i draw the mesh:
glBegin(GL_TRIANGLES);
SmoothNormals(&mesh.coordinates[0],&mesh.normals[0],mesh.nCoords,0);
for (int k = 0;k < (mesh.nCoords);k+=3) {
glNormal3fv(&mesh.normals[k]);
glVertex3fv(&mesh.coordinates[k]);
}
glEnd();
but when i run the program the mesh draws fine but it is all one colour and there are no visible faces
whats going wrong?