PDA

View Full Version : Friends, Romans, Countrymen .............



Mark
12-06-2000, 07:13 AM
I've got geometry defined by triangles. The problem is, not all the normals point in
the same direction. Is there a routine to quickly check that all normals are pointing
in the same direction ??
It is probably a case of checking all triangles vertices are defined counterclockwise, but how do I do that ?

Thanks in advance Guys !!

Glossifah
12-06-2000, 07:41 AM
There is no GL function which will do this. Defining polygon winding only allows the culling routine to know which is the back face (or front face as the case may be). GL is unaware AFAIK of the relationship between polygon winding and normal vector direction (thus we define and clamp our own normals).

If you were to implement this, it would be your own algorithm. I can't think of a link off hand to offer, as that I've never seen an algorithm to test for normals direction.

The easiest way, would be specify each vertex normal's direction based on the vertex position, like so:

glNormal3f(v.x,(v.y + (float)1.0), v.z);
glVertex3f(v.x, v.y, v.z);

Which would give you normals that were "up" along the Y axis or every vertex. Of course, this doesn't address your question of how to test for it, merely how to implement it.

:\

Glossifah

john
12-06-2000, 01:57 PM
Hey,

use the cross product to compute a normal of two vectors. Ie, if if you have vectors <x1 y1 z1> and <x2 y2 z2> you want the solution

| i j k |
| x1 y1 z1 | = 0
| x2 y2 z2 |

(ie. you'll get a parametric solution something like i(constant) + j (constant) + k (constant) = 0)

hmm. not necessarily = 0. I just made that up. eh.

=)

cross product.

cheers
John

Baby I could be your superstar / And take too many drugs -- Regurgitator

Mark
12-07-2000, 01:25 AM
Guys

Thanks for that, but it don't really answer my main problem !!
How the hell can I make sure all triangles vertices are defined in the
SAME direction ????

This is really screwing with my brain so PLEASE someone help me before
I do something drastic ..................

Kilam Malik
12-07-2000, 04:13 AM
Ok, just to understand you right: You have a bunch of triangles and want them all to be oriented in the same way. It's no problem, if you get the points of the triangles always in the same order (clockwise or counterclockwise). Then you can use the approach above.
Otherwise, you maybe want to import some kind of solid object, where each edge of a triangle touches an edge of an other triangle and so on. Then you have to load triangle by triangle and test for each if it touches an existing triangle. Then you have to fit the orientation to the existing triangle. But what can happen is, that the whole object is now inside out, as this depends on the first triangle you read in. The solutions is, to do a ray intersection test (after reading in all triangles) to look, where inside and where outside is. Shoot a ray from one triangle outwards (direction of the normal vector). Count, how many triangles you hit. With an odd number, the orientation of all triangles has to be reversed (the vector has pointed to the inside). Even number means ok.

This only works, if you have got a closed object!

Kilam.


[This message has been edited by Kilam Malik (edited 12-07-2000).]

Deiussum
12-07-2000, 04:18 AM
Where are you getting your vertex data from? And how are you getting your normals? I know this probably isn't the answer you want but about the only way to make sure your vertices are in the right order is to make sure you specify them in the right order.

Also, are you using triangle strips? If you are and you're calculating the normals yourself, you should be aware that the resulting triangles from a strip v1,v2,v3,v4,v5, v6 is actually (v1,v2,v3) v3,v2,v4), (v3, v4, v5), (v5, v4, v6) NOT (v1, v2, v3), (v2, v3, v4), (v3, v4, v5), (v4, v5, v6)