1 #ifndef POINTLIGHT_HXX
 2 #define POINTLIGHT_HXX
 3 
 4 #include "Light.hxx"
 5 
 6 class PointLight : public Light
 7 {
 8 public:
 9   Vec3f position;  // origin
10   Vec3f intensity; // emission (red, green, blue)
11 
12   PointLight(Scene *scene, Vec3f position, Vec3f intensity)
13     : Light(scene),position(position),intensity(intensity)
14   {};  
15 
16   virtual bool Illuminate(Ray &ray, Vec3f &intensity)
17   {
18     /* ray towards point light position */
19     
20     ray.dir = position - ray.org;
21     ray.hit = NULL;
22     ray.t   = Length(ray.dir) - Epsilon; // maximal ray length
23     Normalize(ray.dir);
24     
25     /* return attenuated intensity */
26 
27     //float sqrtDist = ray.t * ray.t;
28     
29     //float attenuation = 1.0f / sqrtDist; 
30     float attenuation = 1.0f / (0.5f* ray.t + 1.0f); // linear attenuation
31     intensity = attenuation * this->intensity;
32 
33     return true;
34   };
35 };
36 
37 #endif


syntax highlighted by Code2HTML, v. 0.9.1