www.pudn.com > Game_11.rar > Cube.h
// Cube.h: interface for the CCube class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_CUBE_H) #define AFX_CUBE_H #include#include #include #include #pragma comment (lib,"winmm.lib") #pragma comment (lib,"d3d9.lib") #pragma comment (lib,"d3dx9.lib") #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #define D3DFVF_CUBE D3DFVF_XYZ|D3DFVF_TEX2 //坐标信息 #define SAFE_RELEASE(p) if(p) {p->Release();p=NULL;} class CCube { protected: struct CubeVertexBuffer { float x,y,z; //坐标信息 float tu1,tv1; float tu2,tv2; }; public: virtual ~CCube(); protected: LPDIRECT3DDEVICE9 m_pDevice; LPDIRECT3DTEXTURE9 m_pTexture1; //材质 LPDIRECT3DTEXTURE9 m_pTexture2; LPDIRECT3DVERTEXBUFFER9 m_pVB; D3DVECTOR m_vPos; float m_fWidth; public: CCube(LPDIRECT3DDEVICE9 pDevice,D3DVECTOR position) { m_pDevice=pDevice; m_vPos=position; m_pTexture1=NULL; m_pTexture2=NULL; }; void CreateCube(float width,char *strText1,char *strText2=NULL) { m_fWidth=width; D3DXCreateTextureFromFile(m_pDevice,strText1, &m_pTexture1); if(strText2) D3DXCreateTextureFromFile(m_pDevice,strText2, &m_pTexture2); InitVB(); } void InitVB(); //创建立方盒的顶点缓冲区 void Render(); void SetMatrix() { D3DXMATRIX matWorld; D3DXMatrixTranslation(&matWorld,m_vPos.x,m_vPos.y,m_vPos.z); m_pDevice->SetTransform(D3DTS_WORLD,&matWorld); }; }; #endif // !defined(AFX_CUBE_H)