
#include <Spectre/Graphics/Transformable.h>

Transformable::Transformable() :
m_position		(0.0f, 0.0f),
m_scale			(1.0f, 1.0f),
m_rotation		(0.0f),
m_transformNeedsUpdate	(false)
{
}

Transformable::Transformable(const Vector2f& position) :
m_position		(position),
m_scale			(1.0f, 1.0f),
m_rotation		(0.0f),
m_transformNeedsUpdate	(false)
{
}

Transformable::~Transformable()
{
}

void Transformable::setPosition(const Vector2f& position)
{
	m_position = position;
	m_transformNeedsUpdate = true;
}

void Transformable::setPosition(float x, float y)
{
	setPosition(Vector2f(x, y));
}

void Transformable::move(const Vector2f& offset)
{
	setPosition(m_position + offset);
}
const Vector2f& Transformable::getPosition() const
{
	return m_position;
}

void Transformable::setRotation(float angle)
{
	m_rotation = angle;
	m_transformNeedsUpdate = true;
}

void Transformable::rotate(float angle)
{
	setRotation(m_rotation + angle);
}

float Transformable::getRotation() const
{
	return m_rotation;
}

void Transformable::setScale(const Vector2f& scale)
{
	m_scale = scale;
	m_transformNeedsUpdate = true;
}

void Transformable::setScale(float scale)
{
	setScale(Vector2f(scale));
}

void Transformable::scale(const Vector2f& offset)
{
	m_scale += offset;
	m_transformNeedsUpdate = true;
}

void Transformable::scale(float offset)
{
	scale(Vector2f(offset));
}

const Vector2f Transformable::getScale() const
{
	return m_scale;
}

const Transform& Transformable::getTransform() const
{
	if (m_transformNeedsUpdate) {
		//m_transform.reset();
		m_transform.set(m_position, m_rotation, m_scale);
		m_transformNeedsUpdate = false;
	}
	return m_transform;
}