1 | /*! |
---|
2 | \file light.h |
---|
3 | \brief Handles Lights. |
---|
4 | |
---|
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 | */ |
---|
9 | |
---|
10 | #ifndef _LIGHT_H |
---|
11 | #define _LIGHT_H |
---|
12 | |
---|
13 | #include "world_entity.h" |
---|
14 | #include "glincl.h" |
---|
15 | |
---|
16 | //! The maximum number of Lights this OpenGL-implementation supports |
---|
17 | #define NUMBEROFLIGHTS GL_MAX_LIGHTS |
---|
18 | |
---|
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 | */ |
---|
25 | enum AttenuationType {CONSTANT, LINEAR, QUADRATIC}; |
---|
26 | |
---|
27 | // FORWARD DEFINITIONS // |
---|
28 | class Vector; |
---|
29 | |
---|
30 | //! A class that handles Lights |
---|
31 | /** |
---|
32 | A Light is a source that emits light rays (photons) |
---|
33 | */ |
---|
34 | class Light : public BaseObject |
---|
35 | { |
---|
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. |
---|
44 | AttenuationType attenuationType;//!< The AttenuationType of this Light. |
---|
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 |
---|
48 | }; |
---|
49 | |
---|
50 | static Light* singletonRef; //!< This is the LightHandlers Reference. |
---|
51 | GLfloat ambientColor[4]; //!< The ambient Color of the scene. |
---|
52 | |
---|
53 | |
---|
54 | Light(void); |
---|
55 | |
---|
56 | void init(int LightNumber); |
---|
57 | LightValue** lights; //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues. |
---|
58 | LightValue* currentLight; //!< The current Light, we are working with. |
---|
59 | |
---|
60 | public: |
---|
61 | static Light* getInstance(); |
---|
62 | virtual ~Light(void); |
---|
63 | |
---|
64 | // set Attributes |
---|
65 | int addLight(void); |
---|
66 | int addLight(int lightNumber); |
---|
67 | void editLightNumber(int lightNumber); |
---|
68 | void deleteLight(void); |
---|
69 | void deleteLight(int lightNumber); |
---|
70 | |
---|
71 | void setPosition(Vector position); |
---|
72 | void setPosition(GLfloat x, GLfloat y, GLfloat z); |
---|
73 | void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); |
---|
74 | void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); |
---|
75 | void setAttenuation(AttenuationType type, float factor); |
---|
76 | void setAmbientColor(GLfloat r, GLfloat g, GLfloat b); |
---|
77 | void setSpotDirection(Vector direction); |
---|
78 | void setSpotCutoff(GLfloat cutoff); |
---|
79 | |
---|
80 | // get Attributes |
---|
81 | Vector getPosition(void); |
---|
82 | /** |
---|
83 | \returns the Position of Light |
---|
84 | \param lightNumber lightnumber |
---|
85 | */ |
---|
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 | } |
---|
94 | |
---|
95 | void debug(void); |
---|
96 | }; |
---|
97 | |
---|
98 | #endif /* _LIGHT_H */ |
---|