Advertisement

Problem with normals

Started by May 25, 2002 07:54 AM
0 comments, last by Serguai 22 years, 9 months ago
Hello, I''m currently working on opengl and learning the making of surfaces of revolutions. I made the revolution surface with no problem but i''ve problems to define the normal for each polygon that makes the surface. I just made a vectorial product to get the coordinates of the normals but the result is not what i expected. I also tried with or without glEnable(GL_NORMALIZE) in the initGL Function but it didn''t change anything. Here is the source code. Thx for helping void Faire_Mi_Thorax(){ float i,x1,y1,z1,x2,z2,x3,y3,z3,x4,z4; int j; Ma_Mi_Thorax = glGenLists(1); glNewList(Ma_Mi_Thorax, GL_COMPILE); glPushMatrix(); glBegin(GL_QUADS); for (j=0;j<10;j++) for (i=0;i<2*PI;i+=2*PI/20.0) { //Coordinates for each polygon. //The equation of the plot used for the surface is y=7-7x²/25 (parabol) //The rotation is made around the Y Axis x1=cos(i)*j; y1=(-7*j*j/25+7); z1=-j*sin(i); x2=cos(i+2*PI/20.0)*j; //y2=y1 z2=-j*sin(i+2*PI/20.0); x3=cos(i)*(j+1); y3=(-7*(j+1)*(j+1)/25+7); z3=-(j+1)*sin(i); x4=cos(i+2*PI/20.0)*(j+1); //y4=y3 z4=-(j+1)*sin(i+2*PI/20.0); //Coordinate for the normal vector glNormal3f(-(z3-z4)*(y1-y3), (z3-z4)*(x2-x4)-(x3-x4)*(z2-z4), (x3-x4)*(y1-y3)); glVertex3f(x1,y1,z1); glVertex3f(x3,y3,z3); glVertex3f(x4,y3,z4); glVertex3f(x2,y1,z2); } glEnd(); glPopMatrix(); glEndList(); }
Oops, i just found the error (i was taking one of the vectors the wrong side)

glNormal3f(-(z4-z3)*(y1-y3), (z4-z3)*(x2-x4)-(x4-x3)*(z2-z4),
(x4-x3)*(y1-y3));

Eh eh it works better like this

This topic is closed to new replies.

Advertisement