|
大家给些意见吧…[em7]
////////////////////////////////////////////////////////////////////////////////
// File Name: Graphic.h
//
// Original Author: Programma Lam
//
// Creation Date: 28/8/2004
//
////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "d3d9.h"
#include "d3dx9.h"
#include "vector"
#define PostErrMessage(str) MessageBox(0,str,0,0)
using namespace std;
////////////////////////////////////////////////////////////////////////////////
// Class Name: IGraphicDevice(Singleton)
//
// Last Modified By: Programma Lam
//
// Last Modified: 28/8/2004
//
// Description: An interface for initialize and terminate
// graphic system, provides basic graphic function
////////////////////////////////////////////////////////////////////////////////
class IGraphicDevice
{
public:
struct CGraphicObjectDesc
{
float m_lZPos; //z-value of graphic
long m_lVertexFlags; //vertex flags
unsigned char m_uchSizeOfEachVertex; //size of each vertex
unsigned short m_NumOfTriangle; //number of triangle
IDirect3DVertexBuffer9 *m_pVertexBuffer; //pointer to vertex buffer
IDirect3DTexture9 *m_pTexture; //pointer to texture to present
D3DXMATRIX &m_WorldMatrixStruct; //world matrix struct
};
IGraphicDevice(void);
~IGraphicDevice(){};
void InitializeEnvironment(HWND hWnd_, unsigned short usScreenWidth_,
unsigned short usScreenHeight_, bool bWindowed_);
void CleanupEnvironment(void);
void Setup2DCamera(void);
void Insert2DObjects(CGraphicObjectDesc* pObjectDesc_); //insert 2D object
void Render2DObjects(void); //render all 2D objects
void Release2DObjects(void); //release all 2D object
private:
IDirect3D9 *m_pDirect3DInterface; //d3d object
HWND m_hWnd; //handle to game window
bool m_bWindowed; //if the game not fullscreen
vector<CGraphicObjectDesc*> m_vObjects2D; //the 2D objects to render
public:
IDirect3DDevice9 *m_pDeviceInterface; //d3d device
unsigned short m_usScreenWidth, m_usScreenHeight; //size of window
public:
static IGraphicDevice& GetInstance(void)
{
return ms_InstanceClass;
}
static IGraphicDevice ms_InstanceClass;
};
#define PLANESURFACE_VERTEX_FLAGS (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)
////////////////////////////////////////////////////////////////////////////////
// Class Name: CPlaneSurface
//
// Last Modified By: Programma Lam
//
// Last Modified: 29/8/2004
//
// Description: A virtual class to store a texture and vertex data,
// send reference of datas to IGraphicDevice
////////////////////////////////////////////////////////////////////////////////
class CPlaneSurface
{
public:
struct CPlaneSurface_Vertex
{
float m_fx, m_fy, m_fz; //position
unsigned long m_ulcolour; //vertex color
float m_fu, m_fv; //texture coordinates
};
CPlaneSurface(unsigned short ulSurfaceWidth_, unsigned short ulSurfaceHeight_);
~CPlaneSurface();
D3DMATRIX & Translate(long lXPos_, long lYPos_);
D3DMATRIX & Scale(float fScaleX_, float fScaleY_);
D3DMATRIX & Rotate(float fAngle_);
//insert this object description to the draw list
void InsertToDrawList(void);
bool LoadTexture(const char *szFilePath_, unsigned long ulKeyColor_ = 0);
//return a surface cut out of this surface
CPlaneSurface * CutOut(unsigned short usXPos_, unsigned short usYPos_,
unsigned short usWidth_, unsigned short usHeight_);
//return a series of surfaces of different part of texture of surface
CPlaneSurface ** Divide(unsigned short usTileWidth_, unsigned short usTileHeight_);
private:
IDirect3DDevice9 *m_pDeviceInterface; //d3d device
IDirect3DVertexBuffer9 *m_pVertexBuffer; //buffer for vertex data
IDirect3DTexture9 *m_pTexture; //texture to render
D3DMATRIX m_WorldMatrixStruct; //world matrix struct
unsigned long m_ulKeyColor; //transparency color
unsigned short m_usWidth, m_usHeight; //size of surface to display
IGraphicDevice::CGraphicObjectDesc *m_ObjectDesc; //description of graphic object
}; |
|