NGL  6.5
The NCCA Graphics Library
ngl::SpotLight Class Reference

Encapsulation of OpenGL spotlight inherits from the Light class. More...

#include <SpotLight.h>

+ Inheritance diagram for ngl::SpotLight:
+ Collaboration diagram for ngl::SpotLight:

Public Member Functions

 SpotLight () noexcept
 default ctor More...
 
 SpotLight (const Vec3 &_pos, const Vec3 &_dir, const Colour &_col) noexcept
 ctor More...
 
 SpotLight (const SpotLight &_l) noexcept
 copy ctor More...
 
void set (const Vec3 &_pos, const Vec3 &_dir, const Colour &_col) noexcept
 a method to set the spotlight parameters More...
 
void enable () noexcept
 enables the spot light More...
 
void setParams (const Real _cutoff, const Real _exponent, const Real _constant, const Real _linear, const Real _quadratic) noexcept
 sets the various spot light params More...
 
void setCutoff (const Real &_cutoff) noexcept
 sets the spot cutoff More...
 
void setInnerCutoff (const Real &_cutoff) noexcept
 sets the spot inner cutoff More...
 
void setExponent (const Real &_exp) noexcept
 sets the exponent More...
 
void aim (const Vec4 &_pos) noexcept
 This function sets the light to aim at the specified point. More...
 
void loadToShader (std::string _uniformName) const noexcept
 this method loads the spotlight values to the shader More...
 
void setTransform (Mat4 &_t) noexcept
 set the transform of the light this will be multiplied by the position Vec4 pos=m_transform*m_position; More...
 
- Public Member Functions inherited from ngl::Light
void setPosition (const Vec3 &_p) noexcept
 set the light position More...
 
void setColour (const Colour &_c) noexcept
 set the light colour More...
 
void setSpecColour (const Colour &_c) noexcept
 set the specular colour More...
 
 Light () noexcept
 default constructor this set nothing so the light will not illuminate More...
 
 Light (const Light &_l) noexcept
 copy ctor this set nothing so the light will not illuminate More...
 
 Light (const Vec3 &_pos, const Colour &_col, LightModes _lightmode) noexcept
 ctor to create the light More...
 
 Light (const Vec3 &_pos, const Colour &_col, const Colour &_specColour, LightModes _lightmode) noexcept
 ctor to create the light More...
 
virtual ~Light () noexcept
 destructor when light is destroyed we turn it off More...
 
void disable () noexcept
 Disable the light by calling glDisable(GL_LIGHT0+LightNo);. More...
 
Vec4 getPos () const noexcept
 returns the current light position as a Vector More...
 
Colour getColour () const noexcept
 returns the current light colour More...
 
Colour getSpecColour () const noexcept
 returns the current light Specular colour More...
 
void setAttenuation (Real _constant=1.0, Real _linear=0.0, Real _quadratic=0.0) noexcept
 set the light attenuation More...
 
void loadToShader (std::string _uniformName) const noexcept
 method to load the current light values to the shader that is active at present More...
 
void setTransform (Mat4 &_t) noexcept
 set a transform so that the light position is multiplied by this value (default is identity matrix) More...
 

Protected Attributes

Real m_innerCutoffAngle
 the spot inner cutoff angle More...
 
Real m_spotExponent
 the SpotExponent value More...
 
Vec4 m_aim
 where the spot is to be aimed More...
 
Vec4 m_dir
 the spot light direction vector More...
 
- Protected Attributes inherited from ngl::Light
Vec4 m_position
 m_pos is used to store the light position w used for point / dir light values More...
 
Colour m_diffuse
 Colour used to give the light a colour. More...
 
Colour m_specular
 specular highlight colour used for the lights More...
 
Colour m_ambient
 ambient light colour used for the lights More...
 
LightModes m_lightMode
 used to hold the current lights mode More...
 
Real m_constantAtten
 attenuation value for constant falloff More...
 
Real m_linearAtten
 attenuation value for linear falloff More...
 
Real m_quadraticAtten
 attenuation value for Quadratic falloff More...
 
bool m_active
 active if true else off More...
 
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)) More...
 
Mat4 m_transform
 the transform applied to the light before loading to the shader this is usually the inverse projection matrix for normal OpenGL style eye-cord calculations but is left for the Application to calculate and pass for easier implementation of different light models More...
 

Detailed Description

Encapsulation of OpenGL spotlight inherits from the Light class.

Definition at line 58 of file SpotLight.h.

Constructor & Destructor Documentation

ngl::SpotLight::SpotLight ( )
inlinenoexcept

default ctor

Definition at line 65 of file SpotLight.h.

ngl::SpotLight::SpotLight ( const Vec3 _pos,
const Vec3 _dir,
const Colour _col 
)
noexcept

ctor

Parameters
[in]_pos- the spot position
[in]_dir- the spot direction
[in]_col- the spot colour

Definition at line 29 of file SpotLight.cpp.

References ngl::SPOTLIGHT.

ngl::SpotLight::SpotLight ( const SpotLight _l)
noexcept

copy ctor

Definition at line 51 of file SpotLight.cpp.

References ngl::SPOTLIGHT.

