#include "Polygon3D.h"

Polygon3D::Polygon3D() : _indices{ 0 }, _uvIndices { 0 }
{
	_depth = 0.0f;
	_r = 0;
	_g = 0;
	_b = 0;
	_culled = false;
}

Polygon3D::Polygon3D(int index0, int index1, int index2, int uvIndex0, int uvIndex1, int uvIndex2)
{
	_indices[0] = index0;
	_indices[1] = index1;
	_indices[2] = index2;

	_uvIndices[0] = uvIndex0;
	_uvIndices[1] = uvIndex1;
	_uvIndices[2] = uvIndex2;

	_depth = 0.0f;

	_r = 0;
	_g = 0;
	_b = 0;

	_culled = false;
}

Polygon3D::Polygon3D(const Polygon3D& other)
{
	Copy(other);
}

Polygon3D::~Polygon3D()
{
	
}

size_t Polygon3D::GetPolygonVertexCount() const
{
	return sizeof(_indices) / sizeof(_indices[0]);
}

size_t Polygon3D::GetPolygonUVCount() const
{
	return sizeof(_uvIndices) / sizeof(_uvIndices[0]);
}

int Polygon3D::GetIndex(const int index) const
{
	return _indices[index];
}

int Polygon3D::GetUVIndex(const int index) const
{
	return _uvIndices[index];
}

void Polygon3D::SetNormal(const Vector3D& normal)
{
	_normal = normal;
}

const Vector3D& Polygon3D::GetNormal() const
{
	return _normal;
}

void Polygon3D::NormalizeNormal()
{
	_normal.Normalize();
}

void Polygon3D::SetColor(int red, int green, int blue)
{		
	_r = red;
	_g = green;
	_b = blue;
}

void Polygon3D::SetColor(const COLORREF color)
{
	_r = GetRValue(color);
	_g = GetGValue(color);
	_b = GetBValue(color);
}

int Polygon3D::GetR() const
{
	return _r;
}

void Polygon3D::SetR(const int r)
{
	_r = r;
}

int Polygon3D::GetG() const
{
	return _g;
}

void Polygon3D::SetG(const int g)
{
	_g = g;
}

int Polygon3D::GetB() const
{
	return _b;
}

void Polygon3D::SetB(const int b)
{
	_b = b;
}

COLORREF Polygon3D::GetColor() const
{
	return RGB(_r, _g, _b);
}

void Polygon3D::SetDepth(float depth)
{
	_depth = depth;
}

float Polygon3D::GetDepth() const
{
	return _depth;
}

void Polygon3D::SetCulled(bool culled)
{
	_culled = culled;
}

bool Polygon3D::GetCulled() const
{
	return _culled;
}

Polygon3D& Polygon3D::operator= (const Polygon3D& rhs)
{
	if (this != &rhs)
	{
		Copy(rhs);
	}
	return *this;
}

void Polygon3D::Copy(const Polygon3D& other)
{
	for (int i = 0; i < sizeof(_indices)/sizeof(_indices[0]); i++)
	{
		_indices[i] = other.GetIndex(i);		
	}

	for (int i = 0; i < sizeof(_uvIndices) / sizeof(_uvIndices[0]); i++)
	{
		_uvIndices[i] = other.GetUVIndex(i);
	}

	_normal = other.GetNormal();
	_culled = other.GetCulled();
	_depth = other.GetDepth();
	
	_r = other.GetR();
	_g = other.GetG();
	_b = other.GetB();
}