Sign in to follow this  
Etnu

[Cross post because this didn't seem to get any response in the math forum] - CSG

Recommended Posts

Ok, I'm a bit dumbfounded here. I've got 2 brushes, "A" and "B", each containing a series of convex polygons. If I want to subtract brush "A" from brush "B", what's the best way to calculate the new triangles to be rendered? I was looking through the unreal editor to see how the intersections worked. It seems as if they're never actually modifying the brushes, but rather just storing the information for the brush, and then calculating the triangles to be rendered each time you do a new subtract / add. I was thinking something like this:

struct Polygon
{
    Vert* Verts;
    int   NumVerts;
};

struct Brush
{
  Polygon* Polys;
  int      NumPolys;
};
void SubtractBrush(Brush* pBrush, Brush* pBrush2,Vert* pVerts);
{
    int iFilled = 0;
    for(int i = 0; i < pBrush->NumPolys; i++)
    {
        Polygon* poly = &pBrush.Polys[i];
        for(int iVerts = 0; i Verts < poly->NumVerts; iVerts++)
            if(!PointIsInBrush(poly->Verts[iVerts],pBrush2)
                Verts[iFilled++] = poly->Verts[iVerts];
    }
}
That would effectively create the 'new' brush, though of course I'm not 100% sure how to calculate the right order to render these vertices in to. Well, not exactly. I suppose i'd need to also create vertices at the point of intersection along the edges when they crossed into the subtractive brush, too. That further complicates things, but i'd be happy just knowing I had the correct vertices, much less having the correct triangles.

Share this post


Link to post
Share on other sites
right, that was my second addendum...polys that intersect one another, as new vertices would need to be created.

I'm reading through this paper, though, it seems to be about what I'm looking for. Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this