DeferredRenderer 1.0
|
00001 #include "PointLight.h" 00002 #include "ngl/ShaderManager.h" 00003 #include "ngl/Types.h" 00004 #include "ngl/TransformStack.h" 00005 #include "ngl/VBOPrimitives.h" 00006 #include "ngl/Util.h" 00007 00008 PointLight::PointLight(){} 00009 PointLight::PointLight(const ngl::Vector &_centre,const float &_radius, const ngl::Vector &_intensity) 00010 { 00011 m_pos.set(_centre.m_x,_centre.m_y,_centre.m_z); 00012 m_radius = _radius; 00013 m_intensity = _intensity; 00014 } 00015 PointLight::~PointLight(){} 00016 00017 bool PointLight::collidesWithSphere(const ngl::Vector &_pos, const float &_radius) 00018 { 00019 ngl::Vector length = m_pos-_pos; 00020 float lengthSq = length.lengthSquared(); 00021 00022 float radiiSq = (m_radius*m_radius) + (_radius*_radius); 00023 00024 return lengthSq < radiiSq; 00025 } 00026 00027 void PointLight::draw(unsigned int &_vao, const std::string &_shaderName) 00028 { 00029 ngl::ShaderManager *shader = ngl::ShaderManager::instance(); 00030 (*shader)[_shaderName]->use(); 00031 00032 shader->setShaderParam3f(_shaderName, 00033 "u_RGBIntensity", 00034 m_intensity.m_x, 00035 m_intensity.m_y, 00036 m_intensity.m_z); 00037 00038 shader->setShaderParam4f(_shaderName, 00039 "u_WSCentreRadius", 00040 m_pos.m_x, 00041 m_pos.m_y, 00042 m_pos.m_z, 00043 m_radius 00044 ); 00045 00046 // now we bind back our vertex array object and draw 00047 glBindVertexArray(_vao); 00048 00049 glDrawArrays(GL_QUADS, 0, 24); 00050 00051 //go back to default just incase 00052 glEnableVertexAttribArray(0); 00053 glBindVertexArray(0); 00054 }