Changeset 4736 in orxonox.OLD for orxonox/trunk/src/lib
- Timestamp:
- Jun 30, 2005, 1:06:53 AM (19 years ago)
- Location:
- orxonox/trunk/src/lib/graphics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/light.cc
r4735 r4736 45 45 46 46 /** 47 \param lightNumber the Light Number to initiate48 */49 Light::Light(int lightNumber)50 {51 this->init(lightNumber);52 }53 54 /**55 47 * \param root The XML-element to load the Light from 56 48 */ 57 49 Light::Light(const TiXmlElement* root) 58 50 { 59 this->init(1); 60 this->loadParams(root); 61 } 62 63 /** 64 \brief destroys a Light 65 */ 66 Light::~Light(void) 67 { 68 glDisable(lightsV[this->lightNumber]); 69 } 70 71 /** 72 * \brief initializes a Light 73 */ 74 void Light::init(int lightNumber) 75 { 51 this->lightNumber = LightManager::getInstance()->registerLight(this); 52 76 53 this->setClassID(CL_LIGHT, "Light"); 77 54 char tmpName[10]; 78 sprintf(tmpName, "Light[%d]", lightNumber);55 sprintf(tmpName, "Light[%d]", this->lightNumber); 79 56 this->setName(tmpName); 80 57 81 PRINTF(4)("initializing Light number %d.\n", lightNumber);58 PRINTF(4)("initializing Light number %d.\n", this->lightNumber); 82 59 // enable The light 83 glEnable(lightsV[ lightNumber]); // postSpawn60 glEnable(lightsV[this->lightNumber]); // postSpawn 84 61 85 62 // set values (defaults) 86 this->lightNumber = lightNumber;87 63 this->setDiffuseColor(1.0, 1.0, 1.0); 88 64 this->setSpecularColor(1.0, 1.0, 1.0); 65 66 this->loadParams(root); 67 68 } 69 70 /** 71 \brief destroys a Light 72 */ 73 Light::~Light(void) 74 { 75 glDisable(lightsV[this->lightNumber]); 76 77 LightManager::getInstance()->unregisterLight(this); 78 } 79 80 /** 81 * \brief initializes a Light 82 */ 83 void Light::init() 84 { 89 85 } 90 86 … … 187 183 \brief draws this Light. Being a World-entity the possibility to do this lies at hand. 188 184 */ 189 void Light::draw() 185 void Light::draw() const 190 186 { 191 187 float pos[4] = {this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z, 1.0}; … … 245 241 glDisable(GL_LIGHTING); 246 242 247 // this will be done either by worldEntity, or by pNode as each light is one of them243 // this will be done either by PNode-tree as each light is one of them 248 244 // for (int i = 0; i < NUMBEROFLIGHTS; i++) 249 245 // this->deleteLight(i); … … 252 248 } 253 249 254 255 250 /** 256 251 \brief singleton-Reference to the Light-class 257 252 */ 258 253 LightManager* LightManager::singletonRef = NULL; 259 260 /**261 \brief initializes a new Light with default values, and enables GL_LIGHTING262 */263 void LightManager::initLight(int lightNumber)264 {265 lights[lightNumber] = new Light(lightNumber);266 }267 254 268 255 /** … … 292 279 } 293 280 } 294 295 /**296 \brief Adds a new Light, by selecting the First free slot.297 298 if no slot is free error299 */300 int LightManager::addLight(void)301 {302 for (int i = 0; i < NUMBEROFLIGHTS; i++)303 if (!this->lights[i])304 return addLight(i);305 PRINTF(1)("no more light slots availiable. All %d already taken\n", NUMBEROFLIGHTS);306 return -1;307 }308 309 310 /**311 \brief Adds a new Light312 \param lightNumber The number of the light to add.313 314 if the Number is not free: warn, automatically choose another slot.315 */316 int LightManager::addLight(int lightNumber)317 {318 if (this->lights[lightNumber])319 {320 PRINTF(2)("Lightslot %d is allready taken, trying another one\n", lightNumber);321 return this->addLight();322 }323 this->initLight(lightNumber);324 this->currentLight = this->lights[lightNumber];325 return lightNumber;326 }327 328 329 /**330 \brief select the light to work with331 \param lightNumber the light to work with332 */333 void LightManager::editLightNumber(int lightNumber)334 {335 if (!this->currentLight)336 {337 PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n");338 return;339 }340 this->currentLight = lights[lightNumber];341 }342 343 344 /**345 \brief Delete the current Light346 */347 void LightManager::deleteLight(void)348 {349 if (!this->currentLight)350 {351 PRINTF(1)("no Light defined yet. So you cannot delete any Light right now.\n");352 return;353 }354 355 this->deleteLight(this->currentLight->getLightNumber());356 }357 358 359 /**360 \brief delete light.361 \param lightNumber the number of the light to delete362 */363 void LightManager::deleteLight(int lightNumber)364 {365 if (this->lights[lightNumber])366 {367 PRINTF(4)("deleting Light number %d\n", lightNumber);368 delete this->lights[lightNumber];369 this->lights[lightNumber] = NULL;370 }371 }372 373 374 /**375 \brief draws all the Lights in their appropriate position376 */377 void LightManager::draw()378 {379 glMatrixMode(GL_MODELVIEW);380 glLoadIdentity();381 PRINTF(4)("Drawing the Lights\n");382 for (int i = 0; i < NUMBEROFLIGHTS; i++)383 if (this->lights[i])384 lights[i]->draw();385 }386 387 388 281 389 282 // set Attributes … … 404 297 } 405 298 406 /** 407 \brief sets an emitting Diffuse color of the currently selected Light 408 \param r red 409 \param g green 410 \param b blue 411 */ 412 void LightManager::setDiffuseColor(GLfloat r, GLfloat g, GLfloat b) 413 { 414 if (!this->currentLight) 299 int LightManager::registerLight(Light* light) 300 { 301 for (int i = 0; i < NUMBEROFLIGHTS; i++) 302 if (!this->lights[i]) 303 { 304 this->lights[i]=light; 305 return i; 306 } 307 PRINTF(1)("no more light slots availiable. All %d already taken\n", NUMBEROFLIGHTS); 308 return -1; 309 } 310 311 void LightManager::unregisterLight(Light* light) 312 { 313 for (int i = 0; i < NUMBEROFLIGHTS; i++) 314 { 315 if (this->lights[i] == light) 415 316 { 416 PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n"); 417 return; 317 this->lights[i] == NULL; 418 318 } 419 this->currentLight->setDiffuseColor(r,g,b); 420 } 421 422 423 /** 424 \brief sets an emitting Specular color of the currently selected Light 425 \param r red 426 \param g green 427 \param b blue 428 */ 429 void LightManager::setSpecularColor(GLfloat r, GLfloat g, GLfloat b) 430 { 431 if (!this->currentLight) 432 { 433 PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n"); 434 return; 435 } 436 this->currentLight->setSpecularColor(r, g, b); 437 } 438 439 440 /** 441 \brief Sets the AttenuationType of th currently selecte LightSource Light Source 442 \param constantAttenuation The Constant Attenuation of the Light 443 \param linearAttenuation The Linear Attenuation of the Light 444 \param quadraticAttenuation The Quadratic Attenuation of the Light 445 */ 446 void LightManager::setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation) 447 { 448 if (!this->currentLight) 449 { 450 PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n"); 451 return; 452 } 453 this->currentLight->setAttenuation(constantAttenuation, linearAttenuation, quadraticAttenuation); 454 } 455 456 457 /** 458 \brief stets the direction of the Spot Light. 459 \param direction The direction of the Spot Light. 460 */ 461 void LightManager::setSpotDirection(Vector direction) 462 { 463 if (!this->currentLight) 464 { 465 PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n"); 466 return; 467 } 468 this->currentLight->setSpotDirection(direction); 469 } 470 471 472 /** 473 \brief sets the cutoff angle of the Light. 474 \param cutoff The cutoff angle. 475 */ 476 void LightManager::setSpotCutoff(GLfloat cutoff) 477 { 478 if (!this->currentLight) 479 { 480 PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n"); 481 return; 482 } 483 this->currentLight->setSpotCutoff(cutoff); 484 } 485 486 /** 487 \returns a pointer to a Light 488 \param lightNumber The light to request the pointer from 489 */ 490 Light* LightManager::getLight(int lightNumber) const 491 { 492 return this->lights[lightNumber]; 493 } 494 319 } 320 PRINTF(2)("Light %p could not be unloaded (this should not heappen\n)"); 321 return; 322 } 323 324 /** 325 \brief draws all the Lights in their appropriate position 326 */ 327 void LightManager::draw() const 328 { 329 glMatrixMode(GL_MODELVIEW); 330 glLoadIdentity(); 331 PRINTF(4)("Drawing the Lights\n"); 332 for (int i = 0; i < NUMBEROFLIGHTS; i++) 333 if (this->lights[i]) 334 lights[i]->draw(); 335 } 495 336 496 337 /** -
orxonox/trunk/src/lib/graphics/light.h
r4735 r4736 26 26 { 27 27 public: 28 Light(int lightNumber); 29 Light(const TiXmlElement* root); 28 Light(const TiXmlElement* root = NULL); 30 29 virtual ~Light(void); 31 30 32 void init( int lightNumber);31 void init(); 33 32 void loadParams(const TiXmlElement* root); 34 33 … … 43 42 int getLightNumber(void) const {return this->lightNumber;} 44 43 45 virtual void draw() ;44 virtual void draw() const; 46 45 47 46 void debug(void) const; … … 66 65 67 66 <b>Usage:</b>\n 68 First you have to get the Light Manager up and running by using LightManager::getInstance .67 First you have to get the Light Manager up and running by using LightManager::getInstance(). 69 68 This automatically initiates the GL_LIGHTING, and sets some default stuff about the light.\n 70 69 Then you will create a new light using: 71 \li int addLight(void); 72 \li int addLight(int lightNumber); 70 \li new Light(); 73 71 74 72 now you can operate on the light as follows: 75 \li void setPosition(Vector position);76 \li void setPosition(GLfloat x, GLfloat y, GLfloat z);77 73 \li void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); 78 74 \li void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); … … 80 76 \li void setSpotDirection(Vector direction); 81 77 \li void setSpotCutoff(GLfloat cutoff); 82 83 These functions are preatty selv-explaining, but you can read about them below.\n 84 If you want to fetch info, or the a Light use: 85 \li Vector getPosition(void) const; 86 \li Vector getPosition(int lightNumber) const; 87 \li Light* getLight(int LightNumber) const; 78 \li all PNode stuff also works 88 79 89 80 To redraw the light use 90 \li void draw() ;81 \li void draw() const; 91 82 92 83 and to delete one just use … … 97 88 98 89 You can also operate on the single Lights themselves, by first retreaving them with 99 \li Light* getLight(int LightNumber) ;90 \li Light* getLight(int LightNumber) const; 100 91 \n 101 92 and then using the same functions on this to change settings. … … 103 94 class LightManager : public BaseObject 104 95 { 96 friend class Light; 105 97 106 98 public: … … 112 104 void loadLights(const TiXmlElement* root); 113 105 114 // set Attributes115 int addLight(void);116 int addLight(int lightNumber);117 void editLightNumber(int lightNumber);118 void deleteLight(void);119 void deleteLight(int lightNumber);120 121 106 void setAmbientColor(GLfloat r, GLfloat g, GLfloat b); 122 107 123 void draw(); 108 Light* getLight(int lightNumber) const; 109 inline Light* getLight() const { return this->currentLight; }; 124 110 125 //set Attributes 126 void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); 127 void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); 128 void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation); 129 void setSpotDirection(Vector direction); 130 void setSpotCutoff(GLfloat cutoff); 131 132 // get Attributes 133 Vector getPosition(void) const; 134 Vector getPosition(int lightNumber) const; 135 136 Light* getLight(int lightNumber) const; 137 Light* getLight() const { return this->currentLight; }; 111 void draw() const; 138 112 139 113 void debug(void) const; 140 114 141 142 115 private: 143 116 LightManager(void); 144 void initLight(int LightNumber);145 117 118 int registerLight(Light* light); 119 void unregisterLight(Light* light); 146 120 147 121 private:
Note: See TracChangeset
for help on using the changeset viewer.