PDA

View Full Version : NURBS + Normals = Suicide



fistfullast33l
12-14-2003, 10:46 PM
Hi all,

I'm trying to write a program that models an outdoor scene and part of the scene involves an amphitheater that I've rendered using NURBS. Now, I'm trying to use texturing and lighting on the object, but am having trouble calculating the normals for the object. There are several parts to the actual theater, so I'll include just one of the sets of control points here. I'm using a 4th order NURB to get this done.

My question is, how do I calculate the Normals? Is it just like calculating normals for Linear objects? Any help you can give is appreciated:




float restnear[4][4][3] = { 8.0, -10.0, 0.0,
8.0, -5.0, 0.0,
8.0, 5.0, -4.0,
8.0, 10.0, -6.0,
6.0, -10.0, 0.0,
6.0, -5.0, 0.0,
6.0, 5.0, -4.0,
6.0, 10.0, -6.0,
2.0, -10.0, 0.0,
2.0, -5.0, 0.0,
2.0, 5.0, -4.0,
2.0, 10.0, -6.0,
0.0, -10.0, 0.0,
0.0, -5.0, 0.0,
0.0, 5.0, -4.0,
0.0, 10.0, -6.0 };

float restnearnorm[4][4][3] = { 0.0, 0.0, -1.0,
0.0, 0.0, -1.0,
0.0, -1.0, -1.0,
0.0, -1.0, -1.0,
0.0, 0.0, -1.0,
0.0, 0.0, -1.0,
0.0, -1.0, -1.0,
0.0, -1.0, -1.0,
0.0, 0.0, -1.0,
0.0, 0.0, -1.0,
0.0, -1.0, -1.0,
0.0, -1.0, -1.0,
0.0, 0.0, -1.0,
0.0, 0.0, -1.0,
0.0, -1.0, -1.0,
0.0, -1.0, -1.0 };

gluNurbsSurface(theNurb,
8, knots, 8, knots,
4 * 3, 3, &restnear[0][0][0],
4, 4, GL_MAP2_NORMAL);
gluNurbsSurface(theNurb,
8, knots, 8, knots,
4 * 3, 3, &restnear[0][0][0],
4, 4, GL_MAP2_VERTEX_3);
gluNurbsSurface(theNurb,
8, knots, 8, knots,
4 * 3, 3, &restnear[0][0][0],
4, 4, GL_MAP2_TEXTURE_COORD_2);

gluEndSurface(theNurb);

Ffelagund
12-15-2003, 03:31 AM
Try glEnable(GL_AUTO_NORMAL);

fistfullast33l
12-15-2003, 05:45 AM
I had that enabled already. I just turned up the ambient and diffuse lighting for now. Is that a proper way to do it? Increase the light settings to compensate?

514VOID
12-15-2003, 05:52 AM
I tried to make an algorythm to get automate calculation of GL_MAP2_NORMAL control points for fun, but it made my brain hurt too much, I think you need higher level normal nurbs than the surface in question, but my calculations hypothesis might have been flawed. I didn't use knots because that would have been way tricky. I was able to calculate normals for MAP1 curves, but that was sort of pointless. But.... maybe specifying GL_MAP2_NORMAL's renders quicker than GL_AUTO_NORMAL or at least in the future. I may go back to it and work it out properly one day, it is more fun than chess.

heppe
12-17-2003, 12:46 AM
lighting that appears either too light or too dark is often the sign of normals that need normaizing. Try glEnable( GL_NORMALIZE) as a workaround.

fistfullast33l
12-17-2003, 06:32 AM
Thanks for the reply guys,

I had normalize enabled already. I just turned the ambient lighting all the way up and it started to blend a little better. That was my biggest issue. The NURBS was part of an object that included flat surfaces as well, so they didn't blend especially well.