
/* _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

	FILE	: Mouse.h

+ ------ Explanation of file --------------------------------------------------------------------------

+ _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ */


#include "Common.h"

#include "windowManager.h"
#include "RayTrace.h"

#include "Mouse.h"

//! 解放
void Mouse::release(void)
{
	SAFE_DELETE(m_pRayTrace);
}

//! 初期化
void Mouse::init(void)
{
	m_pWinMan = WindowManager::getInstance();
	m_pRayTrace = new RayTrace();
	getRayTrace()->Init(WINDOW_W-MENU_W, WINDOW_H, MENU_W, 0);
}

//! 更新
void Mouse::update(void)
{
	if(GetActiveWindow() == getWinMan()->getHWnd()){
		// 座標取得
		POINT cPos;
		GetCursorPos(&cPos);
		ScreenToClient(getWinMan()->getHWnd(), &cPos);
		m_pos.x = (float)cPos.x;
		m_pos.y = (float)cPos.y;

		// L入力状態取得
		if(GetAsyncKeyState(VK_LBUTTON) < 0){
			if(m_inputL == MOUSE_PULL){
				m_inputL = MOUSE_PUSH;
			}else{
				m_inputL = MOUSE_HOLD;
			}
		}else{
			m_inputL = MOUSE_PULL;
		}

		// R入力状態取得
		if(GetAsyncKeyState(VK_RBUTTON) < 0){
			if(m_inputR == MOUSE_PULL){
				m_inputR = MOUSE_PUSH;
			}else{
				m_inputR = MOUSE_HOLD;
			}
		}else{
			m_inputR = MOUSE_PULL;
		}

		// ホイール
		if(m_updateWheel != 0){
			m_wheel = m_updateWheel;
			m_updateWheel = 0;
		}else{
			m_wheel = 0;
		}
	}else{
		m_pos.x = -1.0f;
		m_pos.y = -1.0f;
		m_wheel = 0;
	}
}

//! 3D面とのヒットチェック
bool Mouse::isHitPlane(VEC3* pPos, D3DXMATRIX* pWorld, VEC3* pHit)
{
	return(getRayTrace()->GetPosFromScreen(&m_pos, pPos, pWorld, pHit));
}

