• What is your GameDev Story?

Archived

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

Polygon splitting and vertex ordering

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

Recommended Posts

Hey! I know this would perhaps fit better in "graphics programming and theory", but i would like as much people to see this as possible So anyways, my problem is quite uncommon i believe, because i haven't found a single article about HOW to split polygons. Thats why i ended up making my own algo for it... The function prototype goes like this: bool CPolygon::Split(CPlane& Plane, CPolygon*& pFrontPoly, CPolygon*& pBackPoly) So as you can see, the polygons are split, by a plane crossing them, into two polygons (one on each side of the plane), the polygons are returned using pointer references (so i can actually modify what the pointers provided to the function are pointing to). One very important particularity is that these polygons arent necessarily triangles, they are n-gons (3 or more sides, mostly quads). I have evaluated that since the polygons are convex, only two edges can cross the plane, resulting in the fact that the front polygon, for example, has the same amout of vertexes as the number of vertexes of the main polygon (being splitted) that are on the front side plus two, because the front and the back poly both have two common vertexes that are touching the splitting plane. So my big problem is that, in my algo, i need to reorder the front and back polys so they have the same normal as the main polys, keep in mind that this isnt as easy as it seems since they can have any number of sides. I dont know how to do this (i tried a couple methods, searched the web, cant find). My algo goes like this: - Store the vertexes that are on each side of the plane in two stl-like vectors. - If either of those vectors are empty, return false, because that means the poly has all its vertexes on the same side of the plane and therefore cannot be splitted. - Find out which edges of the polygon being splitted are crossing the plane, calculate the position of the two vertexes that will touch the plane and the texcoords from that - Reorder the front and back vertexes + texcoords so that each polygon has the same normal as the polygon being splitted - Create two new polygon objects and store their memory address in the two pointers passed to this function - Copy the vertexes and texcoords from the stl like vectors to the front and back polygons we just created - Store generic properties in the two polygons (color, material, texture) - Success, return true This is not an easy problem But i need it done, because i can't really build a proper octree if i dont split the polygons, it just gets too nasty on many aspects. Apart from this ordering problem, things seem to be going good, some polys are actually properly ordered (random order) and the texcoords are fine.

Looking for a serious game project?
www.xgameproject.com [edited by - Max_Payne on January 31, 2003 11:51:14 AM]

Share on other sites
Check out this paper written by Stefan Hajnoczi. It has a section daling with sorting vrticies, as well as splitting poly''s. PLus much more.

Here''s the paper: MAPFiles.pdf

-Zims

Share on other sites
Thanks alot, read it, tried it, it works

Looking for a serious game project?
www.xgameproject.com

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 13
• 9
• 9
• 15
• Forum Statistics

• Total Topics
634076
• Total Posts
3015353
×