rayzor
diff 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 diff
1.1 --- a/src/light.cc Sun Apr 13 09:54:51 2014 +0300 1.2 +++ b/src/light.cc Mon Apr 14 07:34:45 2014 +0300 1.3 @@ -3,12 +3,23 @@ 1.4 Light::Light() 1.5 { 1.6 type = NODE_LIGHT; 1.7 + intens = 1.0; 1.8 color.x = color.y = color.z = 1.0; 1.9 atten.x = 1.0; 1.10 atten.y = 0.0; 1.11 atten.z = 0.0; 1.12 } 1.13 1.14 +void Light::set_intensity(float val) 1.15 +{ 1.16 + intens = val; 1.17 +} 1.18 + 1.19 +float Light::get_intensity() const 1.20 +{ 1.21 + return intens; 1.22 +} 1.23 + 1.24 void Light::set_color(const Vector3 &color) 1.25 { 1.26 this->color = color; 1.27 @@ -19,6 +30,11 @@ 1.28 return color; 1.29 } 1.30 1.31 +Vector3 Light::get_color(const Vector3 &pt) const 1.32 +{ 1.33 + float d = (get_position() - pt).length(); 1.34 + return color * calc_attenuation(d) * intens; 1.35 +} 1.36 1.37 void Light::set_attenuation(const Vector3 &atten) 1.38 { 1.39 @@ -30,11 +46,18 @@ 1.40 return atten; 1.41 } 1.42 1.43 +float Light::calc_attenuation(float d) const 1.44 +{ 1.45 + float denom = atten.x + atten.y * d + atten.z * d * d; 1.46 + float at = denom == 0.0 ? 1.0 : 1.0 / denom; 1.47 + return at > 1.0 ? 1.0 : at; 1.48 +} 1.49 + 1.50 void Light::draw() const 1.51 { 1.52 } 1.53 1.54 -bool Light::intersect(const Ray &ray, float *dist) 1.55 +bool Light::intersect(const Ray &ray, RayHit *hit) const 1.56 { 1.57 - return false; 1.58 + return false; // TODO 1.59 }