3ds and face cw/ccw

Started by
3 comments, last by Caesar 16 years, 11 months ago
hi how do I learn whether the vertices in a face in a 3ds file are in CW or CCW order? I know there's a faceflag for each flag, but don't think that's what I'm looking for (I enable back face culling to see whether the object is CW or CCW, but they all have the flag set to 7 (decimal). Any idea where to look? (I'm looking at lib3ds now, but haven't found it yet)
Advertisement
Unless you specifically tell 3DS to reverse the facing of a tile (flip the normal)then they will all be the same direction, and so for the entire mesh you can decide if you need to cull the back or front (usually the back). Lib3ds will load them in the same way they are saved out from 3DS, so it will preserve the direction too.

If needs be, then there is a way of telling if a triangle is cw or ccw. Something to do with computing the area of the triangle I think, but I can't remember off hand.
------------------------------------------[New Delta Games] | [Sliders]
Quote:Original post by Damocles
If needs be, then there is a way of telling if a triangle is cw or ccw. Something to do with computing the area of the triangle I think, but I can't remember off hand.

This is from the top of my head:
// A, B, C are the three triangle vertex positions in 3D space// N is the (normalized) face normal// If s < 0 then CCW, if s > 0 then CW (or the other way round, depends on your coordsys// If s == 0 then the face is degeneratedfloat s = dot(N, cross(A, B) + cross(B, C) + cross(C, A));

Oh, I see. The problem is I'm loading files I've downloaded from the internet and some have the vertex order messed up (CW instead of CCW) (I compute the normals myself instead of loading them). Also, I believe that while you can tell whether the face is CW or CCW, it depends on the actual point of view and thereby you'd need to know whether a certain tri should be facing you or not when you're standing at some specific point in space. Or did I get it totally wrong?
Only now that I read Yann L's post I get it. I need to compare the loaded normal with the one I compute and see if they're the same or not and depending on that, rearrange the vertices to go CW/CCW (the way I want them)

thanks guys

This topic is closed to new replies.

Advertisement