DeferredRenderer 1.0

PointLight Class Reference

Deferred PointLight class using simple geometry to send to the GPU for per-pixel lighting. More...

#include <PointLight.h>

List of all members.

Public Member Functions

 PointLight ()
 ctor
 PointLight (const ngl::Vector &_centre, const float &_radius, const ngl::Vector &_intensity)
 ctor taking the radius, centre and intensity colour of light
 ~PointLight ()
 dtor
void draw (unsigned int &_vao, const std::string &_shaderName)
 method for drawing the pointlight
bool collidesWithSphere (const ngl::Vector &_pos, const float &_radius)
 check for collision with sphere

Public Attributes

ngl::Vector m_pos
 the light position, public for easier access

Private Attributes

float m_radius
 the light radius
ngl::Vector m_intensity
 the light colour intensity

Detailed Description

Deferred PointLight class using simple geometry to send to the GPU for per-pixel lighting.

Definition at line 13 of file PointLight.h.


Constructor & Destructor Documentation

PointLight::PointLight ( )

ctor

Definition at line 8 of file PointLight.cpp.

{}
PointLight::PointLight ( const ngl::Vector &  _centre,
const float &  _radius,
const ngl::Vector &  _intensity 
)

ctor taking the radius, centre and intensity colour of light

Parameters:
[in]_centrethe world space position of light
[in]_radiusthe extent of lights influence
[in]_intensitythe colour value of the light

Definition at line 9 of file PointLight.cpp.

References m_intensity, m_pos, and m_radius.

{
    m_pos.set(_centre.m_x,_centre.m_y,_centre.m_z);
    m_radius = _radius;
    m_intensity = _intensity;
}
PointLight::~PointLight ( )

dtor

Definition at line 15 of file PointLight.cpp.

{}

Member Function Documentation

bool PointLight::collidesWithSphere ( const ngl::Vector &  _pos,
const float &  _radius 
)

check for collision with sphere

Parameters:
[in]_possphere position
[in]_radiussphere radius

Definition at line 17 of file PointLight.cpp.

References m_pos, and m_radius.

{
    ngl::Vector length = m_pos-_pos;
    float lengthSq = length.lengthSquared();

    float radiiSq = (m_radius*m_radius) + (_radius*_radius);

    return lengthSq < radiiSq;
}
void PointLight::draw ( unsigned int &  _vao,
const std::string &  _shaderName 
)

method for drawing the pointlight

Parameters:
[in]_vaothe vao id of pointlight geometry
[in]_shaderNamethe name of the shader to draw with

Definition at line 27 of file PointLight.cpp.

References m_intensity, m_pos, and m_radius.

{
    ngl::ShaderManager *shader = ngl::ShaderManager::instance();
    (*shader)[_shaderName]->use();

    shader->setShaderParam3f(_shaderName,
                             "u_RGBIntensity",
                             m_intensity.m_x,
                             m_intensity.m_y,
                             m_intensity.m_z);

    shader->setShaderParam4f(_shaderName,
                             "u_WSCentreRadius",
                             m_pos.m_x,
                             m_pos.m_y,
                             m_pos.m_z,
                             m_radius
                             );

    // now we bind back our vertex array object and draw
    glBindVertexArray(_vao);

    glDrawArrays(GL_QUADS, 0, 24);

     //go back to default just incase
    glEnableVertexAttribArray(0);
    glBindVertexArray(0);
}

Member Data Documentation

ngl::Vector PointLight::m_intensity [private]

the light colour intensity

Definition at line 45 of file PointLight.h.

ngl::Vector PointLight::m_pos

the light position, public for easier access

Definition at line 39 of file PointLight.h.

float PointLight::m_radius [private]

the light radius

Definition at line 42 of file PointLight.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines