Jump to content
  • Advertisement


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


Vertex normals

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post

Link to post
Share on other sites
here you go:

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

[edited by - Ilici on October 12, 2003 8:10:45 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!