[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 | |
---|
[3436] | 19 | // FORWARD DEFINITIONS // |
---|
| 20 | class Vector; |
---|
[2036] | 21 | |
---|
[3597] | 22 | //! A struct that holds information about a Light |
---|
| 23 | class Light : public WorldEntity |
---|
| 24 | { |
---|
| 25 | public: |
---|
| 26 | Light(int lightNumber); |
---|
| 27 | ~Light(void); |
---|
| 28 | |
---|
| 29 | void setPosition(Vector position); |
---|
| 30 | void setPosition(GLfloat x, GLfloat y, GLfloat z); |
---|
| 31 | void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); |
---|
| 32 | void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); |
---|
| 33 | void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation); |
---|
| 34 | void setSpotDirection(Vector direction); |
---|
| 35 | void setSpotCutoff(GLfloat cutoff); |
---|
| 36 | |
---|
| 37 | virtual void draw(); |
---|
| 38 | |
---|
| 39 | // attributes |
---|
| 40 | |
---|
| 41 | int lightNumber; //!< The number of this Light. |
---|
| 42 | GLfloat lightPosition[4]; //!< The Position of this Light. |
---|
| 43 | GLfloat diffuseColor[4]; //!< The Diffuse Color this Light emmits. |
---|
| 44 | GLfloat specularColor[4]; //!< The specular Color of this Light. |
---|
| 45 | float constantAttenuation; //!< The Factor of the the Constant Attenuation. |
---|
| 46 | float linearAttenuation; //!< The Factor of the the Linear Attenuation. |
---|
| 47 | float quadraticAttenuation; //!< The Factor of the the Quadratic Attenuation. |
---|
| 48 | GLfloat spotDirection[4]; //!< The direction of the Spot Light. |
---|
| 49 | GLfloat spotCutoff; //!< The cutoff Angle of the Light Source |
---|
| 50 | |
---|
| 51 | void debug(void); |
---|
| 52 | }; |
---|
| 53 | |
---|
[3436] | 54 | //! A class that handles Lights |
---|
[3329] | 55 | /** |
---|
[3436] | 56 | A Light is a source that emits light rays (photons) |
---|
[3329] | 57 | */ |
---|
[3597] | 58 | class LightManager : public BaseObject |
---|
[3436] | 59 | { |
---|
[3437] | 60 | private: |
---|
[3597] | 61 | LightManager(void); |
---|
| 62 | void initLight(int LightNumber); |
---|
| 63 | |
---|
| 64 | static LightManager* singletonRef; //!< This is the LightHandlers Reference. |
---|
[3440] | 65 | GLfloat ambientColor[4]; //!< The ambient Color of the scene. |
---|
| 66 | |
---|
[3597] | 67 | Light** lights; //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues. |
---|
| 68 | Light* currentLight; //!< The current Light, we are working with. |
---|
[3436] | 69 | |
---|
[1904] | 70 | public: |
---|
[3597] | 71 | static LightManager* getInstance(); |
---|
| 72 | virtual ~LightManager(void); |
---|
[1853] | 73 | |
---|
[3436] | 74 | // set Attributes |
---|
[3437] | 75 | int addLight(void); |
---|
| 76 | int addLight(int lightNumber); |
---|
| 77 | void editLightNumber(int lightNumber); |
---|
| 78 | void deleteLight(void); |
---|
| 79 | void deleteLight(int lightNumber); |
---|
| 80 | |
---|
[3597] | 81 | void setAmbientColor(GLfloat r, GLfloat g, GLfloat b); |
---|
| 82 | |
---|
| 83 | //set Attributes |
---|
[3436] | 84 | void setPosition(Vector position); |
---|
[3437] | 85 | void setPosition(GLfloat x, GLfloat y, GLfloat z); |
---|
[3436] | 86 | void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); |
---|
| 87 | void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); |
---|
[3597] | 88 | void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation); |
---|
[3453] | 89 | void setSpotDirection(Vector direction); |
---|
| 90 | void setSpotCutoff(GLfloat cutoff); |
---|
| 91 | |
---|
[3436] | 92 | // get Attributes |
---|
| 93 | Vector getPosition(void); |
---|
[3446] | 94 | /** |
---|
| 95 | \returns the Position of Light |
---|
| 96 | \param lightNumber lightnumber |
---|
| 97 | */ |
---|
[3444] | 98 | inline Vector getPosition(int lightNumber) |
---|
| 99 | { |
---|
| 100 | if (!this->lights[lightNumber]) |
---|
| 101 | return Vector(.0,.0,.0); |
---|
| 102 | return Vector(this->lights[lightNumber]->lightPosition[0], |
---|
| 103 | this->lights[lightNumber]->lightPosition[1], |
---|
| 104 | this->lights[lightNumber]->lightPosition[2]); |
---|
| 105 | } |
---|
[3442] | 106 | |
---|
| 107 | void debug(void); |
---|
[1853] | 108 | }; |
---|
| 109 | |
---|
[3436] | 110 | #endif /* _LIGHT_H */ |
---|