00001 /*************************************************************************** 00002 * Copyright (C) 2007 by * 00003 * Pierre-yves JEZEQUEL, Julien MICHOT, Loic MOISAN, * 00004 * Julien PAPILLON, Sebastien PINEAUD, Barthelemy SERRES * 00005 * * 00006 * https://sourceforge.net/projects/anidam * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the * 00020 * Free Software Foundation, Inc., * 00021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00022 ***************************************************************************/ 00023 00024 /*############################################################################## 00025 File: light_module.h 00026 Purpose: This class encapsulates some basic lighting functionality provided 00027 by OSG. It allows for the creation of up to 8 lights which may 00028 be modified via the direct OSG::Light interface. 00029 00030 Note that the user requests lights from this module, and should 00031 not instantiate them on their own, unless they have some way 00032 of keeping track of which lights have been previously enabled. 00033 00034 Note that a maximum of 8 lights may be added to the scene 00035 using this module. 00036 00037 Also note that unless light ONE is allocated here, the it will 00038 be used as the default SceneView light, as it has been in 00039 the previous tutorials. If light ONE is allocated using this 00040 class, then there will be no default SceneView light, leaving 00041 the scene dark save for objects illuminated by allocated lights. 00042 Returns: N/A 00043 */ 00044 #ifndef LIGHT_MANAGER 00045 #define LIGHT_MANAGER 00046 00047 #include <vector> 00048 using std::vector; 00049 // LightSource - used to hold osg::Lights 00050 #include <osg/LightSource> 00051 00052 // Light - represents the functionality of the OpenGL light model 00053 #include <osg/Light> 00054 00055 class LightManager { 00056 public: 00057 /* 00058 This enumeration represents the number of the light currently being allocated. 00059 OpenGL allows for a minimum, and usually maximum of 8 lights at any given 00060 time. This enumeration allows the user to safely request one of these 8 00061 without having to worry about stepping out of bounds. Note that they 00062 are 1 off, meaning 'ONE' actually represents the 0 light in OpenGL, while 00063 'EIGHT' represents the 7 light. 00064 */ 00065 enum LIGHTNUMBER{ 00066 ONE, 00067 TWO, 00068 THREE, 00069 FOUR, 00070 FIVE, 00071 SIX, 00072 SEVEN, 00073 EIGHT 00074 }; 00075 00076 /*////////////////////////////////////////////////////////////////////////// 00077 Default Constructor - This does not allocate any lights. Note that upon 00078 construction, this module is not yet ready for light allocation. The 00079 init() function must first be called. 00081 LightManager(); 00082 00083 /*////////////////////////////////////////////////////////////////////////// 00084 Default Constructor - Empty 00086 ~LightManager() {} 00087 00088 /*////////////////////////////////////////////////////////////////////////// 00089 This function is necessary to grab the osg::Group that will contain 00090 any lights that are requested for allocation. Note that this osg::Group, 00091 for some reason, should be DIRECTLY under the SceneView. That is, there 00092 should not be any other nodes between the SceneView and this osg::Group. 00093 It has something to do with osg::SetStates, but I have yet to figure out 00094 what. 00096 void init(osg::Group * root); 00097 00098 /*////////////////////////////////////////////////////////////////////////// 00099 This function is used to request allocation of an osg::Light. The light 00100 is requested by passing the enumerated value representing the number 00101 of the light. If the light has not been previously allocated, it is created 00102 and added to the osg::Group for rendering. The osg::Light is returned 00103 as a pointer, which may be used to modify the light properties via 00104 the osg::Light interface. 00105 00106 If the light has been previously allocated, it is returned as a pointer. 00107 00108 Note that if this module has not been initialized with the init() function, 00109 NULL will be returned instead of an osg::Light. 00111 osg::Light* getOrCreateLight(LightManager::LIGHTNUMBER number); 00112 00113 private: 00114 osg::Group * groupOfLights; 00115 /* 00116 Vector (really we're just using it as an array), of osg::LightSources, 00117 which themselves contain an individual osg::Light. The number defined 00118 by LightManager::LIGHTNUMBER will directly index a slot in this vector. 00119 */ 00120 vector<osg::LightSource*> lights; 00121 00122 /* 00123 Boolean that represents the state of this class: 00124 false - this class has not been initialized yet 00125 true - the class has been initialized and is ready for light allocation 00126 */ 00127 bool valid; 00128 }; 00129 #endif