/*! * Note that this has complexity O(n^2) but should not count since * triangulation has O(n^3). * * \param globalverts the global vertices vector * \param polylist the global list of polygons * \return zero on success, and a negative integer if some error occured. */ int SimplePolygon::fixAndTriangulate( DCTPVec2dvector &globalverts, simplepolygonvector &polylist ) { Vec2d min, max; if( getMinMax( globalverts, min, max ) ) { // std::cerr << "Ignoring degenerate polygon..." << std::endl; return -1; } // while( removeLinearPoints( globalverts, min, max ) ) { } while( splitPolygon( globalverts, polylist, min, max ) ) { } while( intersectPolygon( globalverts, polylist ) ) { } if( isReversed( globalverts ) ) { // std::cerr << "Ignoring reversed polygon." << std::endl; return 0; // no error here... } // Ok, we have a valid polygon, so triangulate it. triangulate( globalverts, polylist ); return 0; }
Intersection Mesh::intersect(Ray ray) { Intersection intersection; //DEBUG_MSG("Vxs " << m_verts.size() << " Faces: " << m_faces.size() ); // intersect ray polygon //for (SceneNode::ChildList::const_iterator it = root->children().begin(), end = root->children().end(); it != end; ++it) { for (std::vector<Face>::const_iterator it = m_faces.begin(), end = m_faces.end(); it != end; ++it) { std::vector<Point3D> polygon; Face face = *it; for (unsigned int i = 0; i < face.size(); i++) { polygon.push_back(m_verts[face[i]]); //DEBUG_MSG("\t" << face[i]); } //DEBUG_MSG(polygon.size()); Intersection pIntersect = intersectPolygon(ray, polygon); if (pIntersect.hit) { //DEBUG_MSG("HIT"); if (!intersection.hit || pIntersect.t < intersection.t ) { //DEBUG_MSG("HIT SET"); intersection = pIntersect; } } else { // Face face = *it; // polygon.clear(); // for (int i = face.size() - 1; i >= 0; i--) // { // polygon.push_back(m_verts[face[i]]); // // //DEBUG_MSG("\t" << face[i]); // } // //DEBUG_MSG(polygon.size()); // // Intersection pIntersect = intersectPolygon(ray, polygon); // // if (pIntersect.hit) // { // //DEBUG_MSG("HIT"); // if (!intersection.hit || pIntersect.t < intersection.t ) // { // // //DEBUG_MSG("HIT SET"); // intersection = pIntersect; // } // } } } return intersection; }