glc_light.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00025 #ifndef GLC_LIGHT_H_
00026 #define GLC_LIGHT_H_
00027
00028 #include <QColor>
00029 #include <QSet>
00030 #include <QHash>
00031
00032 #include "../glc_object.h"
00033 #include "../maths/glc_vector3d.h"
00034
00035 #include "../glc_config.h"
00036
00037 class QGLContext;
00038
00041
00045
00046
00047 class GLC_LIB_EXPORT GLC_Light : public GLC_Object
00048 {
00049 public:
00051 enum LightType
00052 {
00053 LightPosition= 0,
00054 LightDirection= 1,
00055 LightSpot= 2
00056 };
00058
00060
00061 public:
00063
00064 GLC_Light(const QGLContext* pContext= NULL, const QColor& color= Qt::white);
00065
00067
00068 GLC_Light(LightType lightType, const QGLContext* pContext= NULL, const QColor& color= Qt::white);
00069
00071 GLC_Light(const GLC_Light& light);
00072
00074 virtual ~GLC_Light(void);
00076
00078
00080
00081 public:
00083 static int maxLightCount();
00084
00086 static int builtAbleLightCount(QGLContext* pContext);
00087
00089 inline GLC_Point3d position(void) const
00090 {return m_Position;}
00091
00093 inline QColor ambientColor() const
00094 {return m_AmbientColor;}
00095
00097 inline QColor diffuseColor() const
00098 { return m_DiffuseColor;}
00099
00101 inline QColor specularColor() const
00102 {return m_SpecularColor;}
00103
00105 inline bool isTwoSided() const
00106 {return m_TwoSided;}
00107
00109 inline LightType type() const
00110 {return m_LightType;}
00111
00113 inline GLenum openglID() const
00114 {return m_LightID;}
00115
00117 inline GLfloat constantAttenuation() const
00118 {return m_ConstantAttenuation;}
00119
00121 inline GLfloat linearAttenuation() const
00122 {return m_LinearAttenuation;}
00123
00125 inline GLfloat quadraticAttenuation() const
00126 {return m_QuadraticAttenuation;}
00127
00129 inline GLC_Vector3d spotDirection() const
00130 {return m_SpotDirection;}
00131
00133 inline GLfloat spotCutoffAngle() const
00134 {return m_SpotCutoffAngle;}
00135
00137 inline GLfloat spotEponent() const
00138 {return m_SpotExponent;}
00140
00142
00144
00145 public:
00147 void initForThisContext();
00148
00150 void setPosition(const GLC_Point3d &pos);
00151
00153 void setPosition(GLfloat x, GLfloat y, GLfloat z);
00154
00156 void setAmbientColor(const QColor &color);
00157
00159 void setDiffuseColor(const QColor &color);
00160
00162 void setSpecularColor(const QColor &color);
00163
00165 void setTwoSided(const bool mode);
00166
00168 void setConstantAttenuation(GLfloat constantAttenuation);
00169
00171 void setLinearAttenuation(GLfloat linearAttenuation);
00172
00174 void setQuadraticAttenuation(GLfloat quadraticAttenuation);
00175
00177 void setSpotDirection(const GLC_Vector3d& direction);
00178
00180 void setSpotCutoffAngle(GLfloat cutoffAngle);
00181
00183 void setSpotEponent(GLfloat exponent);
00184
00186
00188
00190
00191 public:
00193 void enable();
00194
00195
00196 void disable();
00197
00199 virtual void glExecute(GLenum Mode= GL_COMPILE_AND_EXECUTE);
00201
00203
00205
00206
00207 private:
00209 void glDraw();
00210
00212 void creationList(GLenum Mode);
00213
00215 void deleteList();
00216
00218
00220
00222 private:
00224 void addNewLight();
00225
00227 void removeThisLight();
00228
00230
00232 private:
00234 GLenum m_LightID;
00235
00237 LightType m_LightType;
00238
00240 GLuint m_ListID;
00241
00243 bool m_ListIsValid;
00244
00246 QColor m_AmbientColor;
00248 QColor m_DiffuseColor;
00250 QColor m_SpecularColor;
00251
00253 GLC_Point3d m_Position;
00254
00256 GLC_Vector3d m_SpotDirection;
00257
00259 GLfloat m_SpotExponent;
00260
00262 GLfloat m_SpotCutoffAngle;
00263
00265 GLfloat m_ConstantAttenuation;
00266
00268 GLfloat m_LinearAttenuation;
00269
00271 GLfloat m_QuadraticAttenuation;
00272
00274 bool m_TwoSided;
00275
00276
00278 static GLint m_MaxLight;
00279
00281 QGLContext* m_pContext;
00282
00284 static QHash<const QGLContext*, QSet<GLenum> > m_ContextToFreeLightSet;
00285 };
00286 #endif //GLC_LIGHT_H_