1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
const CColor CSimpleScene::computeLightColor(const CVector3f& view, const CPoint3f& center, const CNormal3f& normal,
const CMaterial& caracteristics)
{
CColor t_color(0, 0, 0);
//go throught all the lights
for(vector<CLight*>::iterator i = m_lights.begin(); i != m_lights.end(); i++)
{
//get a ray from the object to the light
CVector3f L(0, 0, 0);
L = (*i)->getCenter() - center; //vector from the point of the object to the light
float pathLength = L.norme();
L.normalize();
CRay ray(center, L); //ray from the object to the light
//check if there is something between the object and the light
if(!testCollision(ray, pathLength)) //no collision
{
//LAMBERT
float LdotN = L.dot(normal);
if(LdotN > 0.f)
{
t_color += (*i)->getColor()*caracteristics.m_diffuse*LdotN;
}
}
}
//AMBIENT
t_color += caracteristics.m_ambient*0.2f;
return t_color;
} |
Partager