LightManager.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                               SOFA :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
00024 ******************************************************************************/
00025 //
00026 // C++ Implementation: LightManager
00027 //
00028 // Description: 
00029 //
00030 //
00031 // Author: The SOFA team </www.sofa-framework.org>, (C) 2007
00032 //
00033 // Copyright: See COPYING file that comes with this distribution
00034 //
00035 //
00036 #include <sofa/component/visualmodel/LightManager.h>
00037 #include <sofa/core/ObjectFactory.h>
00038 
00039 namespace sofa
00040 {
00041 
00042 namespace component
00043 {
00044 
00045 namespace visualmodel
00046 {
00047 
00048 SOFA_DECL_CLASS(LightManager)
00049 //Register LightManager in the Object Factory
00050 int LightManagerClass = core::RegisterObject("LightManager")
00051 .add< LightManager >()
00052 ;
00053 
00054 LightManager::LightManager()
00055 {
00056 
00057 }
00058 
00059 LightManager::~LightManager()
00060 {
00061 
00062 }
00063 
00064 void LightManager::init()
00065 {
00066     
00067 }
00068 
00069 void LightManager::putLight(Light* light)
00070 {
00071     if (lights.size() >= MAX_NUMBER_OF_LIGHTS)
00072     {
00073         std::cerr << "The maximum of lights permitted ( "<< MAX_NUMBER_OF_LIGHTS << " ) has been reached." << std::endl;
00074         return ;
00075     }
00076 
00077     light->setID(GL_LIGHT0+lights.size());
00078     lights.push_back(light) ;
00079 }
00080 
00081 void LightManager::putLights(std::vector<Light*> lights)
00082 {
00083     for (std::vector<Light*>::iterator itl = lights.begin(); itl != lights.end() ; itl++)
00084         putLight(*itl);
00085 }
00086 
00087 void LightManager::draw()
00088 {
00089     unsigned int id = 0;
00090     for (std::vector<Light*>::iterator itl = lights.begin(); itl != lights.end() ; itl++){
00091         glEnable(GL_LIGHT0+id);
00092         (*itl)->drawLight();
00093         id++;
00094     }
00095 }
00096 
00097 void LightManager::initVisual()
00098 {
00099     for (std::vector<Light*>::iterator itl = lights.begin(); itl != lights.end() ; itl++){
00100         (*itl)->initVisual();
00101     }
00102 
00103 }
00104 
00105 
00106 void LightManager::clear()
00107 {
00108     for (unsigned int i=0 ; i<MAX_NUMBER_OF_LIGHTS ; i++)
00109         glDisable(GL_LIGHT0+i);
00110     lights.clear();
00111 }
00112 
00113 void LightManager::reinit()
00114 {
00115     for (std::vector<Light*>::iterator itl = lights.begin(); itl != lights.end() ; itl++){
00116         (*itl)->reinit();
00117     }
00118 }
00119 
00120 }//namespace visualmodel
00121 
00122 }//namespace component
00123 
00124 }//namespace sofa

Generated on Sun Nov 23 03:48:33 2008 for Sofa by  doxygen 1.5.7.1