/*! \file light.h \brief Handles Lights. A Light is one of the more important things in a 3D-environment, without it one sees nothing :) It is here for diffuse-, specular- and Bump-Mappings. */ #ifndef _LIGHT_H #define _LIGHT_H #include "p_node.h" #include "glincl.h" //! The maximum number of Lights this OpenGL-implementation supports. #define NUMBEROFLIGHTS GL_MAX_LIGHTS // FORWARD DEFINITIONS // class Vector; class TiXmlElement; //! A class that handles Lights. The LightManager operates on this. class Light : public PNode { public: Light(const TiXmlElement* root = NULL); virtual ~Light(void); void init(); void loadParams(const TiXmlElement* root); void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation); void setSpotDirection(const Vector& direction); void setSpotDirection(float x, float y, float z) { setSpotDirection(Vector(x,y,z)); }; void setSpotCutoff(GLfloat cutoff); /** \returns the lightNumber*/ int getLightNumber(void) const {return this->lightNumber;} virtual void draw() const; void debug(void) const; // attributes private: int lightNumber; //!< The number of this Light. GLfloat diffuseColor[4]; //!< The Diffuse Color this Light emmits. GLfloat specularColor[4]; //!< The specular Color of this Light. float constantAttenuation; //!< The Factor of the the Constant Attenuation. float linearAttenuation; //!< The Factor of the the Linear Attenuation. float quadraticAttenuation; //!< The Factor of the the Quadratic Attenuation. GLfloat spotDirection[4]; //!< The direction of the Spot Light. GLfloat spotCutoff; //!< The cutoff Angle of the Light Source }; //! A class that handles Lights /** A Light is a source that emits light rays (photons) Usage:\n First you have to get the Light Manager up and running by using LightManager::getInstance(). This automatically initiates the GL_LIGHTING, and sets some default stuff about the light.\n Then you will create a new light using: \li new Light(); now you can operate on the light as follows: \li void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); \li void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); \li void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation); \li void setSpotDirection(Vector direction); \li void setSpotCutoff(GLfloat cutoff); \li all PNode stuff also works To redraw the light use \li void draw() const; and to delete one just use \li void deleteLight(void); for some nice output just use: \li void debug(void) const; You can also operate on the single Lights themselves, by first retreaving them with \li Light* getLight(int LightNumber) const; \n and then using the same functions on this to change settings. */ class LightManager : public BaseObject { friend class Light; public: virtual ~LightManager(void); /** \returns a Pointer to the only object of this Class */ inline static LightManager* getInstance(void) { if (!singletonRef) singletonRef = new LightManager(); return singletonRef; }; void loadParams(const TiXmlElement* root); void loadLights(const TiXmlElement* root); void setAmbientColor(GLfloat r, GLfloat g, GLfloat b); Light* getLight(int lightNumber) const; inline Light* getLight() const { return this->currentLight; }; void draw() const; void debug(void) const; private: LightManager(void); int registerLight(Light* light); void unregisterLight(Light* light); private: static LightManager* singletonRef; //!< This is the LightHandlers Reference. GLfloat ambientColor[4]; //!< The ambient Color of the scene. Light** lights; //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues. Light* currentLight; //!< The current Light, we are working with. }; #endif /* _LIGHT_H */