glc_light.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
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:
00192 
00193         // Disable the light
00194         void disable();
00195 
00197         virtual void glExecute();
00199 
00201 
00203 
00204 
00205 private:
00206 
00207 
00209 
00211 // Private services fonction
00213 private:
00215         void addNewLight();
00216 
00218         void removeThisLight();
00219 
00221 // Private Members
00223 private:
00225         GLenum m_LightID;
00226 
00228         LightType m_LightType;
00229 
00231         QColor m_AmbientColor;
00233         QColor m_DiffuseColor;
00235         QColor m_SpecularColor;
00236 
00238         GLC_Point3d m_Position;
00239 
00241         GLC_Vector3d m_SpotDirection;
00242 
00244         GLfloat m_SpotExponent;
00245 
00247         GLfloat m_SpotCutoffAngle;
00248 
00250         GLfloat m_ConstantAttenuation;
00251 
00253         GLfloat m_LinearAttenuation;
00254 
00256         GLfloat m_QuadraticAttenuation;
00257 
00259         bool m_TwoSided;
00260 
00261         // Static member
00263         static GLint m_MaxLight;
00264 
00266         QGLContext* m_pContext;
00267 
00269         bool m_IsValid;
00270 
00272         static QHash<const QGLContext*, QSet<GLenum> > m_ContextToFreeLightSet;
00273 };
00274 #endif //GLC_LIGHT_H_

SourceForge.net Logo

©2005-2011 Laurent Ribon