DeferredRenderer 1.0
|
Spotlight for deferred lighting. More...
#include <SpotLight.h>
Public Member Functions | |
SpotLight () | |
SpotLight (const ngl::Vector &_position, const ngl::Vector &_target, const float &_distance, const float &_angle, const ngl::Vector &_col, const ngl::Vector &_up) | |
ctor | |
~SpotLight () | |
void | set (const ngl::Vector &_position, const ngl::Vector &_target, const float &_distance, const float &_angle, const ngl::Vector &_col, const ngl::Vector &_up) |
set method for the lights values | |
bool | collidesWithSphere (const ngl::Vector &_pos, const float &_rad) |
check for collision with sphere | |
void | draw (const std::string &_vaoName, const std::string &_shader) |
method for drawing the spotlight | |
ngl::Matrix | getView () |
access the light view matrix | |
ngl::Matrix | getWorld () |
acces the light world matrix | |
Protected Attributes | |
ngl::Camera | m_matrixCam |
a temporary use of ngl camera for shadow matrices | |
ngl::Matrix | m_lightView |
the lights view matrix | |
Private Attributes | |
float | m_radius |
radius of spotlight for near plane clipping | |
ngl::Matrix | m_world |
world matrix of spotlight | |
ngl::Vector | m_positionAngle |
the position [xyz] and angle [w] of light | |
ngl::Vector | m_directionDistance |
the direction [xyz] and distance [w] of light | |
ngl::Vector | m_colour |
the light colour |
Spotlight for deferred lighting.
Definition at line 15 of file SpotLight.h.
SpotLight::SpotLight | ( | ) | [inline] |
Definition at line 19 of file SpotLight.h.
{}
SpotLight::SpotLight | ( | const ngl::Vector & | _position, |
const ngl::Vector & | _target, | ||
const float & | _distance, | ||
const float & | _angle, | ||
const ngl::Vector & | _col, | ||
const ngl::Vector & | _up | ||
) |
ctor
[in] | _position | the light pos |
[in] | _target | the light lookat pos |
[in] | _distance | the reach of the light |
[in] | _angle | the cone angle |
[in] | _col | the light colour |
[in] | _up | the apporximated up vector |
Definition at line 13 of file SpotLight.cpp.
{
this->set(_position,_target,_distance,_angle,_col,_up);
}
SpotLight::~SpotLight | ( | ) |
Definition at line 18 of file SpotLight.cpp.
{}
bool SpotLight::collidesWithSphere | ( | const ngl::Vector & | _pos, |
const float & | _rad | ||
) |
check for collision with sphere
[in] | _pos | sphere position |
[in] | _radius | sphere radius |
Definition at line 20 of file SpotLight.cpp.
References m_directionDistance.
{ float radius = m_directionDistance.m_w * 0.5; ngl::Vector centre = ngl::Vector(m_directionDistance.m_x, m_directionDistance.m_y, m_directionDistance.m_z) * (m_directionDistance.m_w * 0.5); ngl::Vector length = centre-_pos; float lengthSq = length.lengthSquared(); float radiiSq = (radius*radius)*1.5 /*scale up to avoid nasty culling */ + (_rad*_rad); return lengthSq < radiiSq; }
void SpotLight::draw | ( | const std::string & | _vaoName, |
const std::string & | _shader | ||
) |
method for drawing the spotlight
[in] | _vaoName | the ngl vboPrimitive of spotlight geometry |
[in] | _shaderName | the name of the shader to draw with |
Definition at line 34 of file SpotLight.cpp.
References m_colour, m_directionDistance, m_positionAngle, and m_world.
{ ngl::ShaderManager *shader = ngl::ShaderManager::instance(); (*shader)[_shader]->use(); shader->setShaderParamFromMatrix(_shader, "u_ModelMatrix", m_world); shader->setShaderParamFromVector(_shader, "a_PositionAngle", m_positionAngle); shader->setShaderParamFromVector(_shader, "a_DirectionDistance", m_directionDistance); shader->setShaderParamFromVector(_shader, "a_Colour", m_colour); ngl::VBOPrimitives *prim = ngl::VBOPrimitives::instance(); prim->draw(_vaoName); }
ngl::Matrix SpotLight::getView | ( | ) | [inline] |
access the light view matrix
Definition at line 53 of file SpotLight.h.
References m_lightView.
{return m_lightView;}
ngl::Matrix SpotLight::getWorld | ( | ) | [inline] |
acces the light world matrix
Definition at line 56 of file SpotLight.h.
References m_world.
{return m_world;}
void SpotLight::set | ( | const ngl::Vector & | _position, |
const ngl::Vector & | _target, | ||
const float & | _distance, | ||
const float & | _angle, | ||
const ngl::Vector & | _col, | ||
const ngl::Vector & | _up | ||
) |
set method for the lights values
[in] | _position | the light pos |
[in] | _target | the light lookat pos |
[in] | _distance | the reach of the light |
[in] | _angle | the cone angle |
[in] | _col | the light colour |
[in] | _up | the apporximated up vector |
Definition at line 49 of file SpotLight.cpp.
References Inverse(), Lookat(), m_colour, m_directionDistance, m_lightView, m_matrixCam, m_positionAngle, and m_world.
{ const float xyscale = _distance*sinf( ( _angle*.5)*ngl::PI/180 ) * 1.1f; // Scaling up to avoid hard edges eating the light ngl::Matrix scale, invView, trans; scale.scale(xyscale,xyscale,_distance); m_matrixCam = ngl::Camera(_position, _target, _up, ngl::PERSPECTIVE); m_lightView = Lookat(_position,_target,_up); invView = Inverse(m_lightView); //magic number to get ngl cone into position trans.translate(0,0,-1); m_world = invView * scale * trans; ngl::Vector direction = _target-_position; direction.normalize(); m_positionAngle = _position; m_positionAngle.m_w=cos( ( _angle*.5)*ngl::PI/180 ); m_directionDistance = direction; m_directionDistance.m_w=_distance; m_colour = _col; }
ngl::Vector SpotLight::m_colour [private] |
the light colour
Definition at line 81 of file SpotLight.h.
ngl::Vector SpotLight::m_directionDistance [private] |
the direction [xyz] and distance [w] of light
Definition at line 78 of file SpotLight.h.
ngl::Matrix SpotLight::m_lightView [protected] |
the lights view matrix
Definition at line 64 of file SpotLight.h.
ngl::Camera SpotLight::m_matrixCam [protected] |
a temporary use of ngl camera for shadow matrices
Definition at line 61 of file SpotLight.h.
ngl::Vector SpotLight::m_positionAngle [private] |
the position [xyz] and angle [w] of light
Definition at line 75 of file SpotLight.h.
float SpotLight::m_radius [private] |
radius of spotlight for near plane clipping
Definition at line 69 of file SpotLight.h.
ngl::Matrix SpotLight::m_world [private] |
world matrix of spotlight
Definition at line 72 of file SpotLight.h.