Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have quite a few debug drawing methods in my engine that can generate geometry useful for debugging, like spheres and cubes.

At the moment I do not generate any normals for these shapes. Is there a general purpose method of generating face normals and per vertex normals for an arbitrary mesh? (I'd imagine you would need face normals to generate per vertex normals?)

share|improve this question
add comment

2 Answers

up vote 10 down vote accepted

To generate face normals, use the vector cross product of two edges each triangle and then normalise the result. Make sure you get the directions right, otherwise some normals will point in and some out.

Vertex normals would then be an interpolation of all the face normals the vertex is attached to.

share|improve this answer
    
You mean a normalized interpolation (or simply a normalized summation), presumably ;) –  Andrew Russell Jul 30 '10 at 11:05
2  
Always renormalize after summing! Even if you interpolated from normalized vectors, the result is NOT normalized! –  Bob Somers Aug 1 '10 at 1:13
    
Thanks for that, sounds simple enough. –  Cubed2D Aug 2 '10 at 10:18
add comment

There are various ways of interpolating normals between faces. More details here: http://meshlabstuff.blogspot.com/2009/04/on-computation-of-vertex-normals.html

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.