#include "CD3DImage.h"


#include <math.h>

#include "CGraphicSystem.h"
#include "CD3DManager.h"

void CD3DTexture::reloadTexture()
{  		

	CD3DManager* d3d = (CD3DManager*)&g_GraphicSystem;			
	d3d->loadTexture(fileName, lpD3DTexture); 
}

//----------------------------------------------------------------//
//					Constructor/Deconstructor
//----------------------------------------------------------------//

CD3DImage::CD3DImage()
{	
	this->setHeight(0);
	this->setWidth(0);
	this->rotation=0;

	scale =  D3DXVECTOR2(1,1);
	colorMod=0xFFFFFFFF;

	m_offSet.x=0;
	m_offSet.y=0;
	

}

CD3DImage::~CD3DImage()
{
	

}


//----------------------------------------------------------------//
//
//----------------------------------------------------------------//



VOID * CD3DImage::getScale()
{
	//float scl;
	//scl=scale.x / scale.y;

	return (VOID *)scale;
}
	
VOID * CD3DImage::getCenter()
{
	

	return (VOID *)center;
}

void CD3DImage::setCenter(int x, int y)
{
	center = D3DXVECTOR2(x, y);

}


void CD3DImage::rotate(int deg)
{
	float rad = float(2 * 3.14159265358979323 * deg / 360);

	this->rotation += rad;

}

void CD3DImage::setTransparency(int pct)
{
	transparency=pct;

	
	if(pct >= 100)
	{
		colorMod = colorMod | 0xFF000000;
		return;
	}	
	if(pct < 0)
		pct=0;


	float p = float(pct)/100;
	float t = p * 256;

	colorMod = colorMod & 0x00FFFFFF;			
	DWORD alpha;			  	

	alpha = ((int)(t/16)) * pow(16,7);
	alpha = alpha | DWORD((((int)t)%16 * pow(16,6)));

//	cout << alpha << "\n";	
	colorMod = colorMod | alpha;


}

void CD3DImage::mirror()
{
	scale.x *= -1.0f;

	if(scale.x < 0)
		m_offSet.x += Width;
	else
		m_offSet.x -= Width;
	
}


void CD3DImage::setScale(float s)
{
	setScale(s, s);
}

void CD3DImage::setScale(float w, float h)
{
	int realWidth = Width / scale.x;
	int realHeight = Height / scale.y;

	//Width /= scale.x;
	//Height /= scale.y;
	
	scale = D3DXVECTOR2(w, h);				

	//Width*=w;
	//Height*=h;

	Width = realWidth * w;
	Height = realHeight * h;

	setCenter(Width/2, Height/2);
	
	
	
}


/*

VOID * CD3DImage::getScale()
{
	//float scl;
	//scl=scale.x / scale.y;

	return (VOID *)&scale;
}


VOID * CD3DImage::getCenter()
{
	//float scl;
	//scl=scale.x / scale.y;

	return (VOID *)&center;
}


void CD3DImage::setCenter(int x, int y)
{
	center = D3DXVECTOR2(x, y);

}

  */