/** 
 * \file Turtle.cpp
 * \brief CTurtle class member functions implementation. CTurtle holds model's position and facing.
 * 
 * \author Petar Bajic, MPE (C) All Rights Reserved, Homepage: www.mystic-peanut.com
 * \date January, 16 2007.
 */

#include "Turtle.h"

#pragma warning( disable : 4996 ) // disable deprecated warning 
#include <strsafe.h>
#pragma warning( default : 4996 )

/**
 * \brief Standard constructor.
 * \author Petar Bajic 
 * \date January, 16 2007.
 */
CTurtle::CTurtle()
{
	m_Model = NULL;
	m_Sound = NULL;
	m_Position = D3DXVECTOR3(0.0f,0.0f,0.0f);
	m_Facing = 0.0f;
	m_isRunning = false;
	m_isIdle = true;
}

/**
 * \brief Standard destructor.
 * \author Petar Bajic 
 * \date January, 16 2007.
 */
CTurtle::~CTurtle()
{
	if(m_Model != NULL)
		delete m_Model;
}

/**
 * \brief Init function loads turtle skinned model (CXFileEntity).
 * \author Petar Bajic 
 * \date January, 16 2007.
 */
bool CTurtle::Init(HWND hWnd, LPDIRECT3DDEVICE9 pd3dDevice)
{
	m_Model = new CXFileEntity(); // Create our entity class
	// Load an x file to start with
	WCHAR strFullPath[MAX_PATH];
	GetCurrentDirectory(MAX_PATH,strFullPath);
	StringCchCat(strFullPath, 255, L"//Media//Models//turtle.x");
	HRESULT hr = m_Model->LoadXFile(pd3dDevice,strFullPath);
	if (FAILED(hr))
	{
		MessageBox(hWnd,L"Could not load Media/Models/turtle.x file",L"Error",MB_OK);
		return false;
	}
	return true;
}

/**
 * \brief Move animated model.
 * \author Petar Bajic 
 * \date January, 16 2007.
 */
void CTurtle::OnFrameMove(LPDIRECT3DDEVICE9 pd3dDevice, float fElapsedTime, D3DXMATRIXA16* matWorld)
{
	m_Model->OnFrameMove(pd3dDevice, fElapsedTime, matWorld);
}

/**
 * \brief Render skinned model.
 * \author Petar Bajic 
 * \date January, 16 2007.
 */
void CTurtle::OnRender(LPDIRECT3DDEVICE9 pd3dDevice)
{
	m_Model->Render(pd3dDevice);
}

/**
 * \brief Restart turtle (position, facing, etc..)
 * \author Petar Bajic 
 * \date January, 16 2007.
 */
void CTurtle::Restart()
{
	m_Position = D3DXVECTOR3(0.0f,0.0f,0.0f);
	m_Facing = 0.0f;
	m_Model->SetAnimationSet(0);
}


