Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » clockwise : anticlockwise - vertices

Credits go to Billybob, gnolam, Goodbytes, and Plucky for helping out!
This thread is locked; no one can reply to it. rss feed Print
clockwise : anticlockwise - vertices
Morpheous
Member #3,812
August 2003
avatar

From what I understand, when you talk about vertices, you usually talk about them as they exist when the shape is initially created. Before the vertices are transformed or whatever.

My understanding is that, if you have a face that is initially seen by the camera, you must (should?) define the vertices in anti-clockwise order (this, I'm told is pretty standard).

Does this mean that any faces that are not seen (i.e. the back faces), need their (initial) vertices defined in clockwise fashion, so that when they do face the camera, the vertices will be then be anti-clockwise?

Or maybe I'm just confused.

Also, could someone explain to me what a "concave" polygon is, please?

I understand what a "self-intersecting" polygon is (I think), but "concave" makes it sound like it's not a closed shape.

Quote:

-- From the Allegro API --
void polygon3d_f(BITMAP *bmp, int type, BITMAP *texture, int vc, V3D_f *vtx[]);

... Unlike the regular polygon() function, these routines don't support concave or self-intersecting shapes ...

Plucky
Member #1,346
May 2001
avatar

A concave polygon is a polygon where at least one of its internal angles is greater than 180 degrees. Another description: there can exist a line segment connecting two vertices that does not fully lie within the polygon; it intersects the outer boundary at one point.

A convex polygon is where all line segments between vertices are contained in the polygon.

[edit]
The "standard" order of the vertices has to do with the method used to determine whether a face is facing the camera. The algorithm is usually a dot product between the face normal and the camera direction; the resulting sign determines whether the polygon normal faces towards the camera or away. Changing Clockwise to counter clockwise will flip the sign of that dot product.

gnolam
Member #2,030
March 2002
avatar

At least in OpenGL you can specify which orientation your polygons have (using glFrontFace()). Counter-clockwise order is the standard though, both in 3d programming and in mathematics (e.g. vector analysis).

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Billybob
Member #3,136
January 2003

You do "backface culling" after transformations. The rendering pipeline will find the normal of the polygon and then cull appropriatly. You can accually turn this off, but it help proformance by 2x in some cases. As for specifying the normal, I'm guessing when it knows the normal off the bat, it'll transform that during the transfomations so it points the right way later.

Also, be careful not to confuse this normal, with the one used for lighting. As I understand, you can specify a different normal for the lighting routines.

;D

Morpheous
Member #3,812
August 2003
avatar

But do I have the right idea?

You specify the front faces anti-clockwise and the back ones clockwise?

That's basicly what I want to know.

Billybob
Member #3,136
January 2003

Sorta kinda...

Goodbytes
Member #448
June 2000
avatar

By sorta kinda, William means yes. Err, actually, maybe he means sorta kinda, because sometimes you'll get faces that face neither towards nor away from the camera... say, pointing along the x-axis or something...

It's easier if you think of it as specifying all vertices in anti-clockwise order as if the polygon in question on whatever 3D model you're constructing is facing you. Just rotate the model in your head. I'm assuming you're constructing something fairly simple like a cube, here, because otherwise you would be using a 3D modeling program and it does these things for you...


--
~Goodbytes

Morpheous
Member #3,812
August 2003
avatar

Actually, I'm working on a framework for my own modeling program.

Tobias Dammers
Member #2,604
August 2002
avatar

Quote:

From what I understand, when you talk about vertices, you usually talk about them as they exist when the shape is initially created. Before the vertices are transformed or whatever.

No. At least not in this case.
You have to think 3d. The terms "clockwise" and "counter-clockwise" make only sense in 2d. If you use them in 3d, you also have to specify some sort of axis, which brings it down to 2d. In this case, that axis is the normal vector (or rather the negative of that). "Clockwise vertex order" then means: Vertices are specified so that they are in clockwise order when viewed along the negative normal".
As a result, the vertices are also in clockwise order in screen coordinates if and only if the polygon faces the viewer. Using this effect to find out which poly's are visible is called back-face culling.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Go to: