Changeset 13041 for OpenSceneGraph/trunk/src/osgUtil/IntersectVisitor.cpp
 Timestamp:
 03/21/12 18:36:20 (5 years ago)
 Files:

 1 modified
Legend:
 Unmodified
 Added
 Removed

OpenSceneGraph/trunk/src/osgUtil/IntersectVisitor.cpp
r12373 r13041 1 /* *c++* OpenSceneGraph  Copyright (C) 19982006 Robert Osfield 1 /* *c++* OpenSceneGraph  Copyright (C) 19982006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 88 88 const osg::Vec3 Hit::getWorldIntersectNormal() const 89 89 { 90 if (_inverse.valid()) 91 { 92 osg::Vec3 norm = osg::Matrix::transform3x3(*_inverse,_intersectNormal); 90 if (_inverse.valid()) 91 { 92 osg::Vec3 norm = osg::Matrix::transform3x3(*_inverse,_intersectNormal); 93 93 norm.normalize(); 94 94 return norm; … … 155 155 LineSegment* ns = new LineSegment; 156 156 157 if (_model_inverse.valid()) 157 if (_model_inverse.valid()) 158 158 { 159 159 if (_view_inverse.valid()) … … 163 163 } 164 164 else 165 { 165 { 166 166 ns>mult(*seg,*(_model_inverse)); 167 167 } … … 175 175 *ns = *seg; 176 176 } 177 177 178 178 _segList.push_back(LineSegmentPair(seg,ns)); 179 179 } … … 185 185 // override the default node visitor mode. 186 186 setTraversalMode(NodeVisitor::TRAVERSE_ACTIVE_CHILDREN); 187 187 188 188 // Initialize eyepoint to 0,0,0 189 189 setEyePoint(Vec3(0.0f,0.0f,0.0f)); … … 245 245 if (cis && (cis>_model_inverse.valid()  cis>_view_inverse.valid())) 246 246 { 247 247 248 248 osg::Vec3 eyePoint = _pseudoEyePoint; 249 249 if (cis>_view_inverse.valid()) eyePoint = eyePoint * (*(cis>_view_inverse)); 250 250 if (cis>_model_inverse.valid()) eyePoint = eyePoint * (*(cis>_model_inverse)); 251 251 252 252 //OSG_NOTICE<<"IntersectVisitor::getEyePoint()"<<eyePoint<<std::endl; 253 253 … … 263 263 { 264 264 if (!seg) return; 265 265 266 266 if (!seg>valid()) 267 267 { … … 270 270 return; 271 271 } 272 272 273 273 IntersectState* cis = _intersectStateStack.back().get(); 274 274 275 275 if (cis>_segList.size()>=32) 276 276 { … … 306 306 nis>_view_matrix = cis>_view_matrix; 307 307 nis>_view_inverse = cis>_view_inverse; 308 308 309 309 // set up new model matrix 310 310 nis>_model_matrix = matrix; … … 373 373 { 374 374 IntersectState* cis = _intersectStateStack.back().get(); 375 if (!cis>_segmentMaskStack.empty()) 375 if (!cis>_segmentMaskStack.empty()) 376 376 cis>_segmentMaskStack.push_back(cis>_segmentMaskStack.back()); 377 377 else 378 378 cis>_segmentMaskStack.push_back(0xffffffff); 379 379 380 380 return true; 381 381 } … … 407 407 _normal(normal), 408 408 _r1(r1), 409 _v1(v1), 409 _v1(v1), 410 410 _r2(r2), 411 _v2(v2), 411 _v2(v2), 412 412 _r3(r3), 413 413 _v3(v3) {} … … 416 416 const osg::Vec3 _normal; 417 417 float _r1; 418 const osg::Vec3* _v1; 418 const osg::Vec3* _v1; 419 419 float _r2; 420 const osg::Vec3* _v2; 420 const osg::Vec3* _v2; 421 421 float _r3; 422 const osg::Vec3* _v3; 422 const osg::Vec3* _v3; 423 423 424 424 protected: … … 440 440 float _ratio; 441 441 bool _hit; 442 443 442 443 444 444 445 445 typedef std::multimap<float,TriangleHit> TriangleHitList; 446 446 447 447 TriangleHitList _thl; 448 448 … … 459 459 set(seg,ratio); 460 460 } 461 461 462 462 void set(const LineSegment& seg,float ratio=FLT_MAX) 463 463 { … … 524 524 if (ds31<d231) return; 525 525 } 526 526 527 527 528 528 float r3; … … 530 530 else if (d312!=0.0f) r3 = ds12/d312; 531 531 else return; // the triangle and the line must be parallel intersection. 532 532 533 533 float r1; 534 534 if (ds23==0.0f) r1=0.0f; 535 535 else if (d123!=0.0f) r1 = ds23/d123; 536 536 else return; // the triangle and the line must be parallel intersection. 537 537 538 538 float r2; 539 539 if (ds31==0.0f) r2=0.0f; … … 550 550 r3 *= inv_total_r; 551 551 } 552 552 553 553 Vec3 in = v1*r1+v2*r2+v3*r3; 554 554 if (!in.valid()) … … 570 570 float r = d/_length; 571 571 572 572 573 573 if (treatVertexDataAsTemporary) 574 574 { … … 605 605 if (ti._hit) 606 606 { 607 607 608 608 osg::Geometry* geometry = drawable.asGeometry(); 609 609 610 610 611 611 for(TriangleIntersect::TriangleHitList::iterator thitr=ti._thl.begin(); … … 613 613 ++thitr) 614 614 { 615 615 616 616 Hit hit; 617 617 hit._nodePath = _nodePath; … … 623 623 624 624 TriangleHit& triHit = thitr>second; 625 625 626 626 hit._ratio = thitr>first; 627 627 hit._primitiveIndex = triHit._index; … … 633 633 634 634 hit._intersectNormal = triHit._normal; 635 635 636 636 if (geometry) 637 637 { … … 645 645 } 646 646 } 647 647 648 648 649 649 _segHitList[sitr>first.get()].push_back(hit); … … 670 670 intersect(*geode.getDrawable(i)); 671 671 } 672 672 673 673 leaveNode(); 674 674 } … … 747 747 setLODSelectionMode(USE_SEGMENT_START_POINT_AS_EYE_POINT_FOR_LOD_LEVEL_SELECTION); 748 748 749 if (viewport && 750 mx >= static_cast<float>(viewport>x()) && 749 if (viewport && 750 mx >= static_cast<float>(viewport>x()) && 751 751 my >= static_cast<float>(viewport>y()) && 752 752 mx < static_cast<float>(viewport>x()+viewport>width()) && … … 778 778 OSG_NOTICE<<"Warning: PickVisitor not set up correctly, picking errors likely"<<std::endl; 779 779 } 780 780 781 781 782 782 addLineSegment(lineSegment); … … 805 805 void PickVisitor::apply(osg::Projection& projection) 806 806 { 807 runNestedPickVisitor( projection, 808 _lastViewport.get(), 807 runNestedPickVisitor( projection, 808 _lastViewport.get(), 809 809 projection.getMatrix(), 810 810 _lastViewMatrix, … … 822 822 runNestedPickVisitor( camera, 823 823 camera.getViewport() ? camera.getViewport() : _lastViewport.get(), 824 _lastProjectionMatrix * camera.getProjectionMatrix(), 824 _lastProjectionMatrix * camera.getProjectionMatrix(), 825 825 _lastViewMatrix * camera.getViewMatrix(), 826 826 _mx, _my ); … … 830 830 runNestedPickVisitor( camera, 831 831 camera.getViewport() ? camera.getViewport() : _lastViewport.get(), 832 camera.getProjectionMatrix() * _lastProjectionMatrix, 832 camera.getProjectionMatrix() * _lastProjectionMatrix, 833 833 camera.getViewMatrix() * _lastViewMatrix, 834 834 _mx, _my ); … … 839 839 runNestedPickVisitor( camera, 840 840 camera.getViewport() ? camera.getViewport() : _lastViewport.get(), 841 camera.getProjectionMatrix(), 841 camera.getProjectionMatrix(), 842 842 camera.getViewMatrix(), 843 843 _mx, _my );