If I have a polygon that bends, how should I specify the normal vector? If I understand correctly, normals are needed for light to reflect off of it.
Thanks.
If I have a polygon that bends, how should I specify the normal vector? If I understand correctly, normals are needed for light to reflect off of it.
Thanks.
If you have a polygon that bends then you’ve either got some |33t hardware thats above consumer level, or you’re going to have to tessalate it into flat surfaces.
To find the normal for a flat surface, you can take the cross product of two vectors that lie on the the surface. To calculate vertex normals you probably want to avarage the normals for all the surrounding faces.
To find out how normals are used in plain old GL lighting, google for the blinn light model.
Well, for example, here’s the polygon I want to create a normal of:
gl.begin(GL.POLYGON);
gl.vertex3f(-20.0f, 40.0f, 0.0f);
gl.vertex3f(-60.0f, 30.0f, -20.0f);
gl.vertex3f(0.0f, 40.0f, -70.0f);
gl.vertex3f(60.0f, 30.0f, -20.0f);
gl.vertex3f(20.0f, 40.0f, 0.0f);
gl.end();
Also, how do I do it for strips or fans?
And my graphics card is an S3 Savage IX/MX with 8MB. 
Thanks.
[quote]Well, for example, here’s the polygon I want to create a normal of:
[/quote]
Without waving my hands around trying to visualize those vertices ;), I’ll take a guess that the points don’t lie in any common plane - this is generally a bad thing! Non-simple/self-intersecting polygons, non-convex polygons and polygons with holes in are not guaranteed to be rendered correctly. If the points of a polygon don’t exist all on a single plane, it’s quite easy for that polygon to be self-intersecting after viewing or modelling transformations.
Either break that polygon into smaller polygons, or (better) draw the surface as a triangle strip.
[quote]And my graphics card is an S3 Savage IX/MX with 8MB. 
[/quote]
Same here! ;D Sucks, don’t it? :
How do I do normals for strips?
Oh, and as for creating normals:
Normals are specified on a per-vertex basis, so the multiple faces of a single triangle strip/fan don’t necessarily have the same normal, thus there’s no concept of a single normal for that strip/fan.
For most (flat) faces the normal vector will be the same for all vertices defining that face, so you just set it before the first vertex. OpenGL (being a state machine) will keep that normal set for the subsequent vertices.
Does that make sense? ???
That does make sense. But for a strip, what if they’re not on the same plane? Several vertices will be on multiple triangles. Which triangle should I assign each one to? Or should I take an average? Or the cross product of a line from each triangle?
Correct, when you’re sharing vertices between faces you need to share the normal vector as well. As Orangy said, you’ll need to calculate the normals for the surrounding faces and average them. This makes the model look a lot “rounder”, so if you’re after a boxy appearance with sharp specular highlights, lit triangle strips may not be for you.
…and you want to avoid GL.POLYGON for exactly the reasons llisted above. No hardware ever actually renders polygons like that, it is always converted into triangles first. This means that it can be triangulated in a way you don’t expect, and is dependant on drivers. If you specify the triangles yourself, you’ll save yourself a lot of headache.
Thanks guys. This also partially fixed my culling problem.