not finished yet, but better than before
[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 Vec3f dir = (ray.origin() + ray.direction() * (ray.t()-Epsilon)) - m_pos;
25 float dist = dir.norm();
26 dir.normalize();
27
28 float c1 = 1, c2 = 0.5, c3 = 0;
29 //float f_att = 1 / (dist*dist);
30 float f_att = 1 / (c1 + c2*dist + c3*dist*dist);
31
32 intensity = m_intensity * f_att;
33
34 // store direction from light to hitpoint
35 ray.setDir(dir);
36 return true;
37 }
38
39 const Vec3f&
40 PointLight::position() const
41 {
42 return m_pos;
43 }
44
45 const Vec3f&
46 PointLight::intensity() const
47 {
48 return m_intensity;
49 }
50
51
This page took 0.061806 seconds and 5 git commands to generate.