ObjsAheadExplorer.cc

Go to the documentation of this file.
00001 #include "esg/explorer/ObjsAheadExplorer.h"
00002 #include <esg/iterator/IteratorSDS.h>
00003 
00004 using namespace esg;
00005 
00006 bool ObjsAheadExplorer::_explore(SceneGraphObject& obj)
00007 {
00008     Transform* pTr = obj.transformation();
00009 
00010     if (pTr) { // new transformation => update stack
00011         Matrix4* auxMat = new Matrix4(pTr->get());
00012         if (!_trStack.empty()) auxMat->mul(*_trStack.top(), *auxMat);
00013         _trStack.push(auxMat);
00014         _rMat.set(*(pTr->getRotation()));
00015         _tVec = pTr->getTranslation();
00016         _sVec = pTr->getScale();
00017         ESG_INVERSE_TR_RAY(_rMat, *_tVec, *_sVec,
00018                            _origin, _trOrigin, _direction, _trDirection);
00019     }
00020 
00021     /*
00022      * Inspect subnodes and/or attributes
00023      */
00024     if (obj.hasSubnodes()) { // iterate
00025         _retVal = false;
00026         IteratorSDS* pIter = obj.traverseSubnodes();
00027         if (pIter) {
00028             pIter->initHalfSpaceSearch(_trOrigin, _trDirection);
00029             _pCandidate = pIter->firstChild();
00030             while (_pCandidate) {
00031                 if (_explore(*_pCandidate)) _retVal = true;
00032                 _pCandidate = pIter->nextChild();
00033             }
00034             delete pIter;
00035         }
00036     } else { // process_leaf
00037         Geometry * pGeom = obj.geometry();
00038         if (pGeom) {
00039             Interval ext = pGeom->extent(_trDirection);
00040 #ifndef _MSC_VER
00041 #warning "FIXME: Store transformed primitives"
00042 #endif
00043             if (ext.max >= _originDist) _pResult->append(&obj);//POSSIBLE ERROR
00044             _retVal = true;
00045         } else
00046             _retVal = false;
00047     }
00048 
00049     /*
00050      * Erase my transform. matrix after backtracking children
00051      */
00052     if (pTr) {
00053         delete _trStack.top();
00054         _trStack.pop();
00055     }
00056 
00057     return _retVal;
00058 }
00059 
00060 
00061 
00062 
00063 
00064 ObjsAheadExplorer::ObjsAheadExplorer(const Vector3& origin,
00065                                      const Vector3& direction,
00066                                      Group *        pRepos)
00067     : RayIntExplorer(origin, direction, NULL)
00068 {
00069     _pResult    = pRepos;
00070     _originDist = _origin.dot(_direction);
00071 }
00072 
00073 

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