Intersector.cc

Go to the documentation of this file.
00001 #include <esg/Intersector.h>
00002 #include <esg/geometry/Geometry.h>
00003 
00004 using namespace esg;
00005 
00006 void Intersector::init(int mask, float maxDist)
00007 {
00008     if (_pEnv) delete _pEnv; // old result is lost forewer
00009     _pEnv       = NULL;
00010     _distance   = maxDist;
00011     _wantedMask = mask|ENV_WANT_DISTANCE;
00012     //_checkMask  = _wantedMask &
00013     //  (ENV_WANT_INTERSECTION|ENV_WANT_INTERFERENCE|ENV_WANT_DISTANCE);
00014 }
00015 
00016 PointEnv* Intersector::adoptIntersection()
00017 {
00018     PointEnv* pRet = _pEnv;
00019     _pEnv          = NULL;
00020     return pRet;
00021 }
00022 
00023 
00024 int Intersector::processCandidate(SceneGraphObject* pObject,       
00025                                   const Vector3&    origin,  
00026                                   const Vector3&    direction)
00027 {
00028     if (!pObject) return 0;
00029 
00030     Geometry* pGeom = pObject->geometry();
00031     if (!pGeom) return 0;
00032 
00033     if (!_pNewEnv) _pNewEnv = new PointEnv;
00034     pGeom->rayIntersection(_pNewEnv,_wantedMask,origin,direction,_distance);
00035 
00036     //if ((_pNewEnv->mask & _checkMask) != _checkMask) return 0;
00037     //if (_pNewEnv->distance <= 0.0 || _pNewEnv->distance >= _distance) return 0;
00038     
00039     if (!(_pNewEnv->mask & ENV_HAVE_DISTANCE) ||
00040         _pNewEnv->distance <= 0.0 ||
00041         _pNewEnv->distance >= _distance) return 0;
00042 
00043     // now we have what we required and the intersection is closest so far
00044     if (_pEnv) delete _pEnv;
00045     _pEnv     = _pNewEnv;
00046     _pNewEnv  = NULL;
00047     _distance = _pEnv->distance;
00048     if (_wantedMask & ENV_WANT_ASOC_PRIMITIVE) {
00049         _pEnv->pVisitableObj = pObject; 
00050         _pEnv->mask |= ENV_HAVE_ASOC_PRIMITIVE; 
00051     }
00052     
00053     return 1; 
00054 }
00055 
00056 
00057 

Generated on Wed Jun 28 12:24:31 2006 for esg by  doxygen 1.4.6