Calculating vertex normals for a terrain
Hey,
I''ve been trying to calculate vertex-normals for a triangle-strip terrain. I''ve been trying to add this feature to GameTutorial''s terrain tutorial #2. Though, I didn''t manage to add this feature.
I know how to calculate vertex normals for a model which uses regular triangles, but I have no idea how to do the same thing for triangle-strips. I''ve searched the net for a tutorial or a source code which does that, but found none.
Please, can you tell me what''s the algorithm to do it? Or, can you please link me to some tutorial/source code?
Thanks,
Yuval
Well, be more specific. For example how do you have stored vertices and faces/trianglestrips. Is the terrain of m x n vertices stored like a m x n matrix ?
Without these informations i can only tell you, that you
have to manage, which triangles belong to which vertex.
Without these informations i can only tell you, that you
have to manage, which triangles belong to which vertex.
I use this algorithm to calculate normal from 3 points.
you should give the points in counterclockwise order, or your normal will point downwards.
normale3f(GLfloat a, GLfloat b, GLfloat c, // first point coord
GLfloat d, GLfloat e, GLfloat f, // second
GLfloat g, GLfloat h, GLfloat i) { // third
GLfloat n[3]; // normal vector
n[0] = ((h-e)*(f-c) - (i-f)*(e-b));
n[1] = ((f-c)*(g-d) - (d-a)*(i-f));
n[2] = ((d-a)*(h-e) - (e-b)*(g-d));
}
if you want to know why this is done this way, ask me and i will try to explain you :D
of course, you need to normalize the vector ....
you should give the points in counterclockwise order, or your normal will point downwards.
normale3f(GLfloat a, GLfloat b, GLfloat c, // first point coord
GLfloat d, GLfloat e, GLfloat f, // second
GLfloat g, GLfloat h, GLfloat i) { // third
GLfloat n[3]; // normal vector
n[0] = ((h-e)*(f-c) - (i-f)*(e-b));
n[1] = ((f-c)*(g-d) - (d-a)*(i-f));
n[2] = ((d-a)*(h-e) - (e-b)*(g-d));
}
if you want to know why this is done this way, ask me and i will try to explain you :D
of course, you need to normalize the vector ....
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement