I wasnt sure of posting this here, since it is a very basic question, but it is math related so I guess it would be better to post it here.
I have to finish an OpenGL project for college, and my deadline is tomorrow at midnight, I have tried everything and can’t find the solution.
I have to display a surface of revolution and add some lights (the surface of revolution happens to be a windmill), my classmates chose other objects such as hands or simple robots that were easier to light, so they couldn’t help me.
My problem is about calculating the normal vectors of the surface.
The surface is drawn as follows
for(v=0;v<=1;v+=K)
{
glBegin(GL_QUAD_STRIP);
for(u=0;u<=sqrh;u+=K)
{
glVertex3f(top(u)Rsin(v2PI),Ru3,top(u)Rcos(v2PI));
glVertex3f(top(u)Rsin((v+K)2PI),Ru3,top(u)Rcos((v+K)2PI));
}
glEnd();
}
GLfloat top(GLfloat u)
{
return (float)height - (u*u);
}
The teacher told me to calculate the normals by using the vector product of the partial derivatives of the ecuation.
I wrote this
GLfloat t1[3],t2[3];
t1[0] = topd(u)Rsin(v2PI);
t1[1] = 3R;
t1[2] = topd(u)Rcos(v2*PI);
t2[0] = 2PI * R * top(u) * cos(v2PI);
t2[1] = 0;
t2[2] = -Rtop(u)2PIsin(v2*PI);
VectorProduct(normal,t2,t1);
Normalize(normal);
Where topd() is
GLfloat inline topd(GLfloat u)
{
return (float)-(2*u);
}
When i render it, almost the 90% of the object is completely white, and just a very small zone is shaded.
The teacher says that there is something wrong with the normal vectors, but I am completely clueless now.
Any help woulde be really appreciated