/** contains the definition of lights **/
 
#include "headers.h"
extern ray_tracer trace;
extern xyz nor;
void point_light::hit_to_light(xyz *hit_point,xyz *light_ray)
{
	light_ray->x=x-(hit_point->x);
	light_ray->y=y-(hit_point->y);
	light_ray->z=z-(hit_point->z);
	light_ray->normalize();
}

double point_light::brightness(void)
{
	return(bright);
}

double area_light::brightness(void)
{
	return(bright);
}

xyz area_light::calc_brightness(int y,int x,xyz *hit_point,int samples)
{

xyz u,v,pnts,ray;
double magu,magv,cellu,cellv,intensity=1;

u.x=pntb.x-pnta.x;
u.y=pntb.y-pnta.y;
u.z=pntb.z-pnta.z;
v.x=pntc.x-pntb.x;
v.y=pntc.y-pntb.y;
v.z=pntc.z-pntb.z;

//cout<<"u x "<<u.x<<"\n";
//cout<<"u y "<<u.y<<"\n";
//cout<<"u z "<<u.z<<"\n\n";
//cout<<"v x "<<v.x<<"\n";
//cout<<"v y "<<v.y<<"\n";
//cout<<"v z "<<v.z<<"\n\n";

magu=u.normalize();
magv=v.normalize();

cellu=magu/samples;
cellv=magv/samples;

pnts.x = pnta.x+((x*cellu+cellu/2)*u.x)+((y*cellv+cellv/2)*v.x);
pnts.y = pnta.y+((x*cellu+cellu/2)*u.y)+((y*cellv+cellv/2)*v.y);
pnts.z = pnta.z+((x*cellu+cellu/2)*u.z)+((y*cellv+cellv/2)*v.z);

ray=pnts - (*hit_point);
ray.normalize();
return(ray);
}

xyz point_light::calc_brightness(int y,int x,xyz *hit_point,int samples)
{
	xyz temp;
	return(temp);
}

void area_light::hit_to_light(xyz *hit_point,xyz *light_ray)
{

}
