src/rcrt/lights/PointLight.cpp

Go to the documentation of this file.
00001 #include "PointLight.h"
00002 
00003 namespace rcrt
00004 {
00005 
00006 PointLight::PointLight(RGBColor p, Point3D pos):Light(p,1),position(pos)
00007 {
00008 }
00009 
00010 PointLight::~PointLight()
00011 {
00012 }
00013 
00014 const Point3D& PointLight::getPosition() const
00015 {
00016         return position;
00017 }
00018 
00019 LightSample PointLight::illuminate(const Point3D& p, const Vec3D& no) const
00020 {
00021         Vec3D dir(position-p);
00022         float dist = dir.norm();
00023         dir.normalize();
00024         
00025         float A0 = 1;
00026         float A1 = 0.25;
00027         float A2 = 0.001;
00028         
00029         float att = 1.0f / (A0 + A1 * (dist) + A2 * dist * dist); // linear attenuation
00030 //      float att = 1.0f / dist; // linear attenuation
00031                 
00032         return LightSample(1, dir, dist, power*att);
00033         
00034 }
00035 
00036 void PointLight::illuminate(const Point3D& p, const Vec3D& no, std::vector<LightSample>& samples,
00037                         const int& noSamples, Scene* s) const
00038 {
00039         samples.push_back(illuminate(p,no));
00040 }
00041 
00042 RGBColor PointLight::getEmitted(const Vec3D& dir, const Point3D& pos) const
00043 {
00044         return power;
00045 }
00046 
00047 void PointLight::emitPhoton(Photon* photon) const
00048 {
00049         photon->setPos(position);
00050         photon->setPower(power);
00051         float xi1 = float(rand()) / float(RAND_MAX);
00052         float xi2 = float(rand()) / float(RAND_MAX);
00053         float r = sqrt(1.0f - xi1*xi1);
00054         float a = 2.0f*M_PI * xi2;
00055         float xi3 = float(rand()) / float(RAND_MAX);
00056         photon->setDir(Vec3D(r * cos(a), r * sin(a), (xi3 > 0.5 ? -1 : 1)* xi1));
00057 }
00058 
00059 }

Generated on Thu Jan 31 19:26:19 2008 for RenderingCompetitionRayTracer by  doxygen 1.5.3