Changeset 8255 in orxonox.OLD for trunk/src/lib/graphics/light.h
- Timestamp:
- Jun 8, 2006, 3:44:12 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/light.h
r6512 r8255 1 1 /*! 2 3 2 * @file light.h 3 * Handles Lights. 4 4 5 6 7 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 8 */ 9 9 … … 25 25 class Light : public PNode 26 26 { 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 27 public: 28 Light(const TiXmlElement* root = NULL); 29 virtual ~Light(); 30 31 virtual void loadParams(const TiXmlElement* root); 32 33 void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); 34 void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); 35 void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation); 36 void setSpotDirection(const Vector& direction); 37 void setSpotDirection(float x, float y, float z) { setSpotDirection(Vector(x,y,z)); }; 38 void setSpotCutoff(GLfloat cutoff); 39 40 /** @returns the lightNumber*/ 41 int getLightNumber() const {return this->lightNumber;} 42 43 virtual void draw() const; 44 45 void debug() const; 46 47 // attributes 48 private: 49 int lightNumber; //!< The number of this Light. 50 GLfloat diffuseColor[4]; //!< The Diffuse Color this Light emmits. 51 GLfloat specularColor[4]; //!< The specular Color of this Light. 52 float constantAttenuation; //!< The Factor of the the Constant Attenuation. 53 float linearAttenuation; //!< The Factor of the the Linear Attenuation. 54 float quadraticAttenuation; //!< The Factor of the the Quadratic Attenuation. 55 GLfloat spotDirection[4]; //!< The direction of the Spot Light. 56 GLfloat spotCutoff; //!< The cutoff Angle of the Light Source 57 57 }; 58 59 60 58 59 60 61 61 //! A class that handles Lights 62 62 /** 63 63 A Light is a source that emits light rays (photons) 64 64 65 66 67 68 69 65 <b>Usage:</b>\n 66 First you have to get the Light Manager up and running by using LightManager::getInstance(). 67 This automatically initiates the GL_LIGHTING, and sets some default stuff about the light.\n 68 Then you will create a new light using: 69 \li new Light(); 70 70 71 72 71 if you want to operate on this Light just apply the following functions onto it. 72 (You can also optain the Light-pointer with LightManager::getInstance()->getLight(lightNumber)) 73 73 74 75 76 77 78 79 80 74 now you can operate on the light as follows: 75 \li void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); 76 \li void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); 77 \li void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation); 78 \li void setSpotDirection(Vector direction); 79 \li void setSpotCutoff(GLfloat cutoff); 80 \li all PNode stuff also works 81 81 82 83 82 To redraw the light use 83 \li void draw() const; (this is automatically done by the LightManager) 84 84 85 86 85 for some nice output just use: 86 \li void debug() const; (either on LightManager for a resume or on any Light for single information.) 87 87 */ 88 88 class LightManager : public BaseObject 89 {90 89 { 90 friend class Light; 91 91 92 93 94 95 92 public: 93 virtual ~LightManager(); 94 /** @returns a Pointer to the only object of this Class */ 95 inline static LightManager* getInstance() { if (!singletonRef) singletonRef = new LightManager(); return singletonRef; }; 96 96 97 98 97 virtual void loadParams(const TiXmlElement* root); 98 void loadLights(const TiXmlElement* root); 99 99 100 void setAmbientColor(GLfloat r, GLfloat g, GLfloat b); 100 void setAmbientColor(GLfloat r, GLfloat g, GLfloat b); 101 // HACK: Assuming r = g = b values 102 inline GLfloat getAmbientColor() { return this->ambientColor[0]; } 101 103 102 103 104 Light* getLight(int lightNumber) const; 105 inline Light* getLight() const { return this->currentLight; }; 104 106 105 107 void draw() const; 106 108 107 109 void debug() const; 108 110 109 110 111 private: 112 LightManager(); 111 113 112 113 114 int registerLight(Light* light); 115 void unregisterLight(Light* light); 114 116 115 116 117 117 private: 118 static LightManager* singletonRef; //!< This is the LightHandlers Reference. 119 GLfloat ambientColor[4]; //!< The ambient Color of the scene. 118 120 119 120 121 Light** lights; //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues. 122 Light* currentLight; //!< The current Light, we are working with. 121 123 122 124 };
Note: See TracChangeset
for help on using the changeset viewer.