Vertex normals
Yup, it''s me again with a normal question... I finaly perfected my face normal calculation code, but now i need vertex normals.
Can any of give me a link or just tell me how to get vertex normals?
Thanks!
It''s easy. Just find the faces that share this vertex and average their normals, you''ll get your vertex normal.
here you go:
It works with the data structures on www.gametutorials.com (for 3DS loading and vectors)
EDIT: now i realized that both the "Vertex normals" and "Face normals" thread were yours .
[ My Site ]
'I wish life was not so short,' he thought. 'Languages take such a time, and so do all the things one wants to know about.' - J.R.R Tolkien
/*ilici*/
[edited by - Ilici on October 12, 2003 8:10:45 AM]
CVector3 *vNormals = NULL; CVector3 sum, v1, v2, v3; t3DObject* pObject; int i, j, k, l; bool e; for (i = 0; i < pModel->numOfObjects; i++) { pObject = &pModel->pObject[i]; pObject->pNormals = new CVector3 [pObject->numOfVerts]; vNormals = new CVector3 [pObject->numOfFaces]; for (j = 0; j < pObject->numOfFaces; j++) { v1 = pObject->pVerts[pObject->pFaces[j].vertIndex[0]]; v2 = pObject->pVerts[pObject->pFaces[j].vertIndex[1]]; v3 = pObject->pVerts[pObject->pFaces[j].vertIndex[2]]; vNormals[j] = Normalize(Cross(v1 - v2, v1 - v3)); } for (j = 0; j < pObject->numOfVerts; j++) { sum = CVector3(0, 0, 0); for (l = 0; l < pObject->numOfFaces; l++) { e = false; for (k = 0; k < 3; k++) { if (pObject->pFaces[l].vertIndex[k] == j) e = true; } if (e) { sum = sum + vNormals[l]; } } sum = Normalize(sum); pObject->pNormals[j] = sum; } delete [] vNormals; }
It works with the data structures on www.gametutorials.com (for 3DS loading and vectors)
EDIT: now i realized that both the "Vertex normals" and "Face normals" thread were yours .
[ My Site ]
'I wish life was not so short,' he thought. 'Languages take such a time, and so do all the things one wants to know about.' - J.R.R Tolkien
/*ilici*/
[edited by - Ilici on October 12, 2003 8:10:45 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement