[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. |
---|
[3453] | 45 | float attenuationFactor; //!< The Factor the attenuation should have. |
---|
| 46 | GLfloat spotDirection[4]; //!< The direction of the Spot Light. |
---|
| 47 | GLfloat spotCutoff; //!< The cutoff Angle of the Light Source |
---|
[3437] | 48 | }; |
---|
| 49 | |
---|
| 50 | static Light* singletonRef; //!< This is the LightHandlers Reference. |
---|
[3440] | 51 | GLfloat ambientColor[4]; //!< The ambient Color of the scene. |
---|
| 52 | |
---|
| 53 | |
---|
[3437] | 54 | Light(void); |
---|
| 55 | |
---|
| 56 | void init(int LightNumber); |
---|
[3446] | 57 | LightValue** lights; //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues. |
---|
| 58 | LightValue* currentLight; //!< The current Light, we are working with. |
---|
[3436] | 59 | |
---|
[1904] | 60 | public: |
---|
[3437] | 61 | static Light* getInstance(); |
---|
[3543] | 62 | virtual ~Light(void); |
---|
[1853] | 63 | |
---|
[3436] | 64 | // set Attributes |
---|
[3437] | 65 | int addLight(void); |
---|
| 66 | int addLight(int lightNumber); |
---|
| 67 | void editLightNumber(int lightNumber); |
---|
| 68 | void deleteLight(void); |
---|
| 69 | void deleteLight(int lightNumber); |
---|
| 70 | |
---|
[3436] | 71 | void setPosition(Vector position); |
---|
[3437] | 72 | void setPosition(GLfloat x, GLfloat y, GLfloat z); |
---|
[3436] | 73 | void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); |
---|
| 74 | void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); |
---|
[3441] | 75 | void setAttenuation(AttenuationType type, float factor); |
---|
[3440] | 76 | void setAmbientColor(GLfloat r, GLfloat g, GLfloat b); |
---|
[3453] | 77 | void setSpotDirection(Vector direction); |
---|
| 78 | void setSpotCutoff(GLfloat cutoff); |
---|
| 79 | |
---|
[3436] | 80 | // get Attributes |
---|
| 81 | Vector getPosition(void); |
---|
[3446] | 82 | /** |
---|
| 83 | \returns the Position of Light |
---|
| 84 | \param lightNumber lightnumber |
---|
| 85 | */ |
---|
[3444] | 86 | inline Vector getPosition(int lightNumber) |
---|
| 87 | { |
---|
| 88 | if (!this->lights[lightNumber]) |
---|
| 89 | return Vector(.0,.0,.0); |
---|
| 90 | return Vector(this->lights[lightNumber]->lightPosition[0], |
---|
| 91 | this->lights[lightNumber]->lightPosition[1], |
---|
| 92 | this->lights[lightNumber]->lightPosition[2]); |
---|
| 93 | } |
---|
[3442] | 94 | |
---|
| 95 | void debug(void); |
---|
[1853] | 96 | }; |
---|
| 97 | |
---|
[3436] | 98 | #endif /* _LIGHT_H */ |
---|