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

	FILE	: RayTrace.h

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

	ゲームプログラミングwikiより引用、改変
	http://www.c3.club.kyutech.ac.jp/gamewiki/index.php?%BB%B0%BC%A1%B8%B5%A4%CE%A5%DE%A5%A6%A5%B9%BA%C2%C9%B8%BC%E8%C6%C0#content_1_1

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

#pragma once

class RayTrace
{
	public:
		RayTrace();
		~RayTrace();
	private:
		D3DXMATRIX m_matInvView;
		D3DXMATRIX m_matInvViewToProj;
		float m_fWidth;
		float m_fHeight;
		float m_offX;
		float m_offY;
		void ProjToWorld(VEC2 *in,D3DXVECTOR4 *ray_start,D3DXVECTOR4 *ray_dir);
		void ScreenToProj(VEC2 *out,VEC2 *in);
		bool GetHitPos(D3DXVECTOR4 *x, D3DXVECTOR4 *v,D3DXVECTOR4 *tmp,VEC3 *outvec);
		// v[4]頂点をv[6]に変換
		void V4toV6(VEC3* v4, VEC3* v6){ v6[0] = v4[0]; v6[1] = v4[1]; v6[2] = v4[2]; v6[3] = v4[1]; v6[4] = v4[2]; v6[5] = v4[3]; };

	public:
		void Init(float fWidth,float fHeight,float offX,float offY);
		void SetMatrix(D3DXMATRIX &matView,D3DXMATRIX &matProj);
		bool GetPosFromScreen(VEC2 *inMousePos,VEC3 *inVertex,D3DXMATRIX *inWorld,VEC3 *outPos = NULL,int inSize = 6);
};

