www.pudn.com > Chesssource.rar > Graphics.h
#ifndef _GRAPHICS_H_
#define _GRAPHICS_H_
class cGraphics
{
protected:
HWND m_hWnd;
IDirect3DDevice9 *m_pD3DDevice;
ID3DXSprite *m_pSprite;
D3DPRESENT_PARAMETERS m_d3dpp;
D3DDISPLAYMODE m_DesktopMode;
D3DFORMAT m_d3dfmtFullscreen;
D3DFORMAT m_d3dfmtTexture;
BOOL m_Windowed;
long m_Width;
long m_Height;
char m_AmbientRed;
char m_AmbientGreen;
char m_AmbientBlue;
public:
cGraphics();
~cGraphics();
IDirect3DDevice9 *Get3DDevice();
ID3DXSprite *GetSpriteDevice();
BOOL Shutdown();
BOOL SetMode(HWND hWnd, BOOL Windowed, long Width=0, long Height=0);
BOOL Display();
BOOL BeginScene();
BOOL EndScene();
BOOL Clear(long Color = 0, float ZBuffer = 1.0f);
BOOL ClearDisplay(long Color = 0);
BOOL ClearZBuffer(float ZBuffer = 1.0f);
long GetWidth();
long GetHeight();
BOOL SetPerspective(float FOV=D3DX_PI / 4.0f, float Aspect=1.3333f, float Near=1.0f, float Far=10000.0f);
BOOL SetAmbientLight(char Red, char Green, char Blue);
BOOL GetAmbientLight(char *Red, char *Green, char *Blue);
BOOL EnableLight(long Num, BOOL Enable = TRUE);
BOOL EnableLighting(BOOL Enable = TRUE);
BOOL EnableZBuffer(BOOL Enable = TRUE);
BOOL EnableAlphaBlending(BOOL Enable = TRUE, DWORD Src = D3DBLEND_SRCALPHA, DWORD Dest = D3DBLEND_INVSRCALPHA);
BOOL EnableAlphaTesting(BOOL Enable = TRUE);
};
class cTexture
{
protected:
cGraphics *m_pGraphics;
ID3DXSprite *m_pSprite;
IDirect3DTexture9 *m_pTexture;
DWORD m_dwTexWidth, m_dwTexHeight;
public:
cTexture();
~cTexture();
IDirect3DTexture9 *GetTexDevice();
BOOL Load(cGraphics *Graphics, char *strFilename, DWORD dwTransparent = 0, D3DFORMAT fmtFormat = D3DFMT_UNKNOWN );
HRESULT Create( cGraphics *Graphics, DWORD dwTexWidth, DWORD dwTexHeight, D3DFORMAT fmtFormat );
HRESULT Create( cGraphics *Graphics, IDirect3DTexture9 *Texture );
VOID Free();
BOOL IsLoaded();
DWORD GetTexWidth();
DWORD GetTexHeight();
D3DFORMAT GetTexFormat();
BOOL Blit(long DestX, long DestY, long SrcX = 0, long SrcY = 0, long Width = 0, long Height = 0,
float XScale = 1.0f, float YScale = 1.0f, D3DCOLOR Color = 0xFFFFFFFF);
};
class cCamera
{
protected:
float m_fXPos, m_fYPos, m_fZPos;
float m_fXRot, m_fYRot, m_fZRot;
float m_fStartXPos, m_fStartYPos, m_fStartZPos;
float m_fStartXRot, m_fStartYRot, m_fStartZRot;
float m_fEndXPos, m_fEndYPos, m_fEndZPos;
float m_fEndXRot, m_fEndYRot, m_fEndZRot;
D3DXMATRIX m_matWorld;
D3DXMATRIX m_matTranslation;
D3DXMATRIX m_matRotation;
public:
cCamera();
D3DXMATRIX *GetMatrix();
void Update();
// 移动并旋转摄像机
void Move( float fXPos, float fYPos, float fZPos );
void MoveRel( float fXAdd, float fYAdd, float fZAdd );
void Rotate( float fXRot, float fYRot, float fZRot );
void RotateRel( float fXAdd, float fYAdd, float fZAdd );
// 把摄像机从Eye的位置指向At的位置
void Point( float fXEye, float fYEye, float fZEye, float fXAt, float fYAt, float fZAt );
// 设置追踪方位的开始点和结束点
void SetStartTrack();
void SetEndTrack();
// 使用Time(0.0~1.0)和总Length沿着追踪路径内插摄像机方位
void Track( float fTime, float fLength );
float GetXPos();
float GetYPos();
float GetZPos();
float GetXRotation();
float GetYRotation();
float GetZRotation();
};
class cLight
{
protected:
D3DLIGHT9 m_pLight;
public:
cLight();
D3DLIGHT9 *GetLight();
void SetType( D3DLIGHTTYPE Type );
void Move( float fXPos, float fYPos, float fZPos );
void MoveRel( float fXPos, float fYPos, float fZPos );
void GetPos( float *fXPos, float *fYPos, float *fZPos );
void Point( float fXFrom, float fYFrom, float fZFrom, float fXAt, float fYAt, float fZAt );
void GetDirection( float *fXDir, float *fYDir, float *fZDir );
void SetDiffuseColor( char cRed, char cGreen, char cBlue );
void GetDiffuseColor( char *cRed, char *cGreen, char *cBlue );
void SetSpecularColor( char cRed, char cGreen, char cBlue );
void GetSpecularColor( char *cRed, char *cGreen, char *cBlue );
void SetAmbientColor( char cRed, char cGreen, char cBlue );
void GetAmbientColor( char *cRed, char *cGreen, char *cBlue );
void SetRange( float fRange );
float GetRange();
void SetFalloff( float fFalloff );
float GetFalloff();
void SetAttenuation0( float fAttenuation );
float GetAttenuation0();
void SetAttenuation1(float fAttenuation);
float GetAttenuation1();
void SetAttenuation2(float fAttenuation);
float GetAttenuation2();
void SetTheta(float fTheta);
float GetTheta();
void SetPhi(float fPhi);
float GetPhi();
};
class cFont
{
private:
ID3DXFont *m_Font;
public:
cFont();
~cFont();
ID3DXFont *GetFontDevice();
BOOL Create(cGraphics *pGraphics, char *strName, long Size = 0, BOOL bBold = FALSE, BOOL bItalic = FALSE, BOOL bUnderline = FALSE, BOOL bStrikeout = FALSE);
BOOL Free();
BOOL Print(char *Text, long XPos, long YPos, long Width = 0, long Height = 0, D3DCOLOR Color = 0xFFFFFFFF, DWORD Format = 0);
};
class cVertexBuffer
{
private:
cGraphics *m_Graphics;
IDirect3DVertexBuffer9 *m_pVB;
DWORD m_NumVertices;
DWORD m_VertexSize;
DWORD m_FVF;
BOOL m_Locked;
char *m_Ptr;
public:
cVertexBuffer();
~cVertexBuffer();
IDirect3DVertexBuffer9 *GetVertexBufferCOM();
unsigned long GetVertexSize();
unsigned long GetVertexFVF();
unsigned long GetNumVertices();
BOOL Create(cGraphics *Graphics, unsigned long NumVertices, DWORD Descriptor, long VertexSize);
BOOL Free();
BOOL IsLoaded();
BOOL Set(unsigned long FirstVertex, unsigned long NumVertices, void *VertexList);
BOOL Render(unsigned long FirstVertex, unsigned long NumPrimitives, DWORD Type);
BOOL Lock(unsigned long FirstVertex = 0, unsigned long NumVertices = 0);
BOOL Unlock();
void *GetPtr();
};
#endif