GLPhotonMapRender.cc

Go to the documentation of this file.
00001 #include <gra/render/GLPhotonMapRender.h>
00002 #include <gra/camera/CameraGL.h>
00003 #include <esg/energy/PhotonMap.h>
00004 #include <esg/energy/PhotonMapEnergy.h>
00005 #include <esg/geometry/Point3D.h>
00006 #include <esg/explorer/ObjsExplorer.h>
00007 #include <esg/Material.h>
00008 #include <GL/gl.h>
00009 
00010 using namespace gra;
00011 
00012 const int GLPhotonMapRender::GLOBAL_PHOTONS  (1<<0);
00013 const int GLPhotonMapRender::CAUSTIC_PHOTONS (1<<1);
00014 
00015 void GLPhotonMapRender::_render(Shader&           shader,
00016                                 FrameBuffer&      fb,
00017                                 Camera&           camera,
00018                                 Scene&            scene)
00019 {
00020     /*
00021      * This render requires an OpenGL camera (CameraGL class).
00022      * Therefore we have to instantiate it from the general camera.
00023      * Although the OpenGL camera is not furher used, its instantiation
00024      * updates the OpenGL projection and transformation matrices.
00025      */
00026     CameraGL cameraGL(camera);
00027 
00028     if (_useDisplayList && _displayList) {
00029         glCallList(_displayList);
00030         return;
00031     }
00032 
00033     if (_useDisplayList) {
00034         _displayList = glGenLists(1);
00035         glNewList(_displayList, GL_COMPILE_AND_EXECUTE);
00036     }
00037 
00038     if (scene.root()) {
00039         ObjsExplorer explorer;
00040         explorer.explore(*(scene.root()));
00041         
00042         SceneGraphObject    * pObj;
00043         Matrix4               trMat;
00044         bool                  tr;
00045         AutoPtr<EnergyCoat> * pACoat;
00046         EnergyCoat          * pCoat;
00047         PhotonMapEnergy     * pMap;
00048             
00049         while ((pObj = explorer.result(trMat, tr))) {
00050             if (!(pACoat = pObj->getEnergyState()))              continue;
00051             if (!(pCoat = pACoat->origObject()))                 continue;
00052             if (!(pMap = dynamic_cast<PhotonMapEnergy*>(pCoat))) continue;
00053 
00054             if (_mode & GLOBAL_PHOTONS) {
00055                 unsigned nPhotons = pMap->numGlobalPhotons();
00056                 glBegin(GL_POINTS); {
00057                     PhotonsIterator* pIter = pMap->globalMapIterator();
00058                     if (pIter) {
00059                         while (pIter->hasNext()) {
00060                             const Photon * pPhoton = pIter->next();
00061                             Vector3 power(pPhoton->getPower());
00062                             Vector3 loc(pPhoton->getLocation());
00063                             power.scale(nPhotons);
00064                             glColor3f(power.x, power.y, power.z);
00065                             glVertex3f(loc.x, loc.y, loc.z);
00066                         }
00067                     }
00068                 } glEnd();
00069             }
00070 
00071             if (_mode & CAUSTIC_PHOTONS) {
00072                 unsigned nPhotons = pMap->numCausticPhotons();
00073                 glBegin(GL_POINTS); {
00074                     PhotonsIterator* pIter = pMap->causticsMapIterator();
00075                     if (pIter) {
00076                         while (pIter->hasNext()) {
00077                             const Photon * pPhoton = pIter->next();
00078                             Vector3 power(pPhoton->getPower());
00079                             Vector3 loc(pPhoton->getLocation());
00080                             power.scale(nPhotons);
00081                             glColor3f(power.x, power.y, power.z);
00082                             glVertex3f(loc.x, loc.y, loc.z);
00083                         }
00084                     }
00085                 } glEnd();
00086             }
00087         }
00088     }
00089     
00090     if (_useDisplayList) glEndList();
00091 }

Generated on Tue Nov 21 15:11:42 2006 for gra by  doxygen 1.4.6