//---------------------------
// Includes
//---------------------------
#include "StdAfx.h"
#include "LevelProp.h"

#include "Painter.h"
#include "ResourceLoader.h"
#include "InputState.h"
#include "CollisionMesh.h"
#include "Image.h"
//---------------------------
// Defines
//---------------------------
//

//---------------------------
// Constructor & Destructor
//---------------------------
LevelProp::LevelProp(ResourceLoader* resourceLoaderPtr,const String& imageName)
	:m_ImagePtr(0)
	,m_CollisionMeshPtr(0)
	,m_Position()
	,m_Angle(0)
	,m_AngularSpeed(0)
	,m_Gravity(0,500)
	,m_Velocity()
	,m_UseRayCast(false)
	,m_Restitution(1.0)
	,m_Friction(1.0)
{
	m_ImagePtr = resourceLoaderPtr->LoadImage(imageName);
}

LevelProp::~LevelProp()
{

}



void LevelProp::Paint(Painter *painterPtr, Matrix2D matTransform)
{
	painterPtr->SetTransformMatrix(m_MatWorld * matTransform);
	painterPtr->DrawImage(m_ImagePtr,0,0);

	//Draw the collisionmesh
	/*painterPtr->SetColor(255,0,0,127);
	painterPtr->SetTransformMatrix(matTransform);
	painterPtr->FillCollisionMesh(m_CollisionMeshPtr);*/
}

void LevelProp::Tick(InputState *inputStatePtr)
{
	m_Angle+=m_AngularSpeed*inputStatePtr->GetDeltaTime();

	Matrix2D matCenter, matRotate, matPosition;

	matCenter.SetAsTranslate(-m_ImagePtr->GetWidth()/2,-m_ImagePtr->GetHeight()/2);
	matRotate.SetAsRotate(m_Angle);
	matPosition.SetAsTranslate(m_Position);
	m_MatWorld = matCenter * matRotate * matPosition;
	m_CollisionMeshPtr->SetTransformMatrix(m_MatWorld);


}

void LevelProp::CheckCollision(Character *characterPtr) const
{

}

void LevelProp::CheckCollision(LevelProp *levelPropPtr, InputState *inputStatePtr) const
{

}

Point2D LevelProp::GetPosition() const
{
	return m_Position;
}

void LevelProp::SetPosition(Point2D pt)
{
	m_Position = pt;
}


Vector2D LevelProp::GetVelocity() const
{
	return m_Velocity;
}

void LevelProp::SetVelocity(Vector2D vel)
{ 
	m_Velocity = vel;
}

CollisionMesh *LevelProp::GetCollisionMesh() const
{
	return m_CollisionMeshPtr;
}

double LevelProp::GetWidth() const
{
	return m_ImagePtr->GetWidth();
}

double LevelProp::GetHeight() const
{
	return m_ImagePtr->GetHeight();
}

void LevelProp::SetAngularSpeed(double angularSpeed)
{
	m_AngularSpeed = angularSpeed;
}

bool LevelProp::UsesRayCast() const
{
	return m_UseRayCast;
}

double LevelProp::GetRestitution() const
{
	return m_Restitution;
}

double LevelProp::GetFriction() const
{
	return m_Friction;
}
