rovolution

06-29-2010, 12:28 AM

Hello all,

I have a huge question about setting normal vectors for coned surfaces.

So I have a piece of code where i want to draw a tree by approximating it with 4 triangles

glBegin( GL_TRIANGLES);

glColor3f(0, 1, 0);

double yval = 0.5;

//One triangle side

glTexCoord2f( leafRep/2,leafRep);

glVertex3f(0,1,0);

glNormal3f(-1, yval, -1);

glTexCoord2f(leafRep,0.0);

glVertex3f(-1,0,-1);

glNormal3f(1, yval,-1);

glTexCoord2f(0.0 ,0.0);

glVertex3f(1,0,-1);

glEnd();

glBegin( GL_TRIANGLES);

//another side

glNormal3f(0, 1, 0);

glTexCoord2f( leafRep/2,leafRep);

glVertex3f(0,1,0);

glNormal3f(1, yval,-1);

glTexCoord2f(leafRep,0.0);

glVertex3f(1,0,-1);

glNormal3f(1, yval, 1);

glTexCoord2f(0.0 ,0.0);

glVertex3f(1,0,1);

glEnd();

glBegin( GL_TRIANGLES);

//another side

glNormal3f(0, 1, 0);

glTexCoord2f( leafRep/2,leafRep);

glVertex3f(0,1,0);

glNormal3f(1, yval, 1);

glTexCoord2f(leafRep,0.0);

glVertex3f(1,0,1);

glNormal3f(-1, yval, 1);

glTexCoord2f(0.0 ,0.0);

glVertex3f(-1,0,1);

glEnd();

glBegin( GL_TRIANGLES);

//another side

glNormal3f(0, 1, 0);

glTexCoord2f( leafRep/2,leafRep);

glVertex3f(0,1,0);

glNormal3f(-1, yval, -1);

glTexCoord2f(leafRep,0.0);

glVertex3f(-1,0,-1);

glNormal3f(-1,yval,1);

glTexCoord2f(0.0 ,0.0);

glVertex3f(-1,0,1);

glEnd();

I have been told that i am setting the normals incorrectly.

So i went on the internet and found a number of tutorials on Gourad Shading and how I should calculate the normals for each triangular surface and then calculate the average of the surface normals that intersect at a particular vertice to get the proper normal vector for that vertice.

But then I was told this:

This technique is only necessary if all you know is the what the triangles

are. When an object is defined ONLY in terms of the triangles, then

Gouraud requires that you calculate the normals that way.

However, when drawing a cylinder or cone or some object which is

analytically defined, you don't have to do that because you KNOW what the

normal is. Using symmetry, it is very easy to show that the answer you

get when averaging the inidividual normals is in fact the true normal.

So the bottom line is if you apply the technique you outline, you will

laboriously calculate a normal which you can determine by inspection.

I do not understand how that applies to my code because i did not use any kind of parametic equation involving sins or cosines to generate my shape.

How would i properly calculate the normals for the vertices to show a "curved effect" without going through the whole averaging the surface normals technique?

Is there even such a way? Do i have to calculate the slope from the top of my tree to one of the edge vertices and then figure something out. I am really confused :(

I have a huge question about setting normal vectors for coned surfaces.

So I have a piece of code where i want to draw a tree by approximating it with 4 triangles

glBegin( GL_TRIANGLES);

glColor3f(0, 1, 0);

double yval = 0.5;

//One triangle side

glTexCoord2f( leafRep/2,leafRep);

glVertex3f(0,1,0);

glNormal3f(-1, yval, -1);

glTexCoord2f(leafRep,0.0);

glVertex3f(-1,0,-1);

glNormal3f(1, yval,-1);

glTexCoord2f(0.0 ,0.0);

glVertex3f(1,0,-1);

glEnd();

glBegin( GL_TRIANGLES);

//another side

glNormal3f(0, 1, 0);

glTexCoord2f( leafRep/2,leafRep);

glVertex3f(0,1,0);

glNormal3f(1, yval,-1);

glTexCoord2f(leafRep,0.0);

glVertex3f(1,0,-1);

glNormal3f(1, yval, 1);

glTexCoord2f(0.0 ,0.0);

glVertex3f(1,0,1);

glEnd();

glBegin( GL_TRIANGLES);

//another side

glNormal3f(0, 1, 0);

glTexCoord2f( leafRep/2,leafRep);

glVertex3f(0,1,0);

glNormal3f(1, yval, 1);

glTexCoord2f(leafRep,0.0);

glVertex3f(1,0,1);

glNormal3f(-1, yval, 1);

glTexCoord2f(0.0 ,0.0);

glVertex3f(-1,0,1);

glEnd();

glBegin( GL_TRIANGLES);

//another side

glNormal3f(0, 1, 0);

glTexCoord2f( leafRep/2,leafRep);

glVertex3f(0,1,0);

glNormal3f(-1, yval, -1);

glTexCoord2f(leafRep,0.0);

glVertex3f(-1,0,-1);

glNormal3f(-1,yval,1);

glTexCoord2f(0.0 ,0.0);

glVertex3f(-1,0,1);

glEnd();

I have been told that i am setting the normals incorrectly.

So i went on the internet and found a number of tutorials on Gourad Shading and how I should calculate the normals for each triangular surface and then calculate the average of the surface normals that intersect at a particular vertice to get the proper normal vector for that vertice.

But then I was told this:

This technique is only necessary if all you know is the what the triangles

are. When an object is defined ONLY in terms of the triangles, then

Gouraud requires that you calculate the normals that way.

However, when drawing a cylinder or cone or some object which is

analytically defined, you don't have to do that because you KNOW what the

normal is. Using symmetry, it is very easy to show that the answer you

get when averaging the inidividual normals is in fact the true normal.

So the bottom line is if you apply the technique you outline, you will

laboriously calculate a normal which you can determine by inspection.

I do not understand how that applies to my code because i did not use any kind of parametic equation involving sins or cosines to generate my shape.

How would i properly calculate the normals for the vertices to show a "curved effect" without going through the whole averaging the surface normals technique?

Is there even such a way? Do i have to calculate the slope from the top of my tree to one of the edge vertices and then figure something out. I am really confused :(