rayzor

annotate src/light.cc @ 22:5380ff64e83f

minor changes from dos, and line endings cleanup
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 02 May 2014 14:32:58 +0300
parents 79609d482762
children
rev   line source
nuclear@1 1 #include "light.h"
nuclear@1 2
nuclear@1 3 Light::Light()
nuclear@1 4 {
nuclear@12 5 type = NODE_LIGHT;
nuclear@17 6 intens = 1.0;
nuclear@1 7 color.x = color.y = color.z = 1.0;
nuclear@1 8 atten.x = 1.0;
nuclear@1 9 atten.y = 0.0;
nuclear@1 10 atten.z = 0.0;
nuclear@1 11 }
nuclear@1 12
nuclear@17 13 void Light::set_intensity(float val)
nuclear@17 14 {
nuclear@17 15 intens = val;
nuclear@17 16 }
nuclear@17 17
nuclear@17 18 float Light::get_intensity() const
nuclear@17 19 {
nuclear@17 20 return intens;
nuclear@17 21 }
nuclear@17 22
nuclear@1 23 void Light::set_color(const Vector3 &color)
nuclear@1 24 {
nuclear@1 25 this->color = color;
nuclear@1 26 }
nuclear@1 27
nuclear@1 28 const Vector3 &Light::get_color() const
nuclear@1 29 {
nuclear@1 30 return color;
nuclear@1 31 }
nuclear@1 32
nuclear@17 33 Vector3 Light::get_color(const Vector3 &pt) const
nuclear@17 34 {
nuclear@17 35 float d = (get_position() - pt).length();
nuclear@17 36 return color * calc_attenuation(d) * intens;
nuclear@17 37 }
nuclear@1 38
nuclear@1 39 void Light::set_attenuation(const Vector3 &atten)
nuclear@1 40 {
nuclear@1 41 this->atten = atten;
nuclear@1 42 }
nuclear@1 43
nuclear@1 44 const Vector3 &Light::get_attenuation() const
nuclear@1 45 {
nuclear@1 46 return atten;
nuclear@1 47 }
nuclear@12 48
nuclear@17 49 float Light::calc_attenuation(float d) const
nuclear@17 50 {
nuclear@17 51 float denom = atten.x + atten.y * d + atten.z * d * d;
nuclear@17 52 float at = denom == 0.0 ? 1.0 : 1.0 / denom;
nuclear@17 53 return at > 1.0 ? 1.0 : at;
nuclear@17 54 }
nuclear@17 55
nuclear@18 56 void Light::draw(bool emph) const
nuclear@12 57 {
nuclear@12 58 }
nuclear@12 59
nuclear@17 60 bool Light::intersect(const Ray &ray, RayHit *hit) const
nuclear@12 61 {
nuclear@17 62 return false; // TODO
nuclear@12 63 }