Vertex-Winding-Order

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Vertex-Winding-Order

Post by Acki »

no, no, not another discussion on what order to use/chose !!! :lol:

I have a problem to determine how 3 vertices are connected... :oops:

the 3 vertices are placed on a xy plane...
and I have a winding order (v1-v2-v3)...

Code: Select all

// get the vertex positions
position2d v1 = getRandomXYPosition();
position2d v2 = getRandomXYPosition();
position2d v3 = getRandomXYPosition();

//  what is the winding order ???
bool cw = isOrderClockwise(v1, v2, v3);
but I have no clue how to calculate the order ??? :shock:
(maybe I'm missing something obvious :oops: )
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Brainsaw
Posts: 1183
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Post by Brainsaw »

Hmm ... not quite sure, but maybe this article could help: http://www.cgafaq.info/wiki/Simple_Polygon_Orientation
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

The widely accepted method (requiring a known normal), is to compare the dot product of the known normal, and the normal calculated by normalize((V2 - V1) x (V3 - V1)). If it is close to 0, it is counter clockwise, otherwise it is clockwise.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

ahhh, normals and dot product !?!?! :lol:
but how do you define "close to 0" ??? :shock:

well, I'll try it...

thank you both !!! :)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Irrlicht doesn't employ the use of normals to determine if the triangle is front or back facing though. You can have really messed up normals or no normals at all and it will still properly determine if the triangle is front or back facing.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

while my researches I also found that there are solutions with cross products... :roll:
but after the keyword "normals" I came up with this "easy" solution:

Code: Select all

bool isOrderClockwise(vector3df v0, vector3df v1, vector3df v2){
  v0.Z = v1.Z = v2.Z = 0.0; // I want the triangle only to be on the xy-plane
  vector3df normal = plane3df(v0, v1, v2).Normal;
  return (normal.Z < 0.0);
}
thanks again, for the hints !!! :)
cu, Acki
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

slavik262 wrote:Irrlicht doesn't employ the use of normals to determine if the triangle is front or back facing though. You can have really messed up normals or no normals at all and it will still properly determine if the triangle is front or back facing.
Of course, but the normal calculated by normalize((V2 - V1) x (V3 - V1)) will return a normal that is the opposite of the known normal if the winding is not counter clockwise.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

You can try getting the middle point and then calculating the angle around that point for a certain axis?
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
terier
Posts: 34
Joined: Sun Oct 05, 2008 4:46 pm

Post by terier »

If you want only the 2D solution then here's my solution:
- take a point (P3)
- make a line out of other points (P1 --> P2)
- determine if the point is BELOW or ABOVE the line
- below: negative orientation of the tri.
- above: positive orientation of the tri.
Post Reply