Ejemplo n.º 1
0
void StrokeIntersector::intersect(osgUtil::IntersectionVisitor &iv, osg::Drawable *drawable)
{
    osg::BoundingBox bb = drawable->getBoundingBox();
    bb.xMin() -= m_offset; bb.xMax() += m_offset;
    bb.yMin() -= m_offset; bb.yMax() += m_offset;
    bb.zMin() -= m_offset; bb.zMax() += m_offset;

    osg::Vec3d s(_start), e(_end);
    if (!intersectAndClip(s, e, bb)) return;
    if (iv.getDoDummyTraversal()) return;

    entity::Stroke* geometry = dynamic_cast<entity::Stroke*>(drawable->asGeometry());
    if (geometry)
    {
        osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(geometry->getVertexArray());
        if (!vertices) return;

        for (unsigned int i=1; i<vertices->size(); ++i)
        {

            double distance = Utilities::getSkewLinesDistance(s,e,(*vertices)[i], (*vertices)[i-1]);

            if (m_offset<distance) continue;

            Intersection hit;
            hit.ratio = distance;
            hit.nodePath = iv.getNodePath();
            hit.drawable = drawable;
            hit.matrix = iv.getModelMatrix();
            hit.localIntersectionPoint = (*vertices)[i];
            m_hitIndices.push_back(i);
            insertIntersection(hit);
        }
    }
}
Ejemplo n.º 2
0
static void findIntersections(UPolygon* subject, UPolygon* clipping)
{

        PointNode* A = subject->pointList;
        while (A != NULL) {
            PointNode* B = A->next[subject->name];
            PointNode* tmp = B;
            if (B == NULL) B = subject->pointList;
            PointNode* C =  clipping->pointList;
            while (C != NULL) {
               PointNode* D = C->next[clipping->name];
                while (D != NULL && D->isIntersection(clipping->name))
                    //skip past intersections
                    D = D->next[clipping->name];
                if (D != NULL) insertIntersection(subject, clipping,A,B,C,D);
                else insertIntersection(subject,clipping,A,B,C,clipping->pointList); // loopback on clipping
                C = D;
            }
            A = tmp;
         }
}