| 130 | | |
|---|
| 131 | | #if 0 |
|---|
| 132 | | for(KdLeafList::iterator itr = _kdLeaves.begin(); |
|---|
| 133 | | itr != _kdLeaves.end(); |
|---|
| 134 | | ++itr) |
|---|
| 135 | | { |
|---|
| 136 | | KdLeaf& leaf = *itr; |
|---|
| 137 | | leaf.bb.init(); |
|---|
| 138 | | int iend = leaf.first+leaf.second; |
|---|
| 139 | | for(int i=leaf.first; i<iend; ++i) |
|---|
| 140 | | { |
|---|
| 141 | | const Triangle& tri = _triangles[_primitiveIndices[i]]; |
|---|
| 142 | | const osg::Vec3& v1 = (*_vertices)[tri._p1]; |
|---|
| 143 | | const osg::Vec3& v2 = (*_vertices)[tri._p2]; |
|---|
| 144 | | const osg::Vec3& v3 = (*_vertices)[tri._p3]; |
|---|
| 145 | | leaf.bb.expandBy(v1); |
|---|
| 146 | | leaf.bb.expandBy(v2); |
|---|
| 147 | | leaf.bb.expandBy(v3); |
|---|
| 148 | | } |
|---|
| 149 | | // osg::notify(osg::NOTICE)<<"leaf.bb.min("<<leaf.bb._min<<") max("<<leaf.bb._max<<")"<<std::endl; |
|---|
| 150 | | |
|---|
| 151 | | } |
|---|
| 152 | | #endif |
|---|
| 632 | | //osg::notify(osg::NOTICE)<<"KdTree::intersect("<<start<<","<<end<<")"<<std::endl; |
|---|
| 633 | | bool intersects = false; |
|---|
| 634 | | |
|---|
| 635 | | int option = 2; |
|---|
| 636 | | switch(option) |
|---|
| 637 | | { |
|---|
| 638 | | case(0): |
|---|
| 639 | | { |
|---|
| 640 | | for(KdLeafList::const_iterator itr = _kdLeaves.begin(); |
|---|
| 641 | | itr != _kdLeaves.end(); |
|---|
| 642 | | ++itr) |
|---|
| 643 | | { |
|---|
| 644 | | if (intersect(*itr, start, end, intersections)) intersects = true; |
|---|
| 645 | | } |
|---|
| 646 | | break; |
|---|
| 647 | | } |
|---|
| 648 | | |
|---|
| 649 | | case(1): |
|---|
| 650 | | { |
|---|
| 651 | | for(KdLeafList::const_iterator itr = _kdLeaves.begin(); |
|---|
| 652 | | itr != _kdLeaves.end(); |
|---|
| 653 | | ++itr) |
|---|
| 654 | | { |
|---|
| 655 | | osg::Vec3 s(start), e(end); |
|---|
| 656 | | if (intersectAndClip(s,e,itr->bb)) |
|---|
| 657 | | { |
|---|
| 658 | | if (intersect(*itr, start, end, intersections)) intersects = true; |
|---|
| 659 | | } |
|---|
| 660 | | } |
|---|
| 661 | | break; |
|---|
| 662 | | } |
|---|
| 663 | | |
|---|
| 664 | | case(2): |
|---|
| 665 | | { |
|---|
| 666 | | //osg::notify(osg::NOTICE)<<"_kdNodes.size()="<<_kdNodes.size()<<std::endl; |
|---|
| 667 | | osg::Vec3 s(start), e(end); |
|---|
| 668 | | if (intersect(getNode(0), start, end, s,e, intersections)) intersects = true; |
|---|
| 669 | | break; |
|---|
| 670 | | } |
|---|
| 671 | | } |
|---|
| 672 | | |
|---|
| 673 | | return intersects; |
|---|
| | 610 | osg::Vec3 s(start), e(end); |
|---|
| | 611 | return intersect(getNode(0), start, end, s,e, intersections); |
|---|