OpenPolyhedra  1.0
Open Polyhedra - set texture coordinates to polyhedra.

This program sets texture coordinates to vertices of the Platonic solids (perfect polyhedra): tetrahedron, octahedron, hexahedron (cube), icosahedron and dodecahedron. Platonic Solids

# Main Steps:

• A face of the polyhedron must be selected with the mouse, so all the other faces become coplanar with the selected face.
1. Then, it is just a question of mapping the open (flattened) polyhedron onto the texture plane (z=0).
• The faces can be traversed in any order, without repetition.
1. Modeling polyhedra as graphs, one can use any traversal algorithm, e.g., breadth or depth first.
• The mapping corresponds to a change of basis: uvn -> xy(z=0), where n is the normal vector of the selected face, and u and v, two vectors on the face plane (pag. 109).
• To select (pick) a face, shoot a ray from the mouse position, and intersect it against the faces of the polyhedron:
1. Sort the intersections along the ray (parametrically described).
2. The one closer to the origin of the ray is from the selected face.
3. If the polyhedra are convex, there can be only two intersections.
4. The ray has coordinates (x,y,0) and (x,y,1).
5. Use gluUnProject to bring the ray back to world coordinates.
6. It is necessary an algorithm of point in polygon testing (an implementation using winding number is simpler, but one using the even-odd rule is more robust).
• Each polygon must contain the transformation with all rotations accumulated, along the path from the selected face, until reaching it.
1. Remember that the fixed point of a linear transformation is the origin.
2. Therefore, choose the edge that will work as a rotation axis, and translate one of its two vertices, to the origin.
3. Then, apply the rotation and translate it back.
• The transformation of the selected (initial) face is the identity.
• The fifth element, dodecahedron, is not Mila Jovovich.

Take a look at drawTexture() for further theoretical reasoning...