//--------------------------------------------------------------------------------------- void Portal::Split(Plane& plane, Portal& a, Portal& b) { a.CopyProps(*this); b.CopyProps(*this); if((_n == plane._n && _c == plane._c) || (_n == -plane._n && _c == -plane._c) ) { #ifdef WINDOWS # pragma message("see this") #endif a._vxes = _vxes; b._vxes = _vxes; return; } v3d_t iv; v3d_t itxB = *_vxes.begin(); v3d_t itxA = _vxes.back(); f32_t fB; f32_t fA = plane.DistTo(itxA); FOREACH(vvector<v3d_t>, _vxes, vxI) { itxB = *vxI; fB = plane.DistTo(itxB); if(fB > GEpsilon) { if(fA < -GEpsilon) { f32_t t = -fA /(fB - fA); iv.interpolate(itxA,itxB,t); a._vxes << iv; b._vxes << iv; } a._vxes<<itxB; } else if(fB < -GEpsilon) { if(fA > GEpsilon) { f32_t t = -fA /(fB - fA); // t of segment iv.interpolate(itxA,itxB,t); a._vxes <<iv; b._vxes <<iv; } b._vxes<<itxB; } else { a._vxes << itxB; b._vxes << itxB; } itxA = itxB; fA = fB; }
void Face::Split(Plane& plane, Face& frontFace, Face& backFace) { Vertex vertex1 = m_points.first(); Vertex vertex2 = m_points.back(); float fB; float fA = plane.DistTo(vertex2._xyz); for_each(vertex in m_poins) { vertex1 = *vertex; fB = plane.DistTo(vertex1._xyz); if(fB > EPSILON) { if(fA < -EPSILON) { float t = -fA /(fB - fA); Vertex midvertex = vertex1 + (vertex2-vertex1)*t; frontFace << midvertex; backFace << midvertex; } frontFace<<vertex1; } else if(fB < -EPSILON) { if(fA > EPSILON) { float t = -fA /(fB - fA); Vertex midvertex = vertex1 + (vertex2-vertex1)*t; frontFace<<midvertex; backFace <<midvertex; } backFace <<vertex1; } else { frontFace << vertex1; backFace << vertex1; } vertex2 = vertex1; fA = fB; }