cloudraven

11-07-2003, 05:54 PM

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)*R*sin(v*2*PI),R*u*3,top(u)*R*cos (v*2*PI));

glVertex3f(top(u)*R*sin((v+K)*2*PI),R*u*3,top(u)*R *cos((v+K)*2*PI));

}

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)*R*sin(v*2*PI);

t1[1] = 3*R;

t1[2] = topd(u)*R*cos(v*2*PI);

t2[0] = 2*PI * R * top(u) * cos(v*2*PI);

t2[1] = 0;

t2[2] = -R*top(u)*2*PI*sin(v*2*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

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)*R*sin(v*2*PI),R*u*3,top(u)*R*cos (v*2*PI));

glVertex3f(top(u)*R*sin((v+K)*2*PI),R*u*3,top(u)*R *cos((v+K)*2*PI));

}

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)*R*sin(v*2*PI);

t1[1] = 3*R;

t1[2] = topd(u)*R*cos(v*2*PI);

t2[0] = 2*PI * R * top(u) * cos(v*2*PI);

t2[1] = 0;

t2[2] = -R*top(u)*2*PI*sin(v*2*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