2efe585a8466b41fad76cfdedb6226a031b9d58e
[MicroTrace.git] / PointLight.cxx
1 #include "PointLight.hxx"
2
3 PointLight::PointLight(Scene* scene, const Vec3f& pos, const Vec3f& intensity)
4 : Light(scene),
5 m_pos(pos),
6 m_intensity(intensity)
7 {
8 }
9
10 PointLight::~PointLight()
11 {
12 }
13
14 PointLight::PointLight()
15 : Light(0),
16 m_pos(Vec3f()),
17 m_intensity(Vec3f())
18 {
19 }
20
21 bool
22 PointLight::Illuminate(Ray& ray, Vec3f& intensity)
23 {
24 float dist = ((ray.origin() + ray.direction() * ray.t()) - m_pos).norm();
25
26 float c1 = 1, c2 = 0.5, c3 = 0;
27 float f_att = 1 / (c1 + c2*dist + c3*dist*dist);
28
29 intensity = m_intensity * f_att;
30
31 // store direction from light to hitpoint
32 ray.setDir(ray.origin() + ray.direction() * (ray.t()-Epsilon) - m_pos);
33 return true;
34 }
35
36 const Vec3f&
37 PointLight::position() const
38 {
39 return m_pos;
40 }
41
42 const Vec3f&
43 PointLight::intensity() const
44 {
45 return m_intensity;
46 }
47
48
This page took 0.043352 seconds and 3 git commands to generate.