/** * @brief * Clips the polygon against a plane */ Polygon Polygon::Clip(const Plane &cPlane) const { uint32 nNumOfVertices = m_lstVertices.GetNumOfElements(); Polygon cClipped; // Loop through all vertices of this polygon for (uint32 i=0; i<nNumOfVertices; i++) { // The 2 vertices of an edge const Vector3 &vA = m_lstVertices[i]; const Vector3 &vB = m_lstVertices[(i+1) % nNumOfVertices]; // Check on which side of the plane the vertices are on Plane::ESide nSideA = cPlane.GetSide(vA); Plane::ESide nSideB = cPlane.GetSide(vB); // Clip if (nSideA == Plane::InFront || nSideA == Plane::Coinciding) { cClipped.AddVertex(vA); if (nSideB == Plane::Behind) cClipped.AddVertex(cPlane.ClipEdge(vA, vB)); } else if (nSideB == Plane::InFront) { cClipped.AddVertex(cPlane.ClipEdge(vA, vB)); cClipped.AddVertex(vB); } } // Return the clipped polygon return cClipped; }