Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Vertices - Calculating their normals?

Author
Message
Hayer
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 26th Sep 2008 15:09
Hi!
What are vertice normals and how do I calculate them?

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Sep 2008 19:58 Edited at: 26th Sep 2008 20:01
Assuming you want smoothing of the lighting, you calculate a vertex normal by averaging the normals of all faces that share that vertex.

Calculating face normals - here's a diagram to help you follow the description:


First calculate vectors from points v0->v1 and v0->v2 - this can be done by subtracting v0 from v1 and v2 in turn giving 2 new vectors vec0 & vec1. You then take the cross-product of these vectors, which results in a new vector FaceVec which should then be normalised (ie, calculate the length of the vector using pythagoras, then divide each part of the vector by this amount) - this is your face normal.

[EDIT]While I'm at it, I'll point you in the direction of some example code - http://www.gamedev.net/reference/articles/article1682.asp. Ignore the fact that most of the article is about OpenGL - just look for the 3 function for getFaceNormal, crossProduct and normalize.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-09-30 07:14:11
Your offset time is: 2024-09-30 07:14:11