#include "Object3D.h"

CObject3D::CObject3D(char *objName)
{
	m_vPosition.init(0.f, 1.0f, 0.f);

	m_fLRTheata  = 0.f;

	m_fMaxSpeed  = 20.f;
	m_fMinSpeed  = -80.f;
	m_fMoveSpeed = 0.f;
	m_fHalfSpeed = 0.5f;

	m_dSpeedOldTick = GetTickCount();
	m_dMovetick		= GetTickCount();

	m_pModel=NULL;

	m_pModel = glmReadOBJ(objName);
	glmUnitize(m_pModel);
	glmFacetNormals(m_pModel);
	glmVertexNormals(m_pModel, 90.0);
}

CObject3D::~CObject3D(void)
{
	if(m_pModel)
		delete m_pModel;

	m_pModel=NULL;
}

void CObject3D::MoveObject()
{
	DWORD nTick = GetTickCount();
	if(nTick-m_dMovetick>50)
	{
		m_vPosition.x = m_vPosition.x+Radian(sin(m_fLRTheata))*m_fMoveSpeed;
		m_vPosition.z = m_vPosition.z+Radian(cos(m_fLRTheata))*m_fMoveSpeed;//*/
		m_dMovetick=nTick;
	}
}

void CObject3D::calSpeed(bool state)
{
	if(!state)
	{
		if(m_fMaxSpeed>m_fMoveSpeed)
		{
			m_fMoveSpeed+=DEFAULTSPEED;
		}
	}
	else
	{
		if(m_fMinSpeed<m_fMoveSpeed)
		{
			m_fMoveSpeed-=DEFAULTSPEED;
		}
	}
}

void CObject3D::RenderObject()
{	
	if(m_pModel)
		glmDraw(m_pModel, GLM_SMOOTH);
}

void CObject3D::leftRotate()
{
	m_fLRTheata+=DEFAULTUPDATE;
	if(m_fLRTheata>=20)
		m_fLRTheata=20;
}

void CObject3D::rightRotate()
{

	m_fLRTheata-=DEFAULTUPDATE;
	if(m_fLRTheata<=-20)
		m_fLRTheata=-20;//*/
}