#include "DiManager.h"
#include <iostream>

DiManager* DiManager::instance;

DiManager::DiManager()
{
}

void DiManager::initDirectInput()
{
	DirectInput8Create(DXUTGetHINSTANCE(),    // the handle to the application
                       DIRECTINPUT_VERSION,    // the compatible version
                       IID_IDirectInput8,    // the DirectInput interface version
                       (void**)&directInput,    // the pointer to the interface
                       NULL);    // COM stuff, so we'll set it to NULL
    directInput->CreateDevice(GUID_SysMouse,
                      &directInputMouse,
                      NULL);
	directInputMouse->SetDataFormat(&c_dfDIMouse);
	directInputMouse->SetCooperativeLevel(DXUTGetHWND(), DISCL_EXCLUSIVE | DISCL_FOREGROUND);

	directInput->CreateDevice(GUID_SysKeyboard,
                      &directInputKeyboard,
                      NULL);
	directInputKeyboard->SetDataFormat(&c_dfDIKeyboard);
	directInputKeyboard->SetCooperativeLevel(DXUTGetHWND(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);

}
D3DXVECTOR2 DiManager::getMouseMovement()
{
	return D3DXVECTOR2((float)mouseState.lX,(float)mouseState.lY);
}
bool DiManager::isKeyPressed(int key)
{
	if(keyboardState[key] & 0x80)
		return true;
	else
		return false;
}
void DiManager::update()
{
	directInputMouse->Acquire();
	directInputMouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouseState);
	
	directInputKeyboard->Acquire();
    directInputKeyboard->GetDeviceState(256, (LPVOID)keyboardState);
}

DiManager::~DiManager()
{}