Member Function Documentation

void ngl::SpotLight::aim ( const Vec4 _pos)
noexcept

This function sets the light to aim at the specified point.

Parameters
[in]_pos- the aim position

Definition at line 84 of file SpotLight.cpp.

References ngl::Vec4::normalize().

+ Here is the call graph for this function:

void ngl::SpotLight::enable ( )
virtualnoexcept

enables the spot light

Reimplemented from ngl::Light.

Definition at line 97 of file SpotLight.cpp.

References ngl::Light::m_active.

void ngl::SpotLight::loadToShader ( std::string  _uniformName) const
noexcept

this method loads the spotlight values to the shader

Parameters
[in]_uniformNamethe uniform base name to load shader values to the struct will be _uniformName.position; _uniformName.direction; _uniformName.ambient; _uniformName.diffuse; _uniformName.specular; _uniformName.spotCosCutoff; _uniformName.spotExponent; _uniformName.constantAttenuation; _uniformName.linearAttenuation; _uniformName.quadraticAttenuation;

struct Lights { vec4 position; vec3 direction; vec4 ambient; vec4 diffuse; vec4 specular; float spotCosCutoff; float constantAttenuation; float linearAttenuation; float quadraticAttenuation; };

Definition at line 121 of file SpotLight.cpp.

References ngl::Singleton< ShaderLib >::instance(), ngl::Colour::m_a, ngl::Light::m_active, ngl::Light::m_ambient, ngl::Colour::m_b, ngl::Light::m_constantAtten, ngl::Light::m_cutoffAngle, ngl::Light::m_diffuse, m_dir, ngl::Colour::m_g, m_innerCutoffAngle, ngl::Light::m_lightMode, ngl::Light::m_linearAtten, ngl::Light::m_position, ngl::Light::m_quadraticAtten, ngl::Colour::m_r, ngl::Light::m_specular, m_spotExponent, ngl::Light::m_transform, ngl::Vec4::m_x, ngl::Vec4::m_y, ngl::Vec4::m_z, ngl::ShaderLib::setShaderParam1f(), ngl::ShaderLib::setShaderParam3f(), and ngl::ShaderLib::setShaderParam4f().

+ Here is the call graph for this function:

void ngl::SpotLight::set ( const Vec3 _pos,
const Vec3 _dir,
const Colour _col 
)
noexcept

a method to set the spotlight parameters

Parameters
[in]_posthe position of the Light
[in]_dirthe direction of the light
[in]_colthe colour of the light

Definition at line 61 of file SpotLight.cpp.

References ngl::SPOTLIGHT.

void ngl::SpotLight::setCutoff ( const Real _cutoff)
noexcept

sets the spot cutoff

Parameters
[in]_cutoffthis is the spot cos cutoff value, we need to calc the cos(radians(_cutoff))

Definition at line 113 of file SpotLight.cpp.

References ngl::Light::m_cutoffAngle, and ngl::radians().

+ Here is the call graph for this function:

void ngl::SpotLight::setExponent ( const Real _exp)
inlinenoexcept

sets the exponent

Parameters
[in]_exponentthe spot exponent vlaue

Definition at line 111 of file SpotLight.h.

void ngl::SpotLight::setInnerCutoff ( const Real _cutoff)
noexcept

sets the spot inner cutoff

Parameters
[in]_cutoffthis is the spot cos cutoff value, we need to calc the cos(radians(_cutoff))

Definition at line 117 of file SpotLight.cpp.

References m_innerCutoffAngle, and ngl::radians().

+ Here is the call graph for this function:

void ngl::SpotLight::setParams ( const Real  _cutoff,
const Real  _exponent,
const Real  _constant,
const Real  _linear,
const Real  _quadratic 
)
noexcept

sets the various spot light params

Parameters
[in]_cutoffthe spot cutoff value
[in]_exponentthe spot exponent vlaue
[in]_constantconstant attenuation value
[in]_linearlinear attenuation value
[in]_quadraticquadratic attenuation value

Definition at line 103 of file SpotLight.cpp.

References ngl::Light::m_constantAtten, ngl::Light::m_cutoffAngle, ngl::Light::m_linearAtten, ngl::Light::m_quadraticAtten, m_spotExponent, and ngl::radians().

+ Here is the call graph for this function:

void ngl::SpotLight::setTransform ( Mat4 _t)
noexcept

set the transform of the light this will be multiplied by the position Vec4 pos=m_transform*m_position;

Parameters
[in]_tthe transform

Definition at line 162 of file SpotLight.cpp.

References ngl::Light::m_transform.

Member Data Documentation

Vec4 ngl::SpotLight::m_aim
protected

where the spot is to be aimed

Definition at line 153 of file SpotLight.h.

Vec4 ngl::SpotLight::m_dir
protected

the spot light direction vector

Definition at line 157 of file SpotLight.h.

Real ngl::SpotLight::m_innerCutoffAngle
protected

the spot inner cutoff angle

Definition at line 145 of file SpotLight.h.

Real ngl::SpotLight::m_spotExponent
protected

the SpotExponent value

Definition at line 149 of file SpotLight.h.


The documentation for this class was generated from the following files: