#include <cmath>
+#include <cstdlib>
#include "QuadAreaLight.hxx"
{
m_n = m_e1.cross(m_e2);
m_area = m_n.norm();
- m_n.normalize();
+ m_n.normalize();
}
QuadAreaLight::QuadAreaLight()
bool
QuadAreaLight::Illuminate(Ray& shadow_ray, Vec3f& intensity)
{
- // generate random factors
+ // generate random factors
float xi1 = drand48();
float xi2 = drand48();
-
+
// bilinear interpolation of position
Vec3f pos = m_p0 + m_e1 * xi1 + m_e2* xi2;
// direction of shadow ray
Vec3f dir = pos-shadow_ray.origin();
-
+
float dist = dir.norm();
float cosN = (dir.dot(m_n)) / dist;
if(cosN <= 0.0f )
return false;
-
+
// squared falloff and projected area
intensity = m_intensity * ( m_area * cosN / ( dist*dist));