| [3245] | 1 | /*!  | 
|---|
| [3436] | 2 |     \file light.h | 
|---|
 | 3 |     \brief Handles Lights. | 
|---|
| [3329] | 4 |  | 
|---|
| [3436] | 5 |     A Light is one of the more important things in a 3D-environment, | 
|---|
 | 6 |     without it one sees nothing :) | 
|---|
 | 7 |     It is here for diffuse-, specular- and Bump-Mappings. | 
|---|
| [3245] | 8 | */ | 
|---|
| [1853] | 9 |  | 
|---|
| [3436] | 10 | #ifndef _LIGHT_H | 
|---|
 | 11 | #define _LIGHT_H | 
|---|
| [1853] | 12 |  | 
|---|
| [3436] | 13 | #include "world_entity.h" | 
|---|
 | 14 | #include "glincl.h" | 
|---|
| [1853] | 15 |  | 
|---|
| [3446] | 16 | //! The maximum number of Lights this OpenGL-implementation supports | 
|---|
| [3437] | 17 | #define NUMBEROFLIGHTS GL_MAX_LIGHTS | 
|---|
 | 18 |  | 
|---|
| [3446] | 19 | //! Enumerator for the attenuation-Type. | 
|---|
 | 20 | /** | 
|---|
 | 21 |    CONSTANT means GL_CONSTANT_ATTENUATION | 
|---|
 | 22 |    LINEAR means   GL_LINEAR_ATTENUATION | 
|---|
 | 23 |    QUADRATIC means GL_QUADRATIC_ATTENUATION | 
|---|
 | 24 | */ | 
|---|
| [3441] | 25 | enum AttenuationType {CONSTANT, LINEAR, QUADRATIC}; | 
|---|
 | 26 |  | 
|---|
| [3436] | 27 | // FORWARD DEFINITIONS // | 
|---|
 | 28 | class Vector; | 
|---|
| [2036] | 29 |  | 
|---|
| [3436] | 30 | //! A class that handles Lights | 
|---|
| [3329] | 31 | /** | 
|---|
| [3436] | 32 |    A Light is a source that emits light rays (photons) | 
|---|
| [3329] | 33 | */ | 
|---|
| [3437] | 34 | class Light : public WorldEntity | 
|---|
| [3436] | 35 | { | 
|---|
| [3437] | 36 |  private: | 
|---|
 | 37 |   //! A struct that holds information about a Light | 
|---|
 | 38 |   struct LightValue | 
|---|
 | 39 |   { | 
|---|
 | 40 |     int lightNumber;            //!< The number of this Light. | 
|---|
 | 41 |     GLfloat lightPosition[4];   //!< The Position of this Light. | 
|---|
 | 42 |     GLfloat diffuseColor[4];    //!< The Diffuse Color this Light emmits. | 
|---|
 | 43 |     GLfloat specularColor[4];   //!< The specular Color of this Light. | 
|---|
| [3441] | 44 |     AttenuationType attenuationType;//!< The AttenuationType of this Light. | 
|---|
 | 45 |     float attenuationFactor;    //!< the Factor the attenuation should have. | 
|---|
| [3437] | 46 |   }; | 
|---|
 | 47 |  | 
|---|
 | 48 |   static Light* singletonRef;    //!< This is the LightHandlers Reference. | 
|---|
| [3440] | 49 |   GLfloat ambientColor[4];       //!< The ambient Color of the scene. | 
|---|
 | 50 |  | 
|---|
 | 51 |  | 
|---|
| [3437] | 52 |   Light(void); | 
|---|
 | 53 |  | 
|---|
 | 54 |   void init(int LightNumber);   | 
|---|
| [3446] | 55 |   LightValue** lights;           //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues. | 
|---|
 | 56 |   LightValue* currentLight;      //!< The current Light, we are working with. | 
|---|
| [3436] | 57 |    | 
|---|
| [1904] | 58 |  public: | 
|---|
| [3437] | 59 |   static Light* getInstance(); | 
|---|
| [3436] | 60 |   ~Light(void); | 
|---|
| [1853] | 61 |  | 
|---|
| [3436] | 62 |   // set Attributes | 
|---|
| [3437] | 63 |   int addLight(void); | 
|---|
 | 64 |   int addLight(int lightNumber); | 
|---|
 | 65 |   void editLightNumber(int lightNumber); | 
|---|
 | 66 |   void deleteLight(void); | 
|---|
 | 67 |   void deleteLight(int lightNumber); | 
|---|
 | 68 |  | 
|---|
| [3436] | 69 |   void setPosition(Vector position); | 
|---|
| [3437] | 70 |   void setPosition(GLfloat x, GLfloat y, GLfloat z); | 
|---|
| [3436] | 71 |   void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); | 
|---|
 | 72 |   void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); | 
|---|
| [3441] | 73 |   void setAttenuation(AttenuationType type, float factor); | 
|---|
| [3440] | 74 |   void setAmbientColor(GLfloat r, GLfloat g, GLfloat b); | 
|---|
| [3436] | 75 |   // get Attributes | 
|---|
 | 76 |   Vector getPosition(void); | 
|---|
| [3446] | 77 |   /** | 
|---|
 | 78 |      \returns the Position of Light  | 
|---|
 | 79 |      \param lightNumber lightnumber | 
|---|
 | 80 |   */ | 
|---|
| [3444] | 81 |   inline Vector getPosition(int lightNumber) | 
|---|
 | 82 |     { | 
|---|
 | 83 |       if (!this->lights[lightNumber]) | 
|---|
 | 84 |         return Vector(.0,.0,.0); | 
|---|
 | 85 |       return Vector(this->lights[lightNumber]->lightPosition[0], | 
|---|
 | 86 |                     this->lights[lightNumber]->lightPosition[1], | 
|---|
 | 87 |                     this->lights[lightNumber]->lightPosition[2]); | 
|---|
 | 88 |     } | 
|---|
| [3442] | 89 |  | 
|---|
 | 90 |   void debug(void); | 
|---|
| [1853] | 91 | }; | 
|---|
 | 92 |  | 
|---|
| [3436] | 93 | #endif /* _LIGHT_H */ | 
|---|