DirectX.h
资源名称:DXGuide.zip [点击查看]
上传用户:wymy58
上传日期:2007-01-07
资源大小:2086k
文件大小:8k
源码类别:
DirextX编程
开发平台:
Visual C++
- // Copyright (C) 1997-1999 DXGuide. All Rights Reserved.
- // File: DirectX.h
- #ifndef _DIRECTX__H
- #define _DIRECTX__H
- #if _MSC_VER >= 1000
- #pragma once
- #endif // _MSC_VER >= 1000
- // turn off warnings for /W4
- #pragma warning(disable: 4201)
- #include <d3d.h> // for D3DCOLOR
- #include <mmsystem.h> // for MMRESULT
- #pragma warning(default: 4201)
- inline void Swap(int* a, int* b)
- {
- int nTemp = *a;
- *a = *b;
- *b = nTemp;
- }
- //** Macros **
- #ifndef max
- #define max(a, b) (((a) > (b)) ? (a) : (b))
- #endif
- #ifndef min
- #define min(a, b) (((a) < (b)) ? (a) : (b))
- #endif
- #ifndef max3
- #define max3(a, b, c) (((a) > (b)) ? (((a) > (c)) ? (a) : (c)) : (((b) > (c)) ? (b) : (c)))
- #endif
- #ifndef min3
- #define min3(a, b, c) (((a) < (b)) ? (((a) < (c)) ? (a) : (c)) : (((b) < (c)) ? (b) : (c)))
- #endif
- #ifndef clamp
- #define clamp(L, V, U) (((L) > (V)) ? (L) : (((U) < (V)) ? (U) : (V)))
- #endif
- // Useful Math constants
- const FLOAT g_PI = 3.14159265358979323846f; // Pi
- const FLOAT g_2_PI = 6.28318530717958623200f; // 2 * Pi
- const FLOAT g_PI_DIV_2 = 1.57079632679489655800f; // Pi / 2
- const FLOAT g_PI_DIV_4 = 0.78539816339744827900f; // Pi / 4
- const FLOAT g_INV_PI = 0.31830988618379069122f; // 1 / Pi
- const FLOAT g_DEGTORAD = 0.01745329251994329547f; // Degrees to Radians
- const FLOAT g_RADTODEG = 57.29577951308232286465f; // Radians to Degrees
- const FLOAT g_HUGE = 1.0e+38f; // Huge number for FLOAT
- const FLOAT g_EPSILON = 1.0e-5f; // Tolerance for FLOATs
- #define DEG2RAD(x) (x * (float)g_PI / 180.0f)
- const int constSineLookupSize = 90;
- class CDirectDraw;
- class CDirectSound;
- class CDirectMusic;
- class CDirectInput;
- class CDXGUIManager;
- class CDirectXApp;
- class CDirectX
- {
- public:
- CDirectX(void);
- ~CDirectX();
- public:
- #ifdef _DEBUG
- static CString __stdcall DXErrorMessage(LPCTSTR lpszFilename,
- int nLine, HRESULT hr);
- static CString __stdcall MMErrorMessage(LPCTSTR lpszFilename,
- int nLine, MMRESULT mmr);
- #endif // _DEBUG
- static CString HRFac2Str(HRESULT hr);
- static CString GUID2Str(const GUID* pGUID);
- static CString PixelFormat2Str(const DDPIXELFORMAT* pDDPF);
- static void AFX_CDECL DirectXMsgBox(LPCTSTR lpszFormat, ...);
- static void GetMCIError(DWORD dwErr);
- static void ExitGame(void);
- protected:
- // cosine/sine lookup tables
- static float m_afSineTable[constSineLookupSize + 1];
- static const LPCTSTR m_lpcszGUIDFormat;
- static const WORD m_dwLibraryVersion;
- static WORD m_wDirectXVersion;
- static const LPCTSTR m_lpcszVersionInfoFmt;
- static const LPCTSTR m_lpcszLibURL;
- static const LPCTSTR m_lpcszLibEmail;
- static const LPCTSTR m_lpcszLogFileName;
- public:
- static DWORD GetLibraryVersion(CString& strOut, LPCTSTR lpFmt = _T("%s, %s"));
- public:
- static float GetSineValue(int nDegree);
- static float GetCosineValue(int nDegree);
- public:
- // Fuzzy compares (within tolerance)
- static bool IsZero(FLOAT a, FLOAT fTol = g_EPSILON);
- public:
- static DWORD GetBitCount(DWORD dwBitMask);
- static DWORD FLOAT2DWORD(FLOAT f);
- static UINT GetSeed(void);
- // Returns a random number (float) in the range [0.0 - 1.0]
- static float rnd(void);
- static int RandInt(int nLow, int nHigh);
- static double RandDouble(double dLow, double dHigh);
- // clips a destination rectange and modifys X,Y coords appropriatly
- static void Clip(int& nDestX, int& nDestY, LPRECT lprcSrc, LPCRECT lprcDest);
- static void RGB2HSV(float fR, float fG, float fB,
- float& fH, float& fS, float& fV);
- static void HSV2RGB(float fH, float fS, float fV,
- float& fR, float& fG, float& fB);
- // Converts bits per pixel to a DirectDraw bit depth flag
- static DWORD BitDepthToFlags(DWORD dwBPP);
- // Gets Bit Depth from DDPF Flags
- static DWORD FlagsToBitDepth(DWORD dwFlags);
- static bool IsPalettized(LPDDPIXELFORMAT lpddpf);
- static D3DCOLOR COLORREF_2_D3DCOLOR(COLORREF clrref);
- static COLORREF D3DCOLOR_2_COLORREF(D3DCOLOR d3dclr);
- static void DelayMM(DWORD dwMS);
- protected:
- static void AFX_CDECL WriteLogFile(LPCTSTR lpszFormat, ...);
- static void CloseLogFile(void);
- #ifdef _DEBUG
- public:
- static HRESULT m_hrFlipToGDISurface;
- #endif // _DEBUG
- #ifdef _LOG_HTML
- public:
- static void SetLog(bool bLog);
- static void LogAppInitFlags(CDirectXApp* pDirectXApp);
- static void LogDDCaps(void const* pv);
- static void LogDSCaps(void const* pv);
- static void LogDMusPortCaps(void const* pv);
- static void LogDDPFFlags(void const* pv);
- static void LogDSBCapsFlags(void const* pv);
- static void LogD3DDeviceDescInfo(void const* pv);
- static void LogDIDeviceInfo(void const* pDIDeviceInstance, void const* pDIDevCaps);
- protected:
- static void LogSysInfo(void);
- static void LogCaps(void const* pcd, void const* pv, bool bIntegrity = true);
- protected:
- static const LPCTSTR m_lpcszHTMLHeadFmt;
- static const LPCTSTR m_lpcszHTMLTail;
- static const LPCTSTR m_lpcszHTMLBreakLine;
- static const LPCTSTR m_lpcszHTMLBreak;
- static const LPCTSTR m_lpcszHTMLBoldFmt;
- static const LPCTSTR m_lpcszHTMLNormalFmt;
- static const LPCTSTR m_lpcszHTMLColorTextFmt;
- static const LPCTSTR m_lpcszHTMLTableHeadFmt;
- static const LPCTSTR m_lpcszHTMLTableTail;
- static const LPCTSTR m_lpcszHTMLTableRowHead;
- static const LPCTSTR m_lpcszHTMLTableRowTail;
- static const LPCTSTR m_lpcszHTMLTableCellFmt;
- static const LPCTSTR m_lpcszHTMLCenterHead;
- static const LPCTSTR m_lpcszHTMLCenterTail;
- static const LPCTSTR m_lpcszHTMLHyperLinkRefFmt;
- static const LPCTSTR m_lpcszHTMLAnchorNameFmt;
- static const LPCTSTR m_lpcszHTMLCommentHead;
- static const LPCTSTR m_lpcszHTMLCommentTail;
- protected:
- static const LPCTSTR m_lpcszSysInfoAnchorName;
- static const LPCTSTR m_lpcszAppInitFlagsInfoAnchorName;
- public:
- static const LPCTSTR m_lpcszCPUInfoAnchorName;
- static const LPCTSTR m_lpcszDDrawInfoAnchorName;
- static const LPCTSTR m_lpcszD3DInfoAnchorName;
- static const LPCTSTR m_lpcszDInputInfoAnchorName;
- static const LPCTSTR m_lpcszDSoundInfoAnchorName;
- static const LPCTSTR m_lpcszDMusicInfoAnchorName;
- static const LPCTSTR m_lpcszDDModeInfoAnchorName;
- static const LPCTSTR m_lpcszRunningInfoAnchorName;
- protected:
- static void LogHTMLHead(LPCTSTR lpszTitle);
- static void LogHTMLTail(void);
- public:
- static void LogHTMLBreakLine(void);
- static void LogHTMLBreak(void);
- static void LogHTMLBoldText(LPCTSTR lpszText, int nSize);
- static void LogHTMLNormalText(LPCTSTR lpszText, int nSize);
- static void LogHTMLColorText(LPCTSTR lpszText, COLORREF clrText, int nSize);
- static void LogHTMLTableHead(LPCTSTR lpszCaption, int nSize);
- static void LogHTMLTableTail(void);
- static void LogHTMLTableRowHead(void);
- static void LogHTMLTableRowTail(void);
- static void LogHTMLTableCell(LPCTSTR lpszText,
- COLORREF clrText, COLORREF clrBack, int nSize);
- static void LogHTMLCenterHead(void);
- static void LogHTMLCenterTail(void);
- static CString HyperLinkRef2Str(LPCTSTR lpszURL,
- LPCTSTR lpszText);
- static void LogHTMLAnchorName(LPCTSTR lpszAnchorName,
- LPCTSTR lpszText, int nSize);
- static void LogHTMLCommentHead(void);
- static void LogHTMLCommentTail(void);
- protected:
- static bool m_bLog;
- #endif // _LOG_HTML
- public:
- static HANDLE m_hLogFile;
- protected:
- static CDirectDraw* m_pDirectDraw;
- static CDirectSound* m_pDirectSound;
- static CDirectMusic* m_pDirectMusic;
- static CDirectInput* m_pDirectInput;
- static CDXGUIManager* m_pDXGUIManager;
- public:
- static void SetDirectDraw(CDirectDraw* pDirectDraw);
- static void SetDirectSound(CDirectSound* pDirectSound);
- static void SetDirectMusic(CDirectMusic* pDirectMusic);
- static void SetDirectInput(CDirectInput* pDirectInput);
- static void SetDXGUIManager(CDXGUIManager* pDXGUIManager);
- static CDirectDraw* GetDirectDraw(void);
- static CDirectSound* GetDirectSound(void);
- static CDirectMusic* GetDirectMusic(void);
- static CDirectInput* GetDirectInput(void);
- static CDXGUIManager* GetDXGUIManager(void);
- };
- #include "DirectX.inl"
- extern CDirectX directX;
- #ifdef _DEBUG
- #define DXCHECK(x) CDirectX::DXErrorMessage(__FILE__, __LINE__, x)
- #define REPORTDXERROR(x) {if (FAILED(x)) CDirectX::DirectXMsgBox(DXCHECK(x)), ::DebugBreak();}
- #define MMCHECK(x) CDirectX::MMErrorMessage(__FILE__, __LINE__, x)
- #define REPORTMMERROR(x) {if (x != MMSYSERR_NOERROR) CDirectX::DirectXMsgBox(MMCHECK(x)), ::DebugBreak();}
- #else
- #define DXCHECK(x)
- #define REPORTDXERROR(x)
- #define MMCHECK(x)
- #define REPORTMMERROR(x)
- #endif // _DEBUG
- #endif // _DIRECTX__H