Polygon generator

Started by
3 comments, last by I CAN DO 14 years, 12 months ago
If I have 3 vertices of a 3D Object and need to generate a polygon face in the direction of clockwise (or not), how should I choose if I need the normal vector of the triangle is generated in the same direction as the vector P (0, 0.0)-Q (cx, cy, cz) where cx, cy, cz is the center of the triangle?
Advertisement
I hope I understood you correct, you want to check if a triangle is clockwise or not from relative to the vector from 0|0|0 to the center of your triangle, right?

you just need to make a dot product of the triangle normal and the vector and check the sign of the result, that will indicate which direction the normal points to and so if it is CCW or CW.
¡Yes, Krypt0n! Thank you! Now, another question. There would be another way to choose the correct normal vector given three points of the triangle without the need for a dot? The object is very irregular and not all faces have the same direction with respect to the origin of coordinates.
all edge of connected triangle should point to the opposide direction of their neighbour's edges, then you will get the same orientation for all normals.


if you have a mesh with indices
0 1 2
1 0 3

then vertex 0 and vertex 1 are shadered and the order of them is inverted, this means, the edges point in opposide directions and the normals will 'correct' in relation to eachother.

I hope that's what you've been looking for.
Thanks, I was very helpful. Have a reference page or source code to implement this correction algorithm?

This topic is closed to new replies.

Advertisement