[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 | |
---|
[4338] | 13 | #include "p_node.h" |
---|
[3436] | 14 | #include "glincl.h" |
---|
[1853] | 15 | |
---|
[3598] | 16 | //! The maximum number of Lights this OpenGL-implementation supports. |
---|
[3437] | 17 | #define NUMBEROFLIGHTS GL_MAX_LIGHTS |
---|
| 18 | |
---|
[4469] | 19 | |
---|
[3436] | 20 | // FORWARD DEFINITIONS // |
---|
| 21 | class Vector; |
---|
[2036] | 22 | |
---|
[4469] | 23 | |
---|
[3598] | 24 | //! A class that handles Lights. The LightManager operates on this. |
---|
[4338] | 25 | class Light : public PNode |
---|
[3597] | 26 | { |
---|
| 27 | public: |
---|
| 28 | Light(int lightNumber); |
---|
[3598] | 29 | virtual ~Light(void); |
---|
[3597] | 30 | |
---|
| 31 | void setPosition(Vector position); |
---|
| 32 | void setPosition(GLfloat x, GLfloat y, GLfloat z); |
---|
[4469] | 33 | Vector getPosition() const; |
---|
| 34 | |
---|
[3597] | 35 | void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); |
---|
| 36 | void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); |
---|
| 37 | void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation); |
---|
| 38 | void setSpotDirection(Vector direction); |
---|
| 39 | void setSpotCutoff(GLfloat cutoff); |
---|
| 40 | |
---|
[3598] | 41 | /** \returns the lightNumber*/ |
---|
[3600] | 42 | int getLightNumber(void) const {return this->lightNumber;} |
---|
[3598] | 43 | |
---|
[3597] | 44 | virtual void draw(); |
---|
| 45 | |
---|
[3600] | 46 | void debug(void) const; |
---|
[3598] | 47 | |
---|
[3597] | 48 | // attributes |
---|
[3598] | 49 | private: |
---|
[4469] | 50 | int lightNumber; //!< The number of this Light. |
---|
| 51 | GLfloat lightPosition[4]; //!< The Position of this Light. |
---|
| 52 | GLfloat diffuseColor[4]; //!< The Diffuse Color this Light emmits. |
---|
| 53 | GLfloat specularColor[4]; //!< The specular Color of this Light. |
---|
| 54 | float constantAttenuation; //!< The Factor of the the Constant Attenuation. |
---|
| 55 | float linearAttenuation; //!< The Factor of the the Linear Attenuation. |
---|
| 56 | float quadraticAttenuation; //!< The Factor of the the Quadratic Attenuation. |
---|
| 57 | GLfloat spotDirection[4]; //!< The direction of the Spot Light. |
---|
| 58 | GLfloat spotCutoff; //!< The cutoff Angle of the Light Source |
---|
[3597] | 59 | }; |
---|
| 60 | |
---|
[4469] | 61 | |
---|
| 62 | |
---|
[3436] | 63 | //! A class that handles Lights |
---|
[3329] | 64 | /** |
---|
[3436] | 65 | A Light is a source that emits light rays (photons) |
---|
[3600] | 66 | |
---|
| 67 | <b>Usage:</b>\n |
---|
| 68 | First you have to get the Light Manager up and running by using LightManager::getInstance. |
---|
| 69 | This automatically initiates the GL_LIGHTING, and sets some default stuff about the light.\n |
---|
| 70 | Then you will create a new light using: |
---|
| 71 | \li int addLight(void); |
---|
| 72 | \li int addLight(int lightNumber); |
---|
| 73 | |
---|
| 74 | 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 | \li void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); |
---|
| 78 | \li void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); |
---|
| 79 | \li void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation); |
---|
| 80 | \li void setSpotDirection(Vector direction); |
---|
| 81 | \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; |
---|
| 88 | |
---|
| 89 | To redraw the light use |
---|
| 90 | \li void draw(); |
---|
| 91 | |
---|
| 92 | and to delete one just use |
---|
| 93 | \li void deleteLight(void); |
---|
| 94 | |
---|
| 95 | for some nice output just use: |
---|
| 96 | \li void debug(void) const; |
---|
| 97 | |
---|
| 98 | You can also operate on the single Lights themselves, by first retreaving them with |
---|
| 99 | \li Light* getLight(int LightNumber); |
---|
| 100 | \n |
---|
| 101 | and then using the same functions on this to change settings. |
---|
[3329] | 102 | */ |
---|
[3597] | 103 | class LightManager : public BaseObject |
---|
[3436] | 104 | { |
---|
[3440] | 105 | |
---|
[1904] | 106 | public: |
---|
[4469] | 107 | virtual ~LightManager(void); |
---|
[4519] | 108 | /** \returns a Pointer to the only object of this Class */ |
---|
| 109 | inline static LightManager* getInstance(void) { if (!singletonRef) singletonRef = new LightManager(); return singletonRef; }; |
---|
[1853] | 110 | |
---|
[3436] | 111 | // set Attributes |
---|
[3437] | 112 | int addLight(void); |
---|
| 113 | int addLight(int lightNumber); |
---|
| 114 | void editLightNumber(int lightNumber); |
---|
| 115 | void deleteLight(void); |
---|
| 116 | void deleteLight(int lightNumber); |
---|
| 117 | |
---|
[3597] | 118 | void setAmbientColor(GLfloat r, GLfloat g, GLfloat b); |
---|
| 119 | |
---|
[3598] | 120 | void draw(); |
---|
| 121 | |
---|
[3597] | 122 | //set Attributes |
---|
[3436] | 123 | void setPosition(Vector position); |
---|
[3437] | 124 | void setPosition(GLfloat x, GLfloat y, GLfloat z); |
---|
[3436] | 125 | void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); |
---|
| 126 | void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); |
---|
[3597] | 127 | void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation); |
---|
[3453] | 128 | void setSpotDirection(Vector direction); |
---|
| 129 | void setSpotCutoff(GLfloat cutoff); |
---|
| 130 | |
---|
[3436] | 131 | // get Attributes |
---|
[3600] | 132 | Vector getPosition(void) const; |
---|
| 133 | Vector getPosition(int lightNumber) const; |
---|
[3598] | 134 | |
---|
[3600] | 135 | Light* getLight(int lightNumber) const; |
---|
| 136 | |
---|
| 137 | void debug(void) const; |
---|
[4469] | 138 | |
---|
| 139 | |
---|
| 140 | private: |
---|
| 141 | LightManager(void); |
---|
| 142 | void initLight(int LightNumber); |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | private: |
---|
| 146 | static LightManager* singletonRef; //!< This is the LightHandlers Reference. |
---|
| 147 | GLfloat ambientColor[4]; //!< The ambient Color of the scene. |
---|
| 148 | |
---|
| 149 | Light** lights; //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues. |
---|
| 150 | Light* currentLight; //!< The current Light, we are working with. |
---|
| 151 | |
---|
[1853] | 152 | }; |
---|
| 153 | |
---|
[3436] | 154 | #endif /* _LIGHT_H */ |
---|