www.pudn.com > Game_11.rar > Cube.cpp
// Cube.cpp: implementation of the CCube class.
//
//////////////////////////////////////////////////////////////////////
#include "Cube.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCube::~CCube()
{
SAFE_RELEASE(m_pVB);
SAFE_RELEASE(m_pTexture1);
SAFE_RELEASE(m_pTexture2);
}
void CCube::Render()
{
m_pDevice->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_BLENDTEXTUREALPHA);
m_pDevice->SetFVF(D3DFVF_CUBE);
m_pDevice->SetStreamSource(0,m_pVB,0,sizeof(CubeVertexBuffer)); //¶¥µãÀ´Ô´
SetMatrix();
if(m_pTexture1) m_pDevice->SetTexture(0,m_pTexture1);
// if(m_pTexture2) m_pDevice->SetTexture(1,m_pTexture2);
m_pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,8);
m_pDevice->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_DISABLE);
m_pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,10,2);
m_pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,14,2);
};
void CCube::InitVB()
{
CubeVertexBuffer VB[18]=
{ -m_fWidth/2, m_fWidth/2, -m_fWidth/2, 0.0f,1.0f,0.0f,1.0f, -m_fWidth/2, -m_fWidth/2, -m_fWidth/2, 0.0f,0.0f,0.0f,0.0f,
m_fWidth/2, m_fWidth/2, -m_fWidth/2, 1.0f,1.0f,1.0f,1.0f, m_fWidth/2, -m_fWidth/2, -m_fWidth/2, 1.0f,0.0f,1.0f,0.0f,
m_fWidth/2, m_fWidth/2, m_fWidth/2, 0.0f,1.0f,0.0f,1.0f, m_fWidth/2, -m_fWidth/2, m_fWidth/2, 0.0f,0.0f,0.0f,0.0f,
-m_fWidth/2, m_fWidth/2, m_fWidth/2, 1.0f,1.0f,1.0f,1.0f, -m_fWidth/2, -m_fWidth/2, m_fWidth/2, 1.0f,0.0f,1.0f,0.0f,
-m_fWidth/2, m_fWidth/2, -m_fWidth/2, 0.0f,1.0f,0.0f,1.0f, -m_fWidth/2, -m_fWidth/2, -m_fWidth/2, 0.0f,0.0f,0.0f,0.0f,
};
VB[10]=VB[3];
VB[11]=VB[1];
VB[12]=VB[5]; VB[12].tu1=1.0f; VB[12].tv1=1.0f; VB[12].tu2=1.0f; VB[12].tv2=1.0f;
VB[13]=VB[7]; VB[13].tu1=0.0f; VB[13].tv1=1.0f; VB[13].tu2=0.0f; VB[13].tv2=1.0f;
VB[14]=VB[2];
VB[15]=VB[4];
VB[16]=VB[0]; VB[16].tu1=1.0f; VB[16].tv1=0.0f; VB[16].tu2=1.0f; VB[16].tv2=0.0f;
VB[17]=VB[6]; VB[17].tu1=0.0f; VB[17].tv1=0.0f; VB[17].tu2=0.0f; VB[17].tv2=0.0f;
m_pDevice->CreateVertexBuffer(18*sizeof(CubeVertexBuffer),D3DUSAGE_SOFTWAREPROCESSING,
D3DFVF_CUBE, D3DPOOL_DEFAULT, &m_pVB,NULL);
void* pVertices;
m_pVB->Lock(0,18*sizeof(CubeVertexBuffer),&pVertices,D3DLOCK_DISCARD);
memcpy(pVertices,(void*)VB,sizeof(VB));
m_pVB->Unlock();
};