// GeomObj.cpp: implementation of the GeomObj class.
//
//////////////////////////////////////////////////////////////////////

#include "GeomObj.h"


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

GeomObj::GeomObj()
{
	next=NULL;
}

// Color3 methods
void Color3::set(float r, float g, float b)
	{red = r; green = g; blue = b;}
void Color3::set(const Color3 c)
	{red = c.red; green = c.green; blue = c.blue;}

Color3 Color3::operator*(float c){
	Color3 newColor;
	newColor.set(red*c, green*c, blue*c);
	return newColor;
}
Color3 Color3::operator*(const Color3& c){
	Color3 newColor;
	newColor.set(red*c.red, green*c.green, blue*c.blue);
	return newColor;
}

void Color3::add(float r, float g, float b)
      {red += r; green += g; blue += b;}
void Color3::add(const Color3& src, const Color3& refl)
{ // add the product of source color and reflection coefficient
	red   += src.red   * refl.red;
	green += src.green * refl.green;
	blue  += src.blue  * refl.blue;
}

void Color3::add(const Color3& colr)
{ // add colr to this color
	red += colr.red ; green += colr.green; blue += colr.blue;}

void Color3::build4tuple(float v[])
{// load 4-tuple with this color: v[3] = 1 for homogeneous
	v[0] = red; v[1] = green; v[2] = blue; v[3] = 1.0f;
}

// Material methods
void Material::setDefault(){
	textureType = 0; // for none
	numParams = 0;
	reflectivity = transparency = 0.0;
	speedOfLight = specularExponent = 1.0;
	specularFraction = 0.0;
	surfaceRoughness = 1.0;
	ambient.set(0.1f,0.1f,0.1f);
	diffuse.set(0.8f,0.8f,0.8f);
	specular.set(0,0,0);
	emissive.set(0,0,0);
}
void Material::set(Material& m)
{
	textureType = m.textureType;
	numParams = m.numParams;
	for(int i = 0; i < numParams; i++) params[i] = m.params[i];
	transparency = m.transparency;
	speedOfLight = m.speedOfLight;
	reflectivity = m.reflectivity;
	specularExponent = m.specularExponent;
	specularFraction = m.specularFraction;
	surfaceRoughness = m.surfaceRoughness;
	ambient.set(m.ambient);
	diffuse.set(m.diffuse);
	specular.set(m.specular);
	emissive.set(m.emissive);
}
