⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cblockmesh.cpp

📁 俄罗斯方块3D 程序+源码俄罗斯方块3D(程序+源码
💻 CPP
字号:
#include "CBlockMesh.h"
#include "normal.h"
#include "CMaterialManager.h"
#include "CGameState.h"

extern CMaterialManager	theMaterialManager;
extern CGameState		theGameState;


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBlockMesh::CBlockMesh()
{
	m_pMesh = NULL;
	m_fSize = 0.2f;
}

CBlockMesh::~CBlockMesh()
{

}


//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
bool CBlockMesh::Init( IDirect3DDevice9 *pD )
{
	HRESULT hr = D3DXCreateBox( pD, m_fSize, m_fSize, m_fSize, &m_pMesh, NULL );
	if ( FAILED( hr ) )
		return false;
	return true;
}


//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
void CBlockMesh::Free()
{
	SafeRelease( m_pMesh );
}


//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
void CBlockMesh::GetMatrix( D3DXMATRIX &out, int row, int col )
{
	float x = (float)( col - theGameState.GetHalfCol() ) * m_fSize;
	float y = (float)( row - theGameState.GetHalfRow() ) * m_fSize;

	D3DXMatrixTranslation( &out, x, y, 0.0f );
}


//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
void CBlockMesh::Draw( IDirect3DDevice9 *pD, int row, int col, int material )
{
	D3DXMATRIX m;
	GetMatrix( m, row, col );

	pD->SetTransform( D3DTS_WORLD, &m );
	theMaterialManager.SetMaterial( pD, material );
	m_pMesh->DrawSubset( 0 );
}

//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
void CBlockMesh::Draw( IDirect3DDevice9 *pD, const CBlock &block )
{
	Draw( pD, block.GetRow(), block.GetCol(), block.GetMaterialIndex() );
}


//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
void CBlockMesh::Draw( IDirect3DDevice9 *pD, const POSITION &position, int material )
{
	Draw( pD, position.row, position.col, material );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -