// returns 0 if plane intersects edge, // -1 if edge is on negative side of plane normal, // 1 if edge is on positive side of plane normal int Bedge::which_side(CWplane& plane) const { Wpt p = plane.origin(); Wvec n = plane.normal(); double dot1 = (p - _v1->loc()) * n; double dot2 = (p - _v2->loc()) * n; return dot1*dot2 < 1e-20 ? 0 : Sign(dot1); }
///////////////////////////////////// // slice_mesh_with_plane() ///////////////////////////////////// void HatchingGroupFixed::slice_mesh_with_plane( Bface *f, CWplane &wpPlane, Wpt_list &wlList) { Bface *nxtFace1, *nxtFace2; Bedge *nxtEdge1, *nxtEdge2; assert(f->front_facing()); nxtFace1 = f->plane_walk(nullptr,wpPlane,nxtEdge1); assert(nxtEdge1); nxtFace2 = f->plane_walk(nxtEdge1,wpPlane,nxtEdge2); assert(nxtEdge2); Wpt_list wlList1; Wpt_list wlList2; wlList1.push_back(wpPlane.intersect(nxtEdge1->line())); wlList2.push_back(wpPlane.intersect(nxtEdge2->line())); //So theres at least 2 pts in the final list... //sky box fix prevents infinite loops for sky box type geometry //where the camera is contained inside the object //points are checked against view volume while (nxtFace1 && nxtFace1->front_facing()) { nxtFace1 = nxtFace1->plane_walk(nxtEdge1,wpPlane,nxtEdge1); if (nxtEdge1) { Wpt temp_pt = wpPlane.intersect(nxtEdge1->line()); //sky box fix if (!temp_pt.in_frustum()) { break; } wlList1.push_back(temp_pt); } else { cerr << "Slice Mesh :: assert(!nxtFace1)" << endl; assert(!nxtFace1); } } while (nxtFace2 && nxtFace2->front_facing()) { nxtFace2 = nxtFace2->plane_walk(nxtEdge2,wpPlane,nxtEdge2); if (nxtEdge2) { Wpt temp_pt =wpPlane.intersect(nxtEdge2->line()); //sky box fix if (!temp_pt.in_frustum()) { break; } wlList2.push_back(temp_pt); } else { cerr << "Slice Mesh :: assert(!nxtFace2)" << endl; assert(!nxtFace2); } } wlList.insert(wlList.end(), wlList1.rbegin(), wlList1.rend()); wlList.insert(wlList.end(), wlList2.begin(), wlList2.end()); }
///////////////////////////////////// // slice_mesh_with_plane() ///////////////////////////////////// void HatchingGroupFixed::slice_mesh_with_plane( Bface *f, CWplane &wpPlane, Wpt_list &wlList) { Bface *nxtFace1, *nxtFace2; Bedge *nxtEdge1, *nxtEdge2; assert(f->front_facing()); nxtFace1 = f->plane_walk(0,wpPlane,nxtEdge1); assert(nxtEdge1); nxtFace2 = f->plane_walk(nxtEdge1,wpPlane,nxtEdge2); assert(nxtEdge2); Wpt_list wlList1; Wpt_list wlList2; wlList1 += wpPlane.intersect(nxtEdge1->line()); wlList2 += wpPlane.intersect(nxtEdge2->line()); //So theres at least 2 pts in the final list... //sky box fix prevents infinite loops for sky box type geometry //where the camera is contained inside the object //points are checked against view volume while (nxtFace1 && (nxtFace1->front_facing())) { nxtFace1 = nxtFace1->plane_walk(nxtEdge1,wpPlane,nxtEdge1); if (nxtEdge1) { Wpt temp_pt = wpPlane.intersect(nxtEdge1->line()); //sky box fix if (!temp_pt.in_frustum()) { break; } wlList1 += temp_pt; } else { cerr << "Slice Mesh :: assert(!nxtFace1)" << endl; assert(!nxtFace1); } } while (nxtFace2 && (nxtFace2->front_facing())) { nxtFace2 = nxtFace2->plane_walk(nxtEdge2,wpPlane,nxtEdge2); if (nxtEdge2) { Wpt temp_pt =wpPlane.intersect(nxtEdge2->line()); //sky box fix if (!temp_pt.in_frustum()) { break; } wlList2 += temp_pt; } else { cerr << "Slice Mesh :: assert(!nxtFace2)" << endl; assert(!nxtFace2); } } int k; for (k = wlList1.num()-1; k >= 0; k--) { wlList += wlList1[k]; } //wlList += wIsect; for (k=0; k < wlList2.num(); k++) { wlList += wlList2[k]; } }