#include "StdAfx.h"
#include "MyApplication.h"
#include "CollisionDetection.h"

MyApplication::MyApplication(HWND hWnd) {
	directXFramework = new DirectXFramework(hWnd);
	LPDIRECT3DDEVICE9 pDevice = directXFramework->GetD3DDevice();
	island = new XFileMesh(TEXT("batokin_island5.x"), pDevice);
	//yukkuri = new XFileMesh(TEXT("yukkuri4.x"), pDevice);
	yukkuri = new MqoMesh(TEXT("yukkuri5.mqo"), pDevice);
	board = new HandMadeMesh(pDevice);
	shadow = new Shadow(pDevice, yukkuri->GetMesh(), yukkuri->GetNumMaterial());
	shadowVolume = new ShadowVolume(pDevice, yukkuri->GetMesh());
	meshLight = new MeshLight(pDevice);
	meshCamera = new MeshCamera(pDevice);
}

MyApplication::~MyApplication(void) {
	delete meshCamera;
	delete meshLight;
	delete shadow;
	delete shadowVolume;
	delete board;
	delete yukkuri;
	delete island;
	delete directXFramework;
}

void MyApplication::Run() {
	directXFramework->BeginScene(0x0F, 0xFF , 0xFF);// シーン開始
	static int t;
	const D3DXVECTOR3 position(0, 0, 0), zeroVector(0, 0, 0);
	D3DXMATRIX rotation, unitMatrix;
	D3DXMatrixRotationY(&rotation, 0.01f*(++t));
	D3DXMatrixIdentity(&unitMatrix);

	// ライト
	D3DXVECTOR3 direction(-1, -1, -1);	// 光の方向
	meshLight->Illume(direction);		// 光をあてる

	// カメラ
	D3DXVECTOR3 eyePoint = D3DXVECTOR3(-0.2f, 0.4f, 1.3f);	// 視点
	D3DXVECTOR3 lookAtPoint = D3DXVECTOR3(0, 0.3f, 0);		// 注視点
	meshCamera->Look(eyePoint, lookAtPoint);				// 見る

	// 描画
	island->Draw(zeroVector, unitMatrix);
	yukkuri->Draw(position, rotation);
	shadow->Draw(position, rotation, direction, D3DXPLANE(0, -1, 0, 0));
	//shadowVolume->Draw(position, rotation, direction);
	//board->Draw(position, rotation);

	directXFramework->EndScene();			// シーン終了
}