| 1 | /*!  | 
|---|
| 2 |     \file light.h | 
|---|
| 3 |     \brief Handles Lights. | 
|---|
| 4 |  | 
|---|
| 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. | 
|---|
| 8 | */ | 
|---|
| 9 |  | 
|---|
| 10 | #ifndef _LIGHT_H | 
|---|
| 11 | #define _LIGHT_H | 
|---|
| 12 |  | 
|---|
| 13 | #include "world_entity.h" | 
|---|
| 14 | #include "glincl.h" | 
|---|
| 15 |  | 
|---|
| 16 | //! The maximum number of Lights this OpenGL-implementation supports | 
|---|
| 17 | #define NUMBEROFLIGHTS GL_MAX_LIGHTS | 
|---|
| 18 |  | 
|---|
| 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 | */ | 
|---|
| 25 | enum AttenuationType {CONSTANT, LINEAR, QUADRATIC}; | 
|---|
| 26 |  | 
|---|
| 27 | // FORWARD DEFINITIONS // | 
|---|
| 28 | class Vector; | 
|---|
| 29 |  | 
|---|
| 30 | //! A class that handles Lights | 
|---|
| 31 | /** | 
|---|
| 32 |    A Light is a source that emits light rays (photons) | 
|---|
| 33 | */ | 
|---|
| 34 | class Light : public WorldEntity | 
|---|
| 35 | { | 
|---|
| 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. | 
|---|
| 44 |     AttenuationType attenuationType;//!< The AttenuationType of this Light. | 
|---|
| 45 |     float attenuationFactor;    //!< the Factor the attenuation should have. | 
|---|
| 46 |   }; | 
|---|
| 47 |  | 
|---|
| 48 |   static Light* singletonRef;    //!< This is the LightHandlers Reference. | 
|---|
| 49 |   GLfloat ambientColor[4];       //!< The ambient Color of the scene. | 
|---|
| 50 |  | 
|---|
| 51 |  | 
|---|
| 52 |   Light(void); | 
|---|
| 53 |  | 
|---|
| 54 |   void init(int LightNumber);   | 
|---|
| 55 |   LightValue** lights;           //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues. | 
|---|
| 56 |   LightValue* currentLight;      //!< The current Light, we are working with. | 
|---|
| 57 |    | 
|---|
| 58 |  public: | 
|---|
| 59 |   static Light* getInstance(); | 
|---|
| 60 |   ~Light(void); | 
|---|
| 61 |  | 
|---|
| 62 |   // set Attributes | 
|---|
| 63 |   int addLight(void); | 
|---|
| 64 |   int addLight(int lightNumber); | 
|---|
| 65 |   void editLightNumber(int lightNumber); | 
|---|
| 66 |   void deleteLight(void); | 
|---|
| 67 |   void deleteLight(int lightNumber); | 
|---|
| 68 |  | 
|---|
| 69 |   void setPosition(Vector position); | 
|---|
| 70 |   void setPosition(GLfloat x, GLfloat y, GLfloat z); | 
|---|
| 71 |   void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); | 
|---|
| 72 |   void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); | 
|---|
| 73 |   void setAttenuation(AttenuationType type, float factor); | 
|---|
| 74 |   void setAmbientColor(GLfloat r, GLfloat g, GLfloat b); | 
|---|
| 75 |   // get Attributes | 
|---|
| 76 |   Vector getPosition(void); | 
|---|
| 77 |   /** | 
|---|
| 78 |      \returns the Position of Light  | 
|---|
| 79 |      \param lightNumber lightnumber | 
|---|
| 80 |   */ | 
|---|
| 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 |     } | 
|---|
| 89 |  | 
|---|
| 90 |   void debug(void); | 
|---|
| 91 | }; | 
|---|
| 92 |  | 
|---|
| 93 | #endif /* _LIGHT_H */ | 
|---|