rayzor

view src/light.cc @ 17:79609d482762

the renderer renders, also fixed an unnoticed matrix conversion problem between scenegraph and min3d
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 14 Apr 2014 07:34:45 +0300
parents d94a69933a71
children 859ccadca671
line source
1 #include "light.h"
3 Light::Light()
4 {
5 type = NODE_LIGHT;
6 intens = 1.0;
7 color.x = color.y = color.z = 1.0;
8 atten.x = 1.0;
9 atten.y = 0.0;
10 atten.z = 0.0;
11 }
13 void Light::set_intensity(float val)
14 {
15 intens = val;
16 }
18 float Light::get_intensity() const
19 {
20 return intens;
21 }
23 void Light::set_color(const Vector3 &color)
24 {
25 this->color = color;
26 }
28 const Vector3 &Light::get_color() const
29 {
30 return color;
31 }
33 Vector3 Light::get_color(const Vector3 &pt) const
34 {
35 float d = (get_position() - pt).length();
36 return color * calc_attenuation(d) * intens;
37 }
39 void Light::set_attenuation(const Vector3 &atten)
40 {
41 this->atten = atten;
42 }
44 const Vector3 &Light::get_attenuation() const
45 {
46 return atten;
47 }
49 float Light::calc_attenuation(float d) const
50 {
51 float denom = atten.x + atten.y * d + atten.z * d * d;
52 float at = denom == 0.0 ? 1.0 : 1.0 / denom;
53 return at > 1.0 ? 1.0 : at;
54 }
56 void Light::draw() const
57 {
58 }
60 bool Light::intersect(const Ray &ray, RayHit *hit) const
61 {
62 return false; // TODO
63 }