ShadowExplorer.cc

Go to the documentation of this file.
00001 #include <esg/explorer/ShadowExplorer.h>
00002 #include <esg/iterator/IteratorSDS.h>
00003 
00004 using namespace esg;
00005 
00006 bool ShadowExplorer::_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         IteratorSDS* pIter = obj.traverseSubnodes();
00026         if (pIter) {
00027             pIter->initRayIntersection(_trOrigin,_trDirection,true,_maxDist);
00028             _pCandidate = pIter->firstChild();
00029             while (_pCandidate) {
00030                 if (_explore(*_pCandidate)) { delete pIter; return true; }
00031                 _pCandidate = pIter->nextChild();
00032             }
00033             delete pIter;
00034         }
00035     } else  { // process_leaf
00036         if (obj.getOID() != _lightOID) { // skip light itself
00037             _pGeometry = obj.geometry();
00038             if (_pGeometry) {
00039                 _pGeometry->rayIntersection(&_env,
00040                                             ENV_WANT_INTERFERENCE|ENV_USE_CACHE,
00041                                             _trOrigin, _trDirection, _maxDist);
00042                 if (_env.mask & ENV_HAVE_INTERFERENCE) {
00043                     _blockingObj.pObj = &obj;
00044                     if (_env.mask & ENV_HAVE_TRANSFORMATION) {
00045                         _blockingObj.transformed = true;
00046                         _blockingObj.trMat.set(_env.trMat);
00047                     } else
00048                         _blockingObj.transformed = false;
00049                     return true;
00050                 }
00051                 return false;
00052             }
00053         }
00054     }
00055 
00056     /*
00057      * Erase my transform. matrix after backtracking children
00058      */
00059     if (pTr) {
00060         delete _trStack.top();
00061         _trStack.pop();
00062     }
00063 
00064     return false;
00065 }
00066     
00067 void ShadowExplorer::explore(SceneGraphObject& obj)
00068 {
00069     _blockingObj.pObj = NULL;
00070     while (!_trStack.empty()) _trStack.pop();
00071     (void) _explore(obj);
00072 }
00073 

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