Skip to content

evanw/polyfrag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This library contains a stable algorithm for splitting a convex polyhedron into two pieces on either side of a 3D plane. It is useful for generating polyhedron fragments to make a polyhedron look like it's breaking apart.

Example usage:

srand(1);
std::vector<Polyhedron *> polyhedra;
Polyhedron::recursiveSlice(Polyhedron::box(Vector3D(-0.5, -2, -0.5), Vector3D(0.5, 2, 0.5)), polyhedra, 4);

for (int i = 0; i < polyhedra.size(); i++)
{
    Vector3D offset = polyhedra[i]->getCentroid() * 0.5;
    glPushMatrix();
    glTranslatef(offset.x, offset.y, offset.z);
    polyhedra[i]->draw();
    glPopMatrix();
    delete polyhedra[i];
}

The generated mesh for a polyhedron uses a shared set of vertices which each polygon indexes into. All polygons are generated in counterclockwise order.

About

Geometry library that splits polyhedra using 3D planes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages