NGL  6.5
The NCCA Graphics Library
Light.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Jon Macey
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef LIGHT_H_
18 #define LIGHT_H_
19 // must include types.h first for Real and GLEW if required
22 #include "Types.h"
23 #include "Colour.h"
24 #include "Vec4.h"
25 #include "Vec3.h"
26 #include "Mat4.h"
27 #include <string>
28 
29 
30 namespace ngl
31 {
32 //----------------------------------------------------------------------------------------------------------------------
38 //----------------------------------------------------------------------------------------------------------------------
39 // for c++ 11 use enum class LIGHTMODES : int
40 enum class LightModes : char
41  {
43  POINTLIGHT,
44  SPOTLIGHT=1
45  };
46 
47 
48 //----------------------------------------------------------------------------------------------------------------------
65 //----------------------------------------------------------------------------------------------------------------------
66 
67 
69 {
70 public:
71 
72  //----------------------------------------------------------------------------------------------------------------------
75  //----------------------------------------------------------------------------------------------------------------------
76  void setPosition( const Vec3& _p ) noexcept
77  {
78  m_position.set(_p.m_x,_p.m_y,_p.m_z,static_cast<Real>(m_lightMode));
79  }
80 
81  //----------------------------------------------------------------------------------------------------------------------
84  //----------------------------------------------------------------------------------------------------------------------
85  void setColour(const Colour& _c) noexcept
86  {
87  m_diffuse.set(_c);
88  }
89 
90  //----------------------------------------------------------------------------------------------------------------------
93  //----------------------------------------------------------------------------------------------------------------------
94  void setSpecColour(const Colour& _c ) noexcept
95  {
96  m_specular.set(_c);
97  }
98 
99  //----------------------------------------------------------------------------------------------------------------------
102  //----------------------------------------------------------------------------------------------------------------------
103  Light() noexcept{;}
104  //----------------------------------------------------------------------------------------------------------------------
107  //----------------------------------------------------------------------------------------------------------------------
108  Light(const Light &_l) noexcept;
109  //----------------------------------------------------------------------------------------------------------------------
114  //----------------------------------------------------------------------------------------------------------------------
115  Light( const Vec3& _pos, const Colour& _col, LightModes _lightmode ) noexcept;
116  //----------------------------------------------------------------------------------------------------------------------
122  //----------------------------------------------------------------------------------------------------------------------
123  Light(const Vec3& _pos, const Colour& _col,const Colour& _specColour,LightModes _lightmode) noexcept;
124  //----------------------------------------------------------------------------------------------------------------------
127  //----------------------------------------------------------------------------------------------------------------------
128  virtual ~Light() noexcept{;}
129  //----------------------------------------------------------------------------------------------------------------------
131  //----------------------------------------------------------------------------------------------------------------------
132  void disable() noexcept;
133  //----------------------------------------------------------------------------------------------------------------------
136  //----------------------------------------------------------------------------------------------------------------------
137  virtual void enable() noexcept;
138  //----------------------------------------------------------------------------------------------------------------------
141  //----------------------------------------------------------------------------------------------------------------------
142  Vec4 getPos()const noexcept{return m_position; }
143  //----------------------------------------------------------------------------------------------------------------------
146  //----------------------------------------------------------------------------------------------------------------------
147  Colour getColour()const noexcept{ return m_diffuse; }
148  //----------------------------------------------------------------------------------------------------------------------
151  //----------------------------------------------------------------------------------------------------------------------
152  Colour getSpecColour() const noexcept{ return m_specular; }
153  //----------------------------------------------------------------------------------------------------------------------
158  //----------------------------------------------------------------------------------------------------------------------
159  void setAttenuation(Real _constant=1.0, Real _linear=0.0, Real _quadratic=0.0 ) noexcept;
160  //----------------------------------------------------------------------------------------------------------------------
163  //----------------------------------------------------------------------------------------------------------------------
164  void loadToShader(std::string _uniformName )const noexcept;
165  //----------------------------------------------------------------------------------------------------------------------
168  //----------------------------------------------------------------------------------------------------------------------
169  void setTransform( Mat4 &_t ) noexcept;
170 protected :
171  //----------------------------------------------------------------------------------------------------------------------
173  //----------------------------------------------------------------------------------------------------------------------
175  //----------------------------------------------------------------------------------------------------------------------
177  //----------------------------------------------------------------------------------------------------------------------
179  //----------------------------------------------------------------------------------------------------------------------
181  //----------------------------------------------------------------------------------------------------------------------
183  //----------------------------------------------------------------------------------------------------------------------
185  //----------------------------------------------------------------------------------------------------------------------
187  //----------------------------------------------------------------------------------------------------------------------
189  //----------------------------------------------------------------------------------------------------------------------
191  //----------------------------------------------------------------------------------------------------------------------
193  //----------------------------------------------------------------------------------------------------------------------
195  //----------------------------------------------------------------------------------------------------------------------
197  //----------------------------------------------------------------------------------------------------------------------
199  //----------------------------------------------------------------------------------------------------------------------
201  //----------------------------------------------------------------------------------------------------------------------
203  //----------------------------------------------------------------------------------------------------------------------
205  //----------------------------------------------------------------------------------------------------------------------
206  bool m_active;
207  //----------------------------------------------------------------------------------------------------------------------
210  //----------------------------------------------------------------------------------------------------------------------
212  //----------------------------------------------------------------------------------------------------------------------
216  //----------------------------------------------------------------------------------------------------------------------
218 
219 
220 private:
221 
222 
223 }; // end class
224 
225 }// end namespace
226 
227 #endif // __LIGHT__
228 
229 //----------------------------------------------------------------------------------------------------------------------
230 
231 
232 
233 
bool m_active
active if true else off
Definition: Light.h:206
GLboolean enable
Definition: glew.h:2748
Real m_linearAtten
attenuation value for linear falloff
Definition: Light.h:198
void setColour(const Colour &_c) noexcept
set the light colour
Definition: Light.h:85
Real m_cutoffAngle
the spot cutoff angle for directional and point lights this is set to 180 by default, and other values are cos(radians(angle))
Definition: Light.h:211
Real m_constantAtten
attenuation value for constant falloff
Definition: Light.h:194
simple class to hold colour information and set the basic opengl colour state. also has overloaded me...
Definition: Colour.h:40
simple Vector class for OpenGL graphics, contains overloaded operators for most math functions...
Definition: Vec4.h:57
Vec4 m_position
m_pos is used to store the light position w used for point / dir light values
Definition: Light.h:174
a simple colour class for RGBA colour
main definition of types and namespace
#define NGL_DLLEXPORT
Definition: Types.h:65
Simple class to encapsulate OpenGL Light functions this will fill in the following structure...
Definition: Light.h:68
simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths a...
Definition: Vec3.h:51
Colour getSpecColour() const noexcept
returns the current light Specular colour
Definition: Light.h:152
implementation files for RibExport class
Definition: AABB.cpp:22
Colour getColour() const noexcept
returns the current light colour
Definition: Light.h:147
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Definition: Types.h:127
encapsulates a 4d Homogenous Point / Vector object
a simple 3 tuple container for compatibility with glsl
void setSpecColour(const Colour &_c) noexcept
set the specular colour
Definition: Light.h:94
Colour m_ambient
ambient light colour used for the lights
Definition: Light.h:186
Colour m_diffuse
Colour used to give the light a colour.
Definition: Light.h:178
Colour m_specular
specular highlight colour used for the lights
Definition: Light.h:182
Light() noexcept
default constructor this set nothing so the light will not illuminate
Definition: Light.h:103
void setPosition(const Vec3 &_p) noexcept
set the light position
Definition: Light.h:76
Matrix Class to do simple matrix operations included operator overloaded functions for maths and matr...
Definition: Mat4.h:58
Vec4 getPos() const noexcept
returns the current light position as a Vector
Definition: Light.h:142
directional light from old OPenGL
GLsizei const GLchar *const * string
Definition: glew.h:1847
Mat4 m_transform
the transform applied to the light before loading to the shader this is usually the inverse projectio...
Definition: Light.h:217
Real m_quadraticAtten
attenuation value for Quadratic falloff
Definition: Light.h:202
LightModes m_lightMode
used to hold the current lights mode
Definition: Light.h:190
LightModes
Definition: Light.h:40
virtual ~Light() noexcept
destructor when light is destroyed we turn it off
Definition: Light.h:128