?? cblockmesh.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 + -