- Timestamp:
- Mar 1, 2005, 8:11:31 PM (20 years ago)
- Location:
- orxonox/trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/light.cc
r3436 r3437 23 23 using namespace std; 24 24 25 //! Definition of the Lights 26 int lightsV[] = {GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, GL_LIGHT3, GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7}; 27 25 28 26 29 /** … … 29 32 Light::Light () 30 33 { 31 this-> init();32 } 33 34 Light::Light(Vector position) 35 { 36 this->init();37 this-> setPosition(position);34 this->setClassName ("Light"); 35 36 glEnable (GL_LIGHTING); 37 this->lights = new LightValue*[NUMBEROFLIGHTS]; 38 for (int i = 0; i < NUMBEROFLIGHTS; i++) 39 lights[i] = NULL; 40 this->currentLight = new LightValue; 38 41 } 39 42 … … 46 49 { 47 50 glDisable(GL_LIGHTING); 48 glDisable(GL_LIGHT0); 51 52 for (int i = 0; i < NUMBEROFLIGHTS; i++) 53 this->deleteLight(i); 54 delete lights; 55 Light::singletonRef = NULL; 56 } 57 58 Light* Light::singletonRef = NULL; 59 60 /** 61 \returns The Instance of the Lights 62 */ 63 Light* Light::getInstance(void) 64 { 65 if (singletonRef) 66 return singletonRef; 67 else 68 return Light::singletonRef = new Light(); 49 69 } 50 70 … … 52 72 \brief initializes a new Light with default values, and enables GL_LIGHTING 53 73 */ 54 void Light::init() 55 { 56 this->setClassName ("Light"); 57 glEnable (GL_LIGHTING); 58 glEnable (GL_LIGHT0); 74 void Light::init(int lightNumber) 75 { 76 PRINTF(3)("initializing Light number %d.\n", lightNumber); 77 // enable The light 78 glEnable(lightsV[lightNumber]); 79 this->currentLight = lights[lightNumber] = new LightValue; 59 80 81 // set default values 82 this->currentLight->lightNumber = lightNumber; 60 83 this->setPosition(Vector(0.0, 0.0, 0.0)); 61 84 this->setDiffuseColor(1.0, 1.0, 1.0); 62 85 this->setSpecularColor(1.0, 1.0, 1.0); 63 86 // lmodelAmbient[] = {.1, .1, .1, 1.0}; 64 65 } 87 } 88 89 /** 90 \brief Adds a new Light, by selecting the First free slot. 91 92 if no slot is free error 93 */ 94 int Light::addLight(void) 95 { 96 for (int i = 0; i < NUMBEROFLIGHTS; i++) 97 if (!this->lights[i]) 98 return addLight(i); 99 PRINTF(1)("no more light slots availiable. All %d already taken\n", NUMBEROFLIGHTS); 100 return -1; 101 } 102 103 /** 104 \brief Adds a new Light 105 \param lightNumber The number of the light to add. 106 107 if the Number is not free: warn, automatically choose another slot. 108 */ 109 int Light::addLight(int lightNumber) 110 { 111 if (this->lights[lightNumber]) 112 { 113 PRINTF(2)("Lightslot %d is allready taken, trying another one\n", lightNumber); 114 return this->addLight(); 115 } 116 this->init(lightNumber); 117 this->currentLight = this->lights[lightNumber]; 118 return lightNumber; 119 } 120 121 /** 122 \brief select the light to work with 123 \param lightNumber the light to work with 124 */ 125 void Light::editLightNumber(int lightNumber) 126 { 127 this->currentLight = lights[lightNumber]; 128 } 129 130 /** 131 \brief Delete the current Light 132 */ 133 void Light::deleteLight(void) 134 { 135 this->deleteLight(this->currentLight->lightNumber); 136 } 137 138 /** 139 \brief delete light. 140 \param lightnumber the number of the light to delete 141 */ 142 void Light::deleteLight(int lightNumber) 143 { 144 if (this->lights[lightNumber]) 145 { 146 PRINTF(3)("deleting Light number %d\n", lightNumber); 147 delete this->lights[lightNumber]; 148 glDisable(lightsV[lightNumber]); 149 this->lights[lightNumber] = NULL; 150 } 151 } 152 153 66 154 67 155 // set Attributes … … 73 161 void Light::setPosition(Vector position) 74 162 { 75 this->lightPosition[0] = position.x; 76 this->lightPosition[1] = position.y; 77 this->lightPosition[2] = position.z; 78 this->lightPosition[3] = 0.0; 79 80 glLightfv (GL_LIGHT0, GL_POSITION, lightPosition); 81 163 this->currentLight->lightPosition[0] = position.x; 164 this->currentLight->lightPosition[1] = position.y; 165 this->currentLight->lightPosition[2] = position.z; 166 this->currentLight->lightPosition[3] = 0.0; 167 168 glLightfv (GL_LIGHT0, GL_POSITION, this->currentLight->lightPosition); 169 } 170 171 void Light::setPosition(GLfloat x, GLfloat y, GLfloat z) 172 { 173 this->currentLight->lightPosition[0] = x; 174 this->currentLight->lightPosition[1] = y; 175 this->currentLight->lightPosition[2] = z; 176 this->currentLight->lightPosition[3] = 0.0; 177 178 glLightfv (GL_LIGHT0, GL_POSITION, this->currentLight->lightPosition); 82 179 } 83 180 … … 90 187 void Light::setDiffuseColor(GLfloat r, GLfloat g, GLfloat b) 91 188 { 92 this-> diffuseColor[0] = r;93 this-> diffuseColor[1] = g;94 this-> diffuseColor[2] = b;95 this-> diffuseColor[3] = 1.0;96 97 glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuseColor);189 this->currentLight->diffuseColor[0] = r; 190 this->currentLight->diffuseColor[1] = g; 191 this->currentLight->diffuseColor[2] = b; 192 this->currentLight->diffuseColor[3] = 1.0; 193 194 glLightfv (GL_LIGHT0, GL_DIFFUSE, this->currentLight->diffuseColor); 98 195 } 99 196 … … 107 204 void Light::setSpecularColor(GLfloat r, GLfloat g, GLfloat b) 108 205 { 109 this-> specularColor[0] = r;110 this-> specularColor[1] = g;111 this-> specularColor[2] = b;112 this-> specularColor[3] = 1.0;113 114 glLightfv (GL_LIGHT0, GL_SPECULAR, specularColor);206 this->currentLight->specularColor[0] = r; 207 this->currentLight->specularColor[1] = g; 208 this->currentLight->specularColor[2] = b; 209 this->currentLight->specularColor[3] = 1.0; 210 211 glLightfv (GL_LIGHT0, GL_SPECULAR, this->currentLight->specularColor); 115 212 } 116 213 … … 122 219 Vector Light::getPosition(void) 123 220 { 124 Vector tmpPosition( lightPosition[0], lightPosition[1],lightPosition[2]);221 Vector tmpPosition(this->currentLight->lightPosition[0], this->currentLight->lightPosition[1], this->currentLight->lightPosition[2]); 125 222 return tmpPosition; 126 223 } -
orxonox/trunk/src/light.h
r3436 r3437 14 14 #include "glincl.h" 15 15 16 #define NUMBEROFLIGHTS GL_MAX_LIGHTS 17 16 18 // FORWARD DEFINITIONS // 17 19 class Vector; … … 21 23 A Light is a source that emits light rays (photons) 22 24 */ 23 class Light : public WorldEntity 25 class Light : public WorldEntity 24 26 { 27 private: 28 //! A struct that holds information about a Light 29 struct LightValue 30 { 31 int lightNumber; //!< The number of this Light. 32 GLfloat lightPosition[4]; //!< The Position of this Light. 33 GLfloat lmodelAmbient[4]; //!< The general Ambient Color. 34 GLfloat diffuseColor[4]; //!< The Diffuse Color this Light emmits. 35 GLfloat specularColor[4]; //!< The specular Color of this Light. 36 37 LightValue* next; 38 }; 39 40 static Light* singletonRef; //!< This is the LightHandlers Reference. 41 Light(void); 42 43 void init(int LightNumber); 44 LightValue** lights; 45 LightValue* currentLight; 25 46 26 27 47 public: 28 Light(void); 29 Light(Vector position); 48 static Light* getInstance(); 30 49 ~Light(void); 31 50 32 51 // set Attributes 52 int addLight(void); 53 int addLight(int lightNumber); 54 void editLightNumber(int lightNumber); 55 void deleteLight(void); 56 void deleteLight(int lightNumber); 57 33 58 void setPosition(Vector position); 59 void setPosition(GLfloat x, GLfloat y, GLfloat z); 34 60 void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); 35 61 void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); 36 37 62 // get Attributes 38 63 Vector getPosition(void); 39 private:40 GLfloat lightPosition[4]; //!< The Position of this Light41 GLfloat lmodelAmbient[4]; //!< The general Ambient Color42 GLfloat diffuseColor[4]; //!< The Diffuse Color this Light emmits43 GLfloat specularColor[4]; //!< The specular Color of this Light44 45 void init();46 64 }; 47 65 -
orxonox/trunk/src/world.cc
r3436 r3437 172 172 void World::load() 173 173 { 174 light0 = new Light(Vector(10.0, 10.0, 19.0)); 174 light = Light::getInstance(); 175 light->addLight(1); 176 light->setPosition(10.0, 10.0, 19.0); 175 177 176 178 // BezierCurve* tmpCurve = new BezierCurve(); -
orxonox/trunk/src/world.h
r3436 r3437 77 77 SDL_Surface *loadImage; 78 78 Skysphere* skySphere; 79 Light* light 0;79 Light* light; 80 80 81 81 WorldEntity* localPlayer;
Note: See TracChangeset
for help on using the changeset viewer.