void Unit::Render() const
{
	if ( !m_Visible || !m_MeshKey || CameraController::GetInstance()->GetHeightGrade() > 3 )
	{
		return;
	}

	if ( SCENE_PLAY == SceneManager::GetInstance()->GetNowSceneType() )
	{
		Scene* scene = SceneManager::GetInstance()->GetNowScene();
		ScenePlay* scenePlay = static_cast<ScenePlay*>( scene );

		Frustum* frustum = scenePlay->GetFrustum();
		
		if ( frustum )
		{
			D3DXVECTOR3	center = m_EyePoint;
			if ( !frustum->IsIn( &center ) )
			{
				return;
			}
		}
	}

	D3DXMATRIXA16 thisMatrix = GetMatrix( false );

	D3DXMATRIXA16 heightMatrix;
	D3DXMatrixTranslation( &heightMatrix, 0, MapManager::GetInstance()->GetHeightByPosition( m_EyePoint.x, m_EyePoint.z ), 0 );
	
	thisMatrix = thisMatrix * heightMatrix;
	Renderer::GetInstance()->SetWorldMatrix( thisMatrix );

	ResourceMesh* mesh = ResourceManager::GetInstance()->GetMeshByKey( m_MeshKey );

	//if ( mesh )
	//{
	//	Renderer::GetInstance()->RenderMesh( mesh->m_MeshObject );
	//}

	char flag = 0;

	if ( m_Corps->IsSelected() )
	{
		flag |= UNIT_STATUS_SELECT;

		D3DXMATRIXA16 viewMatrix = CameraController::GetInstance()->GetViewMatrix();
		D3DXMATRIXA16 billMatrix;
		D3DXMatrixIdentity( &billMatrix );

		billMatrix._11 = viewMatrix._11;
		billMatrix._13 = viewMatrix._13;
		billMatrix._31 = viewMatrix._31;
		billMatrix._33 = viewMatrix._33;

		D3DXMatrixInverse( &billMatrix, NULL, &billMatrix );

		D3DXMATRIXA16 scaleMatrix;
		D3DXMatrixScaling( &scaleMatrix, 1.3f, 1.3f, 1.3f );

		billMatrix = billMatrix * scaleMatrix;

		billMatrix._41 = thisMatrix._41;
		billMatrix._42 = thisMatrix._42;
		billMatrix._43 = thisMatrix._43;

		Renderer::GetInstance()->SetWorldMatrix( billMatrix );
	}
	if ( m_Corps->IsFight() )
	{
		flag |= UNIT_STATUS_ATTACK;
	}
	if ( m_Corps->IsEnemy() )
	{
		flag |= UNIT_STATUS_ENEMY;
	}

	Renderer::GetInstance()->RenderBillboard( m_Corps->GetCorpsTextureType(), flag );
	Renderer::GetInstance()->SetShader( false );
}