示例#1
0
void CEditorScene::Input()
{
	//클릭 들어오면
	//터레인과 충돌 체크 검사
	const KEYINFO* pInfo = _SINGLE(CKeyManager)->GetKey(KEY_NAME_L_BUTTON);
	if(!pInfo)
		return;

	if(pInfo->bPush)
	{
		CEntity* pTerrain = _SINGLE(CObjectManager)->FindObject("MainTerrain");

		CTerrainMesh* pTerrainMesh = (CTerrainMesh*)pTerrain->GetMesh();

		//뷰 스페이스의 레이...
		const D3DXMATRIX* pMatView = _SINGLE(CCameraManager)->GetCurCam()->GetMatView();
		
		//월드로 바꾼다.
		RAY tRay = _SINGLE(CMouse)->TransformRay(pMatView);

		//월드 역좌표로 해서 로컬로 변환하고 싶지만
		//어차피 ㅌㅓ레인의 월드는 Identity겠지...
		//D3DXMATRIX matWorld = pTerrain->GetMatWorld();

		//D3DXMATRIX matInverseWorld;

		//D3DXMatrixInverse(&matInverseWorld, 0, &matWorld);

		//D3DXVec3TransformNormal(&tRay.vDir, &tRay.vDir, &matInverseWorld);

		//여기서 나온 레이 구조체가 터레인 월드의 구조체...

		CEntity* pBox = NULL;

		if(pTerrainMesh->GetCollisionPos(tRay))
		{
			string strName = "PickingBox"; 
			strName += m_iBoxCnt;

			pBox = _SINGLE(CObjectManager)->CreateEntity(
				MT_BOX, RTYPE_ENTITY, strName, MN_BOX);
			pBox->SetPos(D3DXVECTOR3(tRay.vIntersectPos.x, 0.f, tRay.vIntersectPos.z));
			//pBox->SetScale(1, 1, 1);
			pBox->SetShader(SHADER_DEFAULT);
			pBox->SetTechKey("DefaultTech");
			pBox->SetPass(PASS_NOTEXTURE);
			++m_iBoxCnt;

			m_listBox.push_back(pBox);
		}

	}

	pInfo = _SINGLE(CKeyManager)->GetKey(KEY_NAME_R_BUTTON);
	if(!pInfo)
		return;

	if(pInfo->bPush)
	{
		RAY tRay = _SINGLE(CMouse)->TransformRay(_SINGLE(CCameraManager)->GetCurCam()->GetMatView());
		list<CEntity*>::iterator iter = m_listBox.begin();

		for(; iter != m_listBox.end(); ++iter)
		{
			if(_SINGLE(CMouse)->IntersectRayToSphere(&tRay, (*iter)->GetPos(), (*iter)->GetSize()))
			{
				_SINGLE(CObjectManager)->Remove_Object((*iter));
				
				//erase로 지우면 객체가 list에서 안 빠짐...
				//iter = m_listBox.erase(iter);

				m_listBox.remove(*iter);

				--m_iBoxCnt;

				break;
			}
		}
	}

	
	
}
示例#2
0
bool CEntity::Collision()
{
	list<CEntity*>*	RenderList = _SINGLE(CObjectManager)->GetRenderList();

	//µÎ ¿£Æ¼Æ¼ º¤ÅÍ Â÷
	D3DXVECTOR3 vLenth = D3DXVECTOR3(0,0,0);
	//³ë¸» º¤ÅÍ
	D3DXVECTOR3 vNormal = D3DXVECTOR3(0,0,0);
	//Ÿ°ÙÀÇ À§Ä¡
	D3DXVECTOR3 vTarPos = D3DXVECTOR3(0,0,0);
	//Ãæµ¹ÁöÁ¡
	D3DXVECTOR3 vCol = D3DXVECTOR3(0.f, 0.f, 0.f); 
	//¿£Æ¼Æ¼ Å©±â
	float fSize = GetSize();
	float fTarSize = 0.f;
	//µÎ ¿£Æ¼Æ¼°£ÀÇ ±æÀÌ
	float len  = 0.f;
	//¿£Æ¼Æ¼ÀÇ ¸Þ½Ã
	eMESH_TYPE _eTarMesh_type = MT_NULL;
	const CMesh* _pTarMesh = NULL;
	//int i = RTYPE_ENTITY;
	for(list<CEntity*>::iterator iter = RenderList[RTYPE_ENTITY].begin();
		iter != RenderList[RTYPE_ENTITY].end(); ++iter)
	{
		//üũÇÏ·Á´Â °´Ã¼¿Í °°Àº °´Ã¼¶ó¸é ³Ñ¾î°¡¶ó
		if( (*iter)->GetName() == m_strName )
			continue;
		//´ë»ó ¿ÀºêÁ§Æ®ÀÇ À§Ä¡
		vTarPos = (*iter)->GetPos();
		//À̵¿ ¿¹Á¤ÀÎ À§Ä¡¿Í ´ë»ó ¿ÀºêÁ§Æ®ÀÇ Â÷º¤ÅÍ
		vLenth = (m_vPos + m_vMove) - vTarPos;
		//µÎ ¿£Æ¼Æ¼°£ÀÇ °Å¸®
		len = D3DXVec3Length(&vLenth );
		//Ÿ°ÙÀÇ »çÀÌÁî 
		fTarSize = (*iter)->GetSize();
		//Ÿ°ÙÀÇ ¸Þ½ÃÁ¤º¸
		_pTarMesh = (*iter)->GetMesh();
		//Ÿ°ÙÀÇ Ãæµ¹ ŸÀÔ
		_eTarMesh_type = _pTarMesh->GetColliderType();

#ifdef _DEBUG
			_SINGLE(CDebug)->ResetLine();
#endif
		//Ã浹üũ
		if(  _eTarMesh_type == MT_STATIC && //±¸ Ãæµ¹ 
			(fSize + fTarSize) >= len) 
		{

			if( !ComputeNormalVector( (*iter)->GetCollider(), 
				vNormal, vCol, (*iter)) )
				continue;
			m_vPos += vNormal * m_fMoveSpeed/* * _SINGLE(CDebug)->GetDeltaTime()*/;
			m_vPos.y = 0.f;

#ifdef _DEBUG
			//¹ý¼±
			_SINGLE(CDebug)->AddLine( 
				vCol, vCol + vNormal * 30.f, COLOR_ORANGE);
			//À̵¿º¤ÅÍ
			_SINGLE(CDebug)->AddLine( m_vPos, m_vPos + m_vMove * 300.f, COLOR_PURPLE );
			
#endif
			//º¤ÅÍÀÇ ±æÀ̵µ ¿¬»ê¿¡ Áß¿äÇÑ ¿ä¼Ò±â ¶§¹®¿¡ Á¤±ÔÈ­ ÇÏÁö ¾Ê´Â´Ù.
			//D3DXVec3Normalize( &vNormal, &vNormal);
			//D3DXVec3Normalize( &m_vMove, &m_vMove);
			m_vMove -= D3DXVec3Dot( &m_vMove, &vNormal ) * vNormal ;
			//½½¶óÀ̵ù º¤Å͸¦ °è»êÇßÀ¸¸é ÀÌ º¤Å͸¦ ±âÁØÀ¸·Î ´Ù½Ã Ãæµ¹ üũ
			iter = RenderList[RTYPE_ENTITY].begin();
			int static cnt = 0;
			if( cnt++ >= 10)
				break;
				
#ifdef _DEBUG
			//½½¶óÀ̵ù º¤ÅÍ
			_SINGLE(CDebug)->AddLine( m_vPos, m_vPos + m_vMove * 3000.f, COLOR_CYAN);
#endif
		}
		//¹Ú½º Ãæµ¹
		else if( _eTarMesh_type == MT_BOX &&
			fSize + fTarSize > len )
		{
			
			LPD3DXMESH pMesh = _pTarMesh->GetMesh();
			BOXSIZE size = ((CBoxMesh*)_pTarMesh)->GetMinMax();

			if( !ComputeNormalVector( pMesh, 
				vNormal, vCol, (*iter)) )
				continue;

#ifdef _DEBUG
			//¹ý¼±
			_SINGLE(CDebug)->AddLine( 
				vCol, vCol + vNormal * 30.f, COLOR_ORANGE);
			//À̵¿º¤ÅÍ
			_SINGLE(CDebug)->AddLine( m_vPos, m_vPos + m_vMove * 300.f, COLOR_PURPLE );
#endif
			//»ç°¢ÇüÀ̱⠶§¹®¿¡ Ãß°¡ÀûÀÎ Ã浹üũ
			size.vMax += vTarPos;
			size.vMin += vTarPos;

#ifdef _DEBUG
			_SINGLE(CDebug)->AddPosMark( size.vMax, COLOR_MAGENTA );
			_SINGLE(CDebug)->AddPosMark( size.vMin, COLOR_MAGENTA );
#endif
			D3DXVECTOR3 vPrePos = m_vPos + m_vMove;

			if (vCol.x < size.vMin.x - fSize || 
				vCol.x > size.vMax.x + fSize ||
				vCol.z < size.vMin.z - fSize || 
				vCol.z > size.vMax.z + fSize )
				continue;
			m_vPos += vNormal * m_fMoveSpeed/* * _SINGLE(CDebug)->GetDeltaTime()*/;
			
			m_vMove -= D3DXVec3Dot( &m_vMove, &vNormal ) * vNormal ;
			m_vPos.y = 0.f;
		}

	}
	//Ãæµ¹ ¾ÈÇßÀ¸¸é °í°í
	//m_vMove.y = 0.f;
#ifdef _DEBUG
	/*m_vMove *= _SINGLE(CDebug)->GetDeltaTime();*/
#endif
	D3DXVec3Normalize( &m_vMove, &m_vMove);
	m_vPos += m_vMove * m_fMoveSpeed;

	//ÁöÇü À§·Î ij¸¯ÅÍ ¾ñ±â
	CEntity* pTerrain = _SINGLE(CObjectManager)->FindObject("MainTerrain");
	if(!pTerrain)
		return false;

	CTerrainMesh* pTerrainMesh = (CTerrainMesh*)pTerrain->GetMesh();
	
	if(!pTerrainMesh)
		return false;

	m_vPos.y = pTerrainMesh->GetHeight(m_vPos.x, m_vPos.z);

	return false;
}