![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /****************************************************************************** 00002 ** Copyright (c) 2012 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 ******************************************************************************/ 00005 00009 00010 #pragma once 00011 00012 #include <vrvOsg/vrvOsg.h> 00013 #include <vrvOsg/DtOsgNodeTraversalFlags.h> 00014 #include <vrvCore/DtIntersector.h> 00015 #include <vrvCore/DtDe.h> 00016 #include <vrvOsg/DtOsgRenderer.h> 00017 #include <vrvOsg/DtOsgIntersector.h> 00018 #include <osgUtil/IntersectVisitor> 00019 00020 #include <osg/Node> 00021 #include <osgUtil/LineSegmentIntersector> 00022 00023 namespace osgUtil 00024 { 00025 class Hit; 00026 } 00027 00028 namespace osgViewer 00029 { 00030 class View; 00031 } 00032 00033 namespace makVrv 00034 { 00035 class DtOsgRenderer; 00036 00041 class DT_DLL_VRVOSG DtOsgIntersectorResult : public DtIntersectorResult 00042 { 00043 public: 00044 DtOsgIntersectorResult(); 00045 00046 DtOsgIntersectorResult( double x, double y, double z, double normalX, 00047 double normalY, double normalZ, const DtUniqueID& id, 00048 std::vector<osg::Vec3> triangle, osg::Matrixd localToWorld ); 00049 00050 DtOsgIntersectorResult( const DtOsgIntersectorResult& orig ); 00051 00052 DtOsgIntersectorResult& operator=( const DtOsgIntersectorResult &orig ); 00053 00054 public: 00055 // 3 points of the intersected triangle 00056 std::vector<osg::Vec3> myHitTriangle; 00057 00058 // matrix transform from world to triangle local coordinates 00059 osg::Matrixd myLocalToWorld; 00060 }; 00061 00066 class DT_DLL_VRVOSG DtOsgIntersector : public DtIntersector 00067 { 00068 public: 00069 00070 // Abstract DtIntersector Implementation for OSG 00071 00073 DtOsgIntersector( DtDe& de, int modelSet ); 00074 00076 virtual ~DtOsgIntersector(); 00077 00092 virtual bool findNearestIntersectionToPoint(double x, double y, double z, 00093 double vx, double vy, double vz, 00094 DtIntersectorResult& intersection, 00095 IntersectProperties properties=AllNodes, 00096 std::vector<DtElementID>* ignoreList=0, 00097 bool returnTriangle=false, 00098 double maxIsectorLength=-1., bool useHighLod=false ); 00099 00107 virtual bool findAllIntersectionsThroughPoint( double x, double y, double z, 00108 double vx, double vy, double vz, DtIntersections& intersections, 00109 IntersectProperties properties=AllNodes, 00110 std::vector<DtElementID>* ignoreList=0, bool sort=true, bool useHighLod=false ); 00111 00118 virtual bool findFirstIntersectWithLineSegment( 00119 double x, double y, double z, double end_x, double end_y, double end_z, 00120 DtIntersectorResult& intersection, 00121 IntersectProperties properties=AllNodes, 00122 std::vector<DtElementID>* ignoreList=0, bool useHighLod=false); 00123 00130 virtual bool findAllIntersectWithLineSegment( 00131 double x, double y, double z, double end_x, double end_y, double end_z, 00132 DtIntersections& intersections, 00133 IntersectProperties properties=AllNodes, 00134 std::vector<DtElementID>* ignoreList=0, bool sort=true, bool useHighLod=false ); 00135 00141 virtual bool pick( DtChannel& channel, double mx, double my, 00142 DtIntersectorResult& intersection, 00143 IntersectProperties properties=AllNodes, 00144 std::vector<DtElementID>* ignoreList=0); 00145 00150 virtual bool pickAll( DtChannel* channel, double mx, double my, 00151 DtIntersections& intersections, IntersectProperties properties=AllNodes, 00152 std::vector<DtElementID>* ignoreList=0); 00153 00154 public: 00155 00156 // OSG-specific Interface 00157 00158 typedef std::vector<DtOsgIntersectorResult> DtOsgIntersections; 00159 00160 00180 bool findNearestIntersection(double x, double y, double z, 00181 double vx, double vy, double vz, DtOsgIntersectorResult& intersection, 00182 const DtOsgRenderer::RootList& intersectionRoots, 00183 osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn, 00184 std::list<osg::Node*>* excludeNodeList=0, bool returnHitTriangle=false, 00185 double maxIsectorLength=-1.0, bool useHighLod=false); 00186 00200 bool findIntersectionsThroughPoint(double x, double y, double z, 00201 double vx, double vy, double vz, 00202 DtOsgIntersector::DtOsgIntersections& intersections, 00203 const DtOsgRenderer::RootList& intersectionRoots, 00204 osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn, 00205 std::list<osg::Node*>* excludeNodeList=0, bool returnHitTriangle=false, 00206 double maxIsectorLength=-1.0, bool sort=true, bool useHighLod=false ); 00207 00213 bool intersectLineSegmentWithScene( double x, double y, double z, 00214 double end_x, double end_y, double end_z, 00215 DtOsgIntersectorResult& intersection, 00216 const DtOsgRenderer::RootList& intersectionRoots, 00217 osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn, 00218 std::list<osg::Node*>* excludeNodeList=0, 00219 bool returnHitTriangle=false, bool useHighLod=false ); 00220 00226 bool intersectLineSegmentWithScene( double x, double y, double z, 00227 double end_x, double end_y, double end_z, 00228 DtOsgIntersector::DtOsgIntersections& intersections, 00229 const DtOsgRenderer::RootList& intersectionRoots, 00230 osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn, 00231 std::list<osg::Node*>* excludeNodeList=0, 00232 bool returnHitTriangle=false, bool sort=true, bool useHighLod=false ); 00233 00236 virtual bool pick( osgViewer::View& view, double mx, double my, 00237 DtOsgIntersectorResult& intersection, 00238 osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn, 00239 std::list<osg::Node*>* excludeNodeList=0, 00240 bool returnHitTriangle=false ); 00241 00244 virtual bool pick( osgViewer::View& view, double mx, double my, 00245 DtOsgIntersector::DtOsgIntersections& intersections, 00246 osg::Node::NodeMask mask=DtOsgNodeFlags::FlagAllOn, 00247 std::list<osg::Node*>* excludeNodeList=0, 00248 bool returnHitTriangle=false ); 00249 00250 void getExcludeNodesFromIgnoreList( std::vector<DtUniqueID>* ignoreList, 00251 std::list<osg::Node*>& excludeNodes ); 00252 00253 public: 00254 00255 static osg::Node::NodeMask nodeMaskFromIntersectProperties( 00256 IntersectProperties properties ); 00257 00258 static bool anyNodeInNodePath(std::list<osg::Node*>* n, 00259 osg::NodePath const& path); 00260 00261 protected: 00262 00265 osg::Vec3d worldIntersectPoint( const osgUtil::Hit& hit ); 00266 00267 osg::Vec3d worldIntersectPoint( 00268 const osgUtil::LineSegmentIntersector::Intersection& hit ); 00269 00270 osg::Vec3d localToWorld( const osg::Vec3& local, const osg::Matrix& localToWorld ); 00271 00272 bool findIdFromNodePath( const osg::NodePath& nodePath, DtUniqueID& id ); 00273 00275 bool fillResultFromHit(DtOsgIntersectorResult& result, const osgUtil::Hit& hit, 00276 bool returnHitTriangle ) ; 00277 00279 bool fillResultFromHit(DtOsgIntersectorResult& result, 00280 const osgUtil::LineSegmentIntersector::Intersection& hit, 00281 bool returnHitTriangle ) ; 00282 00285 osgUtil::IntersectVisitor::HitList& getLineSegmentIntersection( 00286 osgUtil::IntersectVisitor& collisionVisitor, double x, double y, double z, 00287 double end_x, double end_y, double end_z, 00288 const DtOsgRenderer::RootList& intersectionRoots, osg::Node::NodeMask mask); 00289 00291 bool processLineSegmentIntersection( 00292 osgUtil::IntersectVisitor::HitList& hitList, 00293 std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle, 00294 DtOsgIntersectorResult& intersection ); 00295 00297 bool processLineSegmentIntersection( const osg::Vec3d& testPoint, 00298 osgUtil::IntersectVisitor::HitList& hitList, 00299 std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle, 00300 DtOsgIntersectorResult& intersection ); 00301 00303 bool processLineSegmentIntersection( const osg::Vec3d& testPoint, 00304 osgUtil::IntersectVisitor::HitList& hitList, 00305 std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle, 00306 DtOsgIntersector::DtOsgIntersections& intersections, bool sort ); 00307 00309 bool processPickIntersection( 00310 osgUtil::LineSegmentIntersector::Intersections& hitList, 00311 std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle, 00312 DtOsgIntersectorResult& intersection ); 00313 00315 bool processPickIntersection( 00316 osgUtil::LineSegmentIntersector::Intersections& hitList, 00317 std::list<osg::Node*>* excludeNodeList, bool returnHitTriangle, 00318 DtOsgIntersector::DtOsgIntersections& intersections ); 00319 00320 protected: 00321 int myModelSet; 00322 }; 00323 00327 class DtOsgIntersectorSorter 00328 { 00329 public: 00330 DtOsgIntersectorSorter( const osg::Vec3d& reference ) 00331 : myReference( reference ) {} 00332 00333 inline bool operator() ( const DtOsgIntersectorResult& a, 00334 const DtOsgIntersectorResult& b ) 00335 { 00336 osg::Vec3d diffA = osg::Vec3d(a.x, a.y, a.z) - myReference; 00337 osg::Vec3d diffB = osg::Vec3d(b.x, b.y, b.z) - myReference; 00338 return diffA.length2() > diffB.length2(); 00339 } 00340 protected: 00341 osg::Vec3d myReference; 00342 }; 00343 00346 class DT_DLL_VRVOSG DtOsgIntersectorCreator : public DtIntersectorCreator 00347 { 00348 public: 00350 virtual DtIntersector* create(DtDe& de, int modelSet ); 00351 }; 00352 }