PDA

View Full Version : normal to a line



mithun_daa
12-04-2003, 08:33 AM
im sorry for askin such a silly question, but iv forgotten all my basics.

does a line have a normal?

cause whatz happening is that when i have my lights set up, everythin is fine except that the lines turn darker at times.

Bob
12-04-2003, 09:17 AM
If lighting is enabled, the primary color of a vertex is calculated from the lighting equation. So if lighting is enables when you draw your line, the lines vertices will be lit just like any other vertex, using the current normal. If this means you have to provide a normal for the lighting equation to give the result you expect, then you have to give it a normal.

mithun_daa
12-04-2003, 09:40 AM
Originally posted by Bob:
If lighting is enabled, the primary color of a vertex is calculated from the lighting equation. So if lighting is enables when you draw your line, the lines vertices will be lit just like any other vertex, using the current normal. If this means you have to provide a normal for the lighting equation to give the result you expect, then you have to give it a normal.
but what is the normal of a line?

maximian
12-04-2003, 09:43 AM
As far as I know if you draw geometry using something like glBegin(GL_LINES), or other line modes, than you will not be able to get correct lighting, ie the kind of color variations you get as you move the mesh around with lighting enabled.

I would suggest you instead draw using regular polygos, quads, tris, etc.. And then set glPolygonMode to GL_LINE, which will give you correct lighting.
http://pyopengl.sourceforge.net/documentation/manual/glPolygonMode.3G.html

Bob
12-04-2003, 10:21 AM
Originally posted by mithun_daa:
but what is the normal of a line?
That depends on how you want the vertices to be lit. In 3 dimensions, a line does not have a normal in the same way as a surface. A surface have a unique normal that is perpendicular to the surface, but there are infinitely many normals that are perpendicular to the line, and each normal will give you a different result. So which normal you want depends on what result you want.

[This message has been edited by Bob (edited 12-04-2003).]

zeckensack
12-04-2003, 10:37 AM
You can just disable GL lighting for line rendering.

If you leave lighting turned on, the GL will use the current normal, ie if you stop supplying normals for vertices, the last one you did supply will be used for everything from there on.

There is no such thing as the "correct" normal for a line (maybe in 2D space, but hey ...). But you may get satisfactory results with distance attenuation only (it doesn't require normals).

dvm
12-04-2003, 06:08 PM
Based on a previous answer, on using polys, quads, etc you could draw a polygon and use glEdgeFlag so when the polygon mode is set for lines some of them won't show up

Volt9000
12-04-2003, 08:48 PM
Originally posted by mithun_daa:

Originally posted by Bob:
If lighting is enabled, the primary color of a vertex is calculated from the lighting equation. So if lighting is enables when you draw your line, the lines vertices will be lit just like any other vertex, using the current normal. If this means you have to provide a normal for the lighting equation to give the result you expect, then you have to give it a normal.
but what is the normal of a line?

Well, speaking stricly mathematically, a line doesn't have a normal. Or, if you wanna look at it another way, a line has an infinte number of normals.

A normal is defined as a vector which is perpendicular to the point it's being projected from. In 3D space, you can have a vector "spinning around" a line at any angle, therefore an infinite number of normals. In 2D space, however, a line has two normals; both parallel to each other and perpendicular to the line.