src/PointLight.h

Go to the documentation of this file.
00001 #ifndef POINTLIGHT_H
00002 #define POINTLIGHT_H
00003 
00004 #include "Light.h"
00005 
00006 
00012 class PointLight : public Light
00013 {
00014 public:
00020     PointLight( const RGBAColor &   intensity,
00021                 const Vec3f &       position )
00022         : Light(),
00023             mPosition(position),
00024             mIntensity(intensity)
00025     {
00026     }
00027 
00030     void setNumberOfRays(unsigned int) {}
00031 
00039     RGBAColor illuminate(Vec3f & dir, const Vec3f & org, unsigned int /*index = 0*/) const
00040     {
00041         // ray points towards point light position from the surface
00042         Ray ray;
00043         dir = mPosition - org;
00044         float length = dir.length() - EPSILON;
00045         dir.normalize();
00046         ray.init(org, dir, length);
00047 
00048         // check for occlusion
00049         if (mScene->castShadows() && mScene->intersect(ray) && ray.hit()->castShadows() && ray.t() > EPSILON)
00050             return RGBAColor(0, 0, 0, 1);
00051 
00052         // compute linear attenuation
00053         // see http://www.gamasutra.com/features/20050729/lacroix_01.shtml
00054         float att = 1.0f / (length * length); // linear attenuation
00055         return RGBAColor(att * mIntensity.rgb());
00056     }
00057     
00058 private:
00060     Vec3f       mPosition;
00061 
00063     RGBAColor   mIntensity;
00064 };
00065 
00066 #endif

Generated on Fri Feb 1 00:01:42 2008 for Grayfall by  doxygen 1.5.1