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 ) const
00040 {
00041
00042 Ray ray;
00043 dir = mPosition - org;
00044 float length = dir.length() - EPSILON;
00045 dir.normalize();
00046 ray.init(org, dir, length);
00047
00048
00049 if (mScene->castShadows() && mScene->intersect(ray) && ray.hit()->castShadows() && ray.t() > EPSILON)
00050 return RGBAColor(0, 0, 0, 1);
00051
00052
00053
00054 float att = 1.0f / (length * length);
00055 return RGBAColor(att * mIntensity.rgb());
00056 }
00057
00058 private:
00060 Vec3f mPosition;
00061
00063 RGBAColor mIntensity;
00064 };
00065
00066 #endif