Jump to content
• Advertisement

#### Archived

This topic is now archived and is closed to further replies.

# correct winding for a polygon

This topic is 5616 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

I''ve looked through these pages trying to find the information I need, but have only found other related things I already knew, but I apologize if this is a repeatedly asked question. Given a set of three points and a desired orientation, is there an algorithm that can order these points so that when drawn in that order, the corresponding polygon would have the correct winding? I understand that you want them to be counter-clockwise by default, and that by hand it is easy to see which way is counter-clockwise for a variety of polygons, but I''m dealing with over a thousand polygons so it''s not feasable to check each one, I''m writing a program to calculate all of this, and everything looks great until I start lighting (normals are not properly calculated I''m assuming, along with the order I''m declaring the points). Any assistance would be appreciated. Elijah

#### Share this post

##### Share on other sites
Advertisement
yes, there is a simple algorithm to see what order they are in. you would probably not want to change their order every frame, but rather do it once in initialization. this code is from The Black Art of 3D Game Programming.

  	if((x1==x2 && x2==x3) || (y1==y2 && y2==y3))		return;	//sort vertices	if(y2<y1)	{ //little swapping trick		x1^=x2^=x1^=x2;		y1^=y2^=y1^=y2;	}	if(y3<y1)	{		x1^=x3^=x1^=x3;		y1^=y3^=y1^=y3;	}	if(y3<y2)	{		x2^=x3^=x2^=x3;		y2^=y3^=y2^=y3;	}	if(y3<0 || y1>200 || (x1<0 && x2<0 && x3<0) ||		(x1>320 && x2>320 && x3>320))		return;

the x^x1^... craziness is just a bitwise swap technique I added.

My Homepage

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5
gaxio
12
• Advertisement

• 14
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631724
• Total Posts
3001897
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